Linux 5.7.6
[linux/fpc-iii.git] / arch / x86 / include / asm / stacktrace.h
blob14db05086bbf27198628785918ce3c2e627aa5c4
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright (C) 1991, 1992 Linus Torvalds
4 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
5 */
7 #ifndef _ASM_X86_STACKTRACE_H
8 #define _ASM_X86_STACKTRACE_H
10 #include <linux/uaccess.h>
11 #include <linux/ptrace.h>
13 #include <asm/cpu_entry_area.h>
14 #include <asm/switch_to.h>
16 enum stack_type {
17 STACK_TYPE_UNKNOWN,
18 STACK_TYPE_TASK,
19 STACK_TYPE_IRQ,
20 STACK_TYPE_SOFTIRQ,
21 STACK_TYPE_ENTRY,
22 STACK_TYPE_EXCEPTION,
23 STACK_TYPE_EXCEPTION_LAST = STACK_TYPE_EXCEPTION + N_EXCEPTION_STACKS-1,
26 struct stack_info {
27 enum stack_type type;
28 unsigned long *begin, *end, *next_sp;
31 bool in_task_stack(unsigned long *stack, struct task_struct *task,
32 struct stack_info *info);
34 bool in_entry_stack(unsigned long *stack, struct stack_info *info);
36 int get_stack_info(unsigned long *stack, struct task_struct *task,
37 struct stack_info *info, unsigned long *visit_mask);
39 const char *stack_type_name(enum stack_type type);
41 static inline bool on_stack(struct stack_info *info, void *addr, size_t len)
43 void *begin = info->begin;
44 void *end = info->end;
46 return (info->type != STACK_TYPE_UNKNOWN &&
47 addr >= begin && addr < end &&
48 addr + len > begin && addr + len <= end);
51 #ifdef CONFIG_X86_32
52 #define STACKSLOTS_PER_LINE 8
53 #else
54 #define STACKSLOTS_PER_LINE 4
55 #endif
57 #ifdef CONFIG_FRAME_POINTER
58 static inline unsigned long *
59 get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
61 if (regs)
62 return (unsigned long *)regs->bp;
64 if (task == current)
65 return __builtin_frame_address(0);
67 return &((struct inactive_task_frame *)task->thread.sp)->bp;
69 #else
70 static inline unsigned long *
71 get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
73 return NULL;
75 #endif /* CONFIG_FRAME_POINTER */
77 static inline unsigned long *
78 get_stack_pointer(struct task_struct *task, struct pt_regs *regs)
80 if (regs)
81 return (unsigned long *)regs->sp;
83 if (task == current)
84 return __builtin_frame_address(0);
86 return (unsigned long *)task->thread.sp;
89 void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
90 unsigned long *stack, char *log_lvl);
92 /* The form of the top of the frame on the stack */
93 struct stack_frame {
94 struct stack_frame *next_frame;
95 unsigned long return_address;
98 struct stack_frame_ia32 {
99 u32 next_frame;
100 u32 return_address;
103 void show_opcodes(struct pt_regs *regs, const char *loglvl);
104 void show_ip(struct pt_regs *regs, const char *loglvl);
105 #endif /* _ASM_X86_STACKTRACE_H */