^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (C) 1991, 1992 Linus Torvalds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #ifndef _ASM_X86_STACKTRACE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #define _ASM_X86_STACKTRACE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/ptrace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/cpu_entry_area.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/switch_to.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) enum stack_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) STACK_TYPE_UNKNOWN,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) STACK_TYPE_TASK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) STACK_TYPE_IRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) STACK_TYPE_SOFTIRQ,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) STACK_TYPE_ENTRY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) STACK_TYPE_EXCEPTION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) STACK_TYPE_EXCEPTION_LAST = STACK_TYPE_EXCEPTION + N_EXCEPTION_STACKS-1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) struct stack_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) enum stack_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) unsigned long *begin, *end, *next_sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) bool in_task_stack(unsigned long *stack, struct task_struct *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct stack_info *info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) bool in_entry_stack(unsigned long *stack, struct stack_info *info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) int get_stack_info(unsigned long *stack, struct task_struct *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) struct stack_info *info, unsigned long *visit_mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) bool get_stack_info_noinstr(unsigned long *stack, struct task_struct *task,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct stack_info *info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) const char *stack_type_name(enum stack_type type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) static inline bool on_stack(struct stack_info *info, void *addr, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) void *begin = info->begin;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) void *end = info->end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) return (info->type != STACK_TYPE_UNKNOWN &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) addr >= begin && addr < end &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) addr + len > begin && addr + len <= end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #ifdef CONFIG_X86_32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) #define STACKSLOTS_PER_LINE 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #define STACKSLOTS_PER_LINE 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) #ifdef CONFIG_FRAME_POINTER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static inline unsigned long *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) return (unsigned long *)regs->bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) if (task == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) return __builtin_frame_address(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) return &((struct inactive_task_frame *)task->thread.sp)->bp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static inline unsigned long *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) #endif /* CONFIG_FRAME_POINTER */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static inline unsigned long *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) get_stack_pointer(struct task_struct *task, struct pt_regs *regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) if (regs)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) return (unsigned long *)regs->sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (task == current)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return __builtin_frame_address(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) return (unsigned long *)task->thread.sp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) unsigned long *stack, const char *log_lvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) /* The form of the top of the frame on the stack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) struct stack_frame {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct stack_frame *next_frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) unsigned long return_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) struct stack_frame_ia32 {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) u32 next_frame;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) u32 return_address;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) void show_opcodes(struct pt_regs *regs, const char *loglvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) void show_ip(struct pt_regs *regs, const char *loglvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) #endif /* _ASM_X86_STACKTRACE_H */