]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/x86/include/asm/stacktrace.h
x86/bugs, KVM: Support the combination of guest and host IBRS
[mirror_ubuntu-artful-kernel.git] / arch / x86 / include / asm / stacktrace.h
CommitLineData
c9cf4dbb
FW
1/*
2 * Copyright (C) 1991, 1992 Linus Torvalds
3 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
4 */
5
1965aae3
PA
6#ifndef _ASM_X86_STACKTRACE_H
7#define _ASM_X86_STACKTRACE_H
c0b766f1 8
c9cf4dbb 9#include <linux/uaccess.h>
9c0729dc 10#include <linux/ptrace.h>
7b32aead 11#include <asm/switch_to.h>
c9cf4dbb 12
cb76c939
JP
13enum stack_type {
14 STACK_TYPE_UNKNOWN,
15 STACK_TYPE_TASK,
16 STACK_TYPE_IRQ,
17 STACK_TYPE_SOFTIRQ,
e0437c47 18 STACK_TYPE_ENTRY,
cb76c939
JP
19 STACK_TYPE_EXCEPTION,
20 STACK_TYPE_EXCEPTION_LAST = STACK_TYPE_EXCEPTION + N_EXCEPTION_STACKS-1,
21};
22
23struct stack_info {
24 enum stack_type type;
25 unsigned long *begin, *end, *next_sp;
26};
27
28bool in_task_stack(unsigned long *stack, struct task_struct *task,
29 struct stack_info *info);
30
e0437c47 31bool in_entry_stack(unsigned long *stack, struct stack_info *info);
72e90cc5 32
cb76c939
JP
33int get_stack_info(unsigned long *stack, struct task_struct *task,
34 struct stack_info *info, unsigned long *visit_mask);
35
3d02a9c4 36const char *stack_type_name(enum stack_type type);
cb76c939
JP
37
38static inline bool on_stack(struct stack_info *info, void *addr, size_t len)
39{
40 void *begin = info->begin;
41 void *end = info->end;
42
43 return (info->type != STACK_TYPE_UNKNOWN &&
44 addr >= begin && addr < end &&
45 addr + len > begin && addr + len <= end);
46}
47
c9cf4dbb
FW
48#ifdef CONFIG_X86_32
49#define STACKSLOTS_PER_LINE 8
c9cf4dbb
FW
50#else
51#define STACKSLOTS_PER_LINE 4
c9cf4dbb
FW
52#endif
53
9c0729dc 54#ifdef CONFIG_FRAME_POINTER
4b8afafb
JP
55static inline unsigned long *
56get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
9c0729dc 57{
9c0729dc 58 if (regs)
4b8afafb 59 return (unsigned long *)regs->bp;
9c0729dc 60
81539169 61 if (task == current)
4b8afafb 62 return __builtin_frame_address(0);
9c0729dc 63
2c96b2fe 64 return &((struct inactive_task_frame *)task->thread.sp)->bp;
9c0729dc
SSP
65}
66#else
4b8afafb
JP
67static inline unsigned long *
68get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
9c0729dc 69{
4b8afafb
JP
70 return NULL;
71}
72#endif /* CONFIG_FRAME_POINTER */
73
74static inline unsigned long *
75get_stack_pointer(struct task_struct *task, struct pt_regs *regs)
76{
77 if (regs)
78 return (unsigned long *)kernel_stack_pointer(regs);
79
81539169 80 if (task == current)
4b8afafb
JP
81 return __builtin_frame_address(0);
82
83 return (unsigned long *)task->thread.sp;
9c0729dc 84}
9c0729dc 85
e18bcccd
JP
86void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
87 unsigned long *stack, char *log_lvl);
c9cf4dbb 88
c9cf4dbb
FW
89extern unsigned int code_bytes;
90
91/* The form of the top of the frame on the stack */
92struct stack_frame {
93 struct stack_frame *next_frame;
94 unsigned long return_address;
95};
96
97struct stack_frame_ia32 {
98 u32 next_frame;
99 u32 return_address;
100};
101
b0f82b81 102static inline unsigned long caller_frame_pointer(void)
c9cf4dbb
FW
103{
104 struct stack_frame *frame;
105
4b8afafb 106 frame = __builtin_frame_address(0);
c9cf4dbb
FW
107
108#ifdef CONFIG_FRAME_POINTER
b0f82b81 109 frame = frame->next_frame;
c9cf4dbb
FW
110#endif
111
112 return (unsigned long)frame;
113}
114
1965aae3 115#endif /* _ASM_X86_STACKTRACE_H */