Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 1 | #ifndef _ASM_I386_UNWIND_H |
| 2 | #define _ASM_I386_UNWIND_H |
| 3 | |
| 4 | /* |
| 5 | * Copyright (C) 2002-2006 Novell, Inc. |
| 6 | * Jan Beulich <jbeulich@novell.com> |
| 7 | * This code is released under version 2 of the GNU GPL. |
| 8 | */ |
| 9 | |
| 10 | #ifdef CONFIG_STACK_UNWIND |
| 11 | |
| 12 | #include <linux/sched.h> |
| 13 | #include <asm/fixmap.h> |
| 14 | #include <asm/ptrace.h> |
| 15 | #include <asm/uaccess.h> |
| 16 | |
| 17 | struct unwind_frame_info |
| 18 | { |
| 19 | struct pt_regs regs; |
| 20 | struct task_struct *task; |
Jan Beulich | adf1423 | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 21 | unsigned call_frame:1; |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 22 | }; |
| 23 | |
| 24 | #define UNW_PC(frame) (frame)->regs.eip |
| 25 | #define UNW_SP(frame) (frame)->regs.esp |
| 26 | #ifdef CONFIG_FRAME_POINTER |
| 27 | #define UNW_FP(frame) (frame)->regs.ebp |
| 28 | #define FRAME_RETADDR_OFFSET 4 |
| 29 | #define FRAME_LINK_OFFSET 0 |
| 30 | #define STACK_BOTTOM(tsk) STACK_LIMIT((tsk)->thread.esp0) |
| 31 | #define STACK_TOP(tsk) ((tsk)->thread.esp0) |
Andi Kleen | a32cf39 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 32 | #else |
| 33 | #define UNW_FP(frame) ((void)(frame), 0) |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 34 | #endif |
| 35 | #define STACK_LIMIT(ptr) (((ptr) - 1) & ~(THREAD_SIZE - 1)) |
| 36 | |
| 37 | #define UNW_REGISTER_INFO \ |
| 38 | PTREGS_INFO(eax), \ |
| 39 | PTREGS_INFO(ecx), \ |
| 40 | PTREGS_INFO(edx), \ |
| 41 | PTREGS_INFO(ebx), \ |
| 42 | PTREGS_INFO(esp), \ |
| 43 | PTREGS_INFO(ebp), \ |
| 44 | PTREGS_INFO(esi), \ |
| 45 | PTREGS_INFO(edi), \ |
| 46 | PTREGS_INFO(eip) |
| 47 | |
Jan Beulich | adf1423 | 2006-09-26 10:52:41 +0200 | [diff] [blame] | 48 | #define UNW_DEFAULT_RA(raItem, dataAlign) \ |
| 49 | ((raItem).where == Memory && \ |
| 50 | !((raItem).value * (dataAlign) + 4)) |
| 51 | |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 52 | static inline void arch_unw_init_frame_info(struct unwind_frame_info *info, |
| 53 | /*const*/ struct pt_regs *regs) |
| 54 | { |
| 55 | if (user_mode_vm(regs)) |
| 56 | info->regs = *regs; |
| 57 | else { |
| 58 | memcpy(&info->regs, regs, offsetof(struct pt_regs, esp)); |
| 59 | info->regs.esp = (unsigned long)®s->esp; |
| 60 | info->regs.xss = __KERNEL_DS; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | static inline void arch_unw_init_blocked(struct unwind_frame_info *info) |
| 65 | { |
| 66 | memset(&info->regs, 0, sizeof(info->regs)); |
| 67 | info->regs.eip = info->task->thread.eip; |
| 68 | info->regs.xcs = __KERNEL_CS; |
| 69 | __get_user(info->regs.ebp, (long *)info->task->thread.esp); |
| 70 | info->regs.esp = info->task->thread.esp; |
| 71 | info->regs.xss = __KERNEL_DS; |
| 72 | info->regs.xds = __USER_DS; |
| 73 | info->regs.xes = __USER_DS; |
Jeremy Fitzhardinge | 66e10a4 | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 74 | info->regs.xgs = __KERNEL_PDA; |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 75 | } |
| 76 | |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 77 | extern asmlinkage int arch_unwind_init_running(struct unwind_frame_info *, |
| 78 | asmlinkage int (*callback)(struct unwind_frame_info *, |
| 79 | void *arg), |
| 80 | void *arg); |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 81 | |
Jan Beulich | 359ad0d | 2006-12-07 02:14:13 +0100 | [diff] [blame] | 82 | static inline int arch_unw_user_mode(/*const*/ struct unwind_frame_info *info) |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 83 | { |
Jan Beulich | 359ad0d | 2006-12-07 02:14:13 +0100 | [diff] [blame] | 84 | return user_mode_vm(&info->regs) |
| 85 | || info->regs.eip < PAGE_OFFSET |
Ingo Molnar | e6e5494 | 2006-06-27 02:53:50 -0700 | [diff] [blame] | 86 | || (info->regs.eip >= __fix_to_virt(FIX_VDSO) |
Jan Beulich | 359ad0d | 2006-12-07 02:14:13 +0100 | [diff] [blame] | 87 | && info->regs.eip < __fix_to_virt(FIX_VDSO) + PAGE_SIZE) |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 88 | || info->regs.esp < PAGE_OFFSET; |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | #else |
| 92 | |
| 93 | #define UNW_PC(frame) ((void)(frame), 0) |
Jan Beulich | ea42405 | 2006-08-30 19:37:11 +0200 | [diff] [blame] | 94 | #define UNW_SP(frame) ((void)(frame), 0) |
Andi Kleen | a32cf39 | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 95 | #define UNW_FP(frame) ((void)(frame), 0) |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 96 | |
| 97 | static inline int arch_unw_user_mode(const void *info) |
| 98 | { |
| 99 | return 0; |
| 100 | } |
| 101 | |
| 102 | #endif |
| 103 | |
| 104 | #endif /* _ASM_I386_UNWIND_H */ |