blob: f0ac399bae3c9e88204ec4e39c65089fe88835ed [file] [log] [blame]
Jan Beulich176a2712006-06-26 13:57:41 +02001#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
17struct 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)
Andi Kleena32cf392006-09-26 10:52:34 +020031#else
32#define UNW_FP(frame) ((void)(frame), 0)
Jan Beulich176a2712006-06-26 13:57:41 +020033#endif
34#define STACK_LIMIT(ptr) (((ptr) - 1) & ~(THREAD_SIZE - 1))
35
36#define UNW_REGISTER_INFO \
37 PTREGS_INFO(eax), \
38 PTREGS_INFO(ecx), \
39 PTREGS_INFO(edx), \
40 PTREGS_INFO(ebx), \
41 PTREGS_INFO(esp), \
42 PTREGS_INFO(ebp), \
43 PTREGS_INFO(esi), \
44 PTREGS_INFO(edi), \
45 PTREGS_INFO(eip)
46
47static inline void arch_unw_init_frame_info(struct unwind_frame_info *info,
48 /*const*/ struct pt_regs *regs)
49{
50 if (user_mode_vm(regs))
51 info->regs = *regs;
52 else {
53 memcpy(&info->regs, regs, offsetof(struct pt_regs, esp));
54 info->regs.esp = (unsigned long)&regs->esp;
55 info->regs.xss = __KERNEL_DS;
56 }
57}
58
59static inline void arch_unw_init_blocked(struct unwind_frame_info *info)
60{
61 memset(&info->regs, 0, sizeof(info->regs));
62 info->regs.eip = info->task->thread.eip;
63 info->regs.xcs = __KERNEL_CS;
64 __get_user(info->regs.ebp, (long *)info->task->thread.esp);
65 info->regs.esp = info->task->thread.esp;
66 info->regs.xss = __KERNEL_DS;
67 info->regs.xds = __USER_DS;
68 info->regs.xes = __USER_DS;
69}
70
Jan Beulichc33bd9a2006-06-26 13:57:47 +020071extern asmlinkage int arch_unwind_init_running(struct unwind_frame_info *,
72 asmlinkage int (*callback)(struct unwind_frame_info *,
73 void *arg),
74 void *arg);
Jan Beulich176a2712006-06-26 13:57:41 +020075
76static inline int arch_unw_user_mode(const struct unwind_frame_info *info)
77{
78#if 0 /* This can only work when selector register and EFLAGS saves/restores
79 are properly annotated (and tracked in UNW_REGISTER_INFO). */
80 return user_mode_vm(&info->regs);
81#else
82 return info->regs.eip < PAGE_OFFSET
Ingo Molnare6e54942006-06-27 02:53:50 -070083 || (info->regs.eip >= __fix_to_virt(FIX_VDSO)
84 && info->regs.eip < __fix_to_virt(FIX_VDSO) + PAGE_SIZE)
Jan Beulich176a2712006-06-26 13:57:41 +020085 || info->regs.esp < PAGE_OFFSET;
86#endif
87}
88
89#else
90
91#define UNW_PC(frame) ((void)(frame), 0)
Jan Beulichea424052006-08-30 19:37:11 +020092#define UNW_SP(frame) ((void)(frame), 0)
Andi Kleena32cf392006-09-26 10:52:34 +020093#define UNW_FP(frame) ((void)(frame), 0)
Jan Beulich176a2712006-06-26 13:57:41 +020094
95static inline int arch_unw_user_mode(const void *info)
96{
97 return 0;
98}
99
100#endif
101
102#endif /* _ASM_I386_UNWIND_H */