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; |
| 21 | }; |
| 22 | |
| 23 | #define UNW_PC(frame) (frame)->regs.eip |
| 24 | #define UNW_SP(frame) (frame)->regs.esp |
| 25 | #ifdef CONFIG_FRAME_POINTER |
| 26 | #define UNW_FP(frame) (frame)->regs.ebp |
| 27 | #define FRAME_RETADDR_OFFSET 4 |
| 28 | #define FRAME_LINK_OFFSET 0 |
| 29 | #define STACK_BOTTOM(tsk) STACK_LIMIT((tsk)->thread.esp0) |
| 30 | #define STACK_TOP(tsk) ((tsk)->thread.esp0) |
| 31 | #endif |
| 32 | #define STACK_LIMIT(ptr) (((ptr) - 1) & ~(THREAD_SIZE - 1)) |
| 33 | |
| 34 | #define UNW_REGISTER_INFO \ |
| 35 | PTREGS_INFO(eax), \ |
| 36 | PTREGS_INFO(ecx), \ |
| 37 | PTREGS_INFO(edx), \ |
| 38 | PTREGS_INFO(ebx), \ |
| 39 | PTREGS_INFO(esp), \ |
| 40 | PTREGS_INFO(ebp), \ |
| 41 | PTREGS_INFO(esi), \ |
| 42 | PTREGS_INFO(edi), \ |
| 43 | PTREGS_INFO(eip) |
| 44 | |
| 45 | static inline void arch_unw_init_frame_info(struct unwind_frame_info *info, |
| 46 | /*const*/ struct pt_regs *regs) |
| 47 | { |
| 48 | if (user_mode_vm(regs)) |
| 49 | info->regs = *regs; |
| 50 | else { |
| 51 | memcpy(&info->regs, regs, offsetof(struct pt_regs, esp)); |
| 52 | info->regs.esp = (unsigned long)®s->esp; |
| 53 | info->regs.xss = __KERNEL_DS; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | static inline void arch_unw_init_blocked(struct unwind_frame_info *info) |
| 58 | { |
| 59 | memset(&info->regs, 0, sizeof(info->regs)); |
| 60 | info->regs.eip = info->task->thread.eip; |
| 61 | info->regs.xcs = __KERNEL_CS; |
| 62 | __get_user(info->regs.ebp, (long *)info->task->thread.esp); |
| 63 | info->regs.esp = info->task->thread.esp; |
| 64 | info->regs.xss = __KERNEL_DS; |
| 65 | info->regs.xds = __USER_DS; |
| 66 | info->regs.xes = __USER_DS; |
| 67 | } |
| 68 | |
Jan Beulich | c33bd9a | 2006-06-26 13:57:47 +0200 | [diff] [blame] | 69 | extern asmlinkage int arch_unwind_init_running(struct unwind_frame_info *, |
| 70 | asmlinkage int (*callback)(struct unwind_frame_info *, |
| 71 | void *arg), |
| 72 | void *arg); |
Jan Beulich | 176a271 | 2006-06-26 13:57:41 +0200 | [diff] [blame] | 73 | |
| 74 | static inline int arch_unw_user_mode(const struct unwind_frame_info *info) |
| 75 | { |
| 76 | #if 0 /* This can only work when selector register and EFLAGS saves/restores |
| 77 | are properly annotated (and tracked in UNW_REGISTER_INFO). */ |
| 78 | return user_mode_vm(&info->regs); |
| 79 | #else |
| 80 | return info->regs.eip < PAGE_OFFSET |
| 81 | || (info->regs.eip >= __fix_to_virt(FIX_VSYSCALL) |
| 82 | && info->regs.eip < __fix_to_virt(FIX_VSYSCALL) + PAGE_SIZE) |
| 83 | || info->regs.esp < PAGE_OFFSET; |
| 84 | #endif |
| 85 | } |
| 86 | |
| 87 | #else |
| 88 | |
| 89 | #define UNW_PC(frame) ((void)(frame), 0) |
| 90 | |
| 91 | static inline int arch_unw_user_mode(const void *info) |
| 92 | { |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | #endif |
| 97 | |
| 98 | #endif /* _ASM_I386_UNWIND_H */ |