Frederic Weisbecker | c9cf4db | 2010-05-19 21:35:17 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 3 | * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs |
| 4 | */ |
| 5 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 6 | #ifndef _ASM_X86_STACKTRACE_H |
| 7 | #define _ASM_X86_STACKTRACE_H |
Andi Kleen | c0b766f | 2006-09-26 10:52:34 +0200 | [diff] [blame] | 8 | |
Frederic Weisbecker | c9cf4db | 2010-05-19 21:35:17 +0200 | [diff] [blame] | 9 | #include <linux/uaccess.h> |
Soeren Sandmann Pedersen | 9c0729d | 2010-11-05 05:59:39 -0400 | [diff] [blame] | 10 | #include <linux/ptrace.h> |
Brian Gerst | 7b32aea | 2016-08-13 12:38:18 -0400 | [diff] [blame] | 11 | #include <asm/switch_to.h> |
Frederic Weisbecker | c9cf4db | 2010-05-19 21:35:17 +0200 | [diff] [blame] | 12 | |
Josh Poimboeuf | cb76c93 | 2016-09-14 21:07:42 -0500 | [diff] [blame] | 13 | enum stack_type { |
| 14 | STACK_TYPE_UNKNOWN, |
| 15 | STACK_TYPE_TASK, |
| 16 | STACK_TYPE_IRQ, |
| 17 | STACK_TYPE_SOFTIRQ, |
| 18 | STACK_TYPE_EXCEPTION, |
| 19 | STACK_TYPE_EXCEPTION_LAST = STACK_TYPE_EXCEPTION + N_EXCEPTION_STACKS-1, |
| 20 | }; |
| 21 | |
| 22 | struct stack_info { |
| 23 | enum stack_type type; |
| 24 | unsigned long *begin, *end, *next_sp; |
| 25 | }; |
| 26 | |
| 27 | bool in_task_stack(unsigned long *stack, struct task_struct *task, |
| 28 | struct stack_info *info); |
| 29 | |
| 30 | int get_stack_info(unsigned long *stack, struct task_struct *task, |
| 31 | struct stack_info *info, unsigned long *visit_mask); |
| 32 | |
Josh Poimboeuf | 3d02a9c | 2016-11-18 11:46:23 -0600 | [diff] [blame] | 33 | const char *stack_type_name(enum stack_type type); |
Josh Poimboeuf | cb76c93 | 2016-09-14 21:07:42 -0500 | [diff] [blame] | 34 | |
| 35 | static inline bool on_stack(struct stack_info *info, void *addr, size_t len) |
| 36 | { |
| 37 | void *begin = info->begin; |
| 38 | void *end = info->end; |
| 39 | |
| 40 | return (info->type != STACK_TYPE_UNKNOWN && |
| 41 | addr >= begin && addr < end && |
| 42 | addr + len > begin && addr + len <= end); |
| 43 | } |
| 44 | |
Frederic Weisbecker | c9cf4db | 2010-05-19 21:35:17 +0200 | [diff] [blame] | 45 | #ifdef CONFIG_X86_32 |
| 46 | #define STACKSLOTS_PER_LINE 8 |
Frederic Weisbecker | c9cf4db | 2010-05-19 21:35:17 +0200 | [diff] [blame] | 47 | #else |
| 48 | #define STACKSLOTS_PER_LINE 4 |
Frederic Weisbecker | c9cf4db | 2010-05-19 21:35:17 +0200 | [diff] [blame] | 49 | #endif |
| 50 | |
Soeren Sandmann Pedersen | 9c0729d | 2010-11-05 05:59:39 -0400 | [diff] [blame] | 51 | #ifdef CONFIG_FRAME_POINTER |
Josh Poimboeuf | 4b8afaf | 2016-08-24 11:50:17 -0500 | [diff] [blame] | 52 | static inline unsigned long * |
| 53 | get_frame_pointer(struct task_struct *task, struct pt_regs *regs) |
Soeren Sandmann Pedersen | 9c0729d | 2010-11-05 05:59:39 -0400 | [diff] [blame] | 54 | { |
Soeren Sandmann Pedersen | 9c0729d | 2010-11-05 05:59:39 -0400 | [diff] [blame] | 55 | if (regs) |
Josh Poimboeuf | 4b8afaf | 2016-08-24 11:50:17 -0500 | [diff] [blame] | 56 | return (unsigned long *)regs->bp; |
Soeren Sandmann Pedersen | 9c0729d | 2010-11-05 05:59:39 -0400 | [diff] [blame] | 57 | |
Josh Poimboeuf | 8153916 | 2016-09-16 08:05:20 -0500 | [diff] [blame] | 58 | if (task == current) |
Josh Poimboeuf | 4b8afaf | 2016-08-24 11:50:17 -0500 | [diff] [blame] | 59 | return __builtin_frame_address(0); |
Soeren Sandmann Pedersen | 9c0729d | 2010-11-05 05:59:39 -0400 | [diff] [blame] | 60 | |
Josh Poimboeuf | 2c96b2f | 2017-01-09 12:00:24 -0600 | [diff] [blame^] | 61 | return &((struct inactive_task_frame *)task->thread.sp)->bp; |
Soeren Sandmann Pedersen | 9c0729d | 2010-11-05 05:59:39 -0400 | [diff] [blame] | 62 | } |
| 63 | #else |
Josh Poimboeuf | 4b8afaf | 2016-08-24 11:50:17 -0500 | [diff] [blame] | 64 | static inline unsigned long * |
| 65 | get_frame_pointer(struct task_struct *task, struct pt_regs *regs) |
Soeren Sandmann Pedersen | 9c0729d | 2010-11-05 05:59:39 -0400 | [diff] [blame] | 66 | { |
Josh Poimboeuf | 4b8afaf | 2016-08-24 11:50:17 -0500 | [diff] [blame] | 67 | return NULL; |
Soeren Sandmann Pedersen | 9c0729d | 2010-11-05 05:59:39 -0400 | [diff] [blame] | 68 | } |
Josh Poimboeuf | 4b8afaf | 2016-08-24 11:50:17 -0500 | [diff] [blame] | 69 | #endif /* CONFIG_FRAME_POINTER */ |
| 70 | |
| 71 | static inline unsigned long * |
| 72 | get_stack_pointer(struct task_struct *task, struct pt_regs *regs) |
| 73 | { |
| 74 | if (regs) |
| 75 | return (unsigned long *)kernel_stack_pointer(regs); |
| 76 | |
Josh Poimboeuf | 8153916 | 2016-09-16 08:05:20 -0500 | [diff] [blame] | 77 | if (task == current) |
Josh Poimboeuf | 4b8afaf | 2016-08-24 11:50:17 -0500 | [diff] [blame] | 78 | return __builtin_frame_address(0); |
| 79 | |
| 80 | return (unsigned long *)task->thread.sp; |
| 81 | } |
Soeren Sandmann Pedersen | 9c0729d | 2010-11-05 05:59:39 -0400 | [diff] [blame] | 82 | |
Josh Poimboeuf | e18bccc | 2016-09-16 14:18:16 -0500 | [diff] [blame] | 83 | void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs, |
| 84 | unsigned long *stack, char *log_lvl); |
Frederic Weisbecker | c9cf4db | 2010-05-19 21:35:17 +0200 | [diff] [blame] | 85 | |
Frederic Weisbecker | c9cf4db | 2010-05-19 21:35:17 +0200 | [diff] [blame] | 86 | extern unsigned int code_bytes; |
| 87 | |
| 88 | /* The form of the top of the frame on the stack */ |
| 89 | struct stack_frame { |
| 90 | struct stack_frame *next_frame; |
| 91 | unsigned long return_address; |
| 92 | }; |
| 93 | |
| 94 | struct stack_frame_ia32 { |
| 95 | u32 next_frame; |
| 96 | u32 return_address; |
| 97 | }; |
| 98 | |
Frederic Weisbecker | b0f82b8 | 2010-05-20 07:47:21 +0200 | [diff] [blame] | 99 | static inline unsigned long caller_frame_pointer(void) |
Frederic Weisbecker | c9cf4db | 2010-05-19 21:35:17 +0200 | [diff] [blame] | 100 | { |
| 101 | struct stack_frame *frame; |
| 102 | |
Josh Poimboeuf | 4b8afaf | 2016-08-24 11:50:17 -0500 | [diff] [blame] | 103 | frame = __builtin_frame_address(0); |
Frederic Weisbecker | c9cf4db | 2010-05-19 21:35:17 +0200 | [diff] [blame] | 104 | |
| 105 | #ifdef CONFIG_FRAME_POINTER |
Frederic Weisbecker | b0f82b8 | 2010-05-20 07:47:21 +0200 | [diff] [blame] | 106 | frame = frame->next_frame; |
Frederic Weisbecker | c9cf4db | 2010-05-19 21:35:17 +0200 | [diff] [blame] | 107 | #endif |
| 108 | |
| 109 | return (unsigned long)frame; |
| 110 | } |
| 111 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 112 | #endif /* _ASM_X86_STACKTRACE_H */ |