blob: 2e41c50ddf47f414c8f2e4b0a99965ceafffb4bf [file] [log] [blame]
Frederic Weisbeckerc9cf4db2010-05-19 21:35:17 +02001/*
2 * Copyright (C) 1991, 1992 Linus Torvalds
3 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
4 */
5
H. Peter Anvin1965aae2008-10-22 22:26:29 -07006#ifndef _ASM_X86_STACKTRACE_H
7#define _ASM_X86_STACKTRACE_H
Andi Kleenc0b766f2006-09-26 10:52:34 +02008
Frederic Weisbeckerc9cf4db2010-05-19 21:35:17 +02009#include <linux/uaccess.h>
Soeren Sandmann Pedersen9c0729d2010-11-05 05:59:39 -040010#include <linux/ptrace.h>
Brian Gerst7b32aea2016-08-13 12:38:18 -040011#include <asm/switch_to.h>
Frederic Weisbeckerc9cf4db2010-05-19 21:35:17 +020012
Josh Poimboeufcb76c932016-09-14 21:07:42 -050013enum 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
22struct stack_info {
23 enum stack_type type;
24 unsigned long *begin, *end, *next_sp;
25};
26
27bool in_task_stack(unsigned long *stack, struct task_struct *task,
28 struct stack_info *info);
29
30int get_stack_info(unsigned long *stack, struct task_struct *task,
31 struct stack_info *info, unsigned long *visit_mask);
32
Josh Poimboeuf3d02a9c2016-11-18 11:46:23 -060033const char *stack_type_name(enum stack_type type);
Josh Poimboeufcb76c932016-09-14 21:07:42 -050034
35static 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 Weisbeckerc9cf4db2010-05-19 21:35:17 +020045#ifdef CONFIG_X86_32
46#define STACKSLOTS_PER_LINE 8
Frederic Weisbeckerc9cf4db2010-05-19 21:35:17 +020047#else
48#define STACKSLOTS_PER_LINE 4
Frederic Weisbeckerc9cf4db2010-05-19 21:35:17 +020049#endif
50
Soeren Sandmann Pedersen9c0729d2010-11-05 05:59:39 -040051#ifdef CONFIG_FRAME_POINTER
Josh Poimboeuf4b8afaf2016-08-24 11:50:17 -050052static inline unsigned long *
53get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
Soeren Sandmann Pedersen9c0729d2010-11-05 05:59:39 -040054{
Soeren Sandmann Pedersen9c0729d2010-11-05 05:59:39 -040055 if (regs)
Josh Poimboeuf4b8afaf2016-08-24 11:50:17 -050056 return (unsigned long *)regs->bp;
Soeren Sandmann Pedersen9c0729d2010-11-05 05:59:39 -040057
Josh Poimboeuf81539162016-09-16 08:05:20 -050058 if (task == current)
Josh Poimboeuf4b8afaf2016-08-24 11:50:17 -050059 return __builtin_frame_address(0);
Soeren Sandmann Pedersen9c0729d2010-11-05 05:59:39 -040060
Josh Poimboeuf2c96b2f2017-01-09 12:00:24 -060061 return &((struct inactive_task_frame *)task->thread.sp)->bp;
Soeren Sandmann Pedersen9c0729d2010-11-05 05:59:39 -040062}
63#else
Josh Poimboeuf4b8afaf2016-08-24 11:50:17 -050064static inline unsigned long *
65get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
Soeren Sandmann Pedersen9c0729d2010-11-05 05:59:39 -040066{
Josh Poimboeuf4b8afaf2016-08-24 11:50:17 -050067 return NULL;
Soeren Sandmann Pedersen9c0729d2010-11-05 05:59:39 -040068}
Josh Poimboeuf4b8afaf2016-08-24 11:50:17 -050069#endif /* CONFIG_FRAME_POINTER */
70
71static inline unsigned long *
72get_stack_pointer(struct task_struct *task, struct pt_regs *regs)
73{
74 if (regs)
75 return (unsigned long *)kernel_stack_pointer(regs);
76
Josh Poimboeuf81539162016-09-16 08:05:20 -050077 if (task == current)
Josh Poimboeuf4b8afaf2016-08-24 11:50:17 -050078 return __builtin_frame_address(0);
79
80 return (unsigned long *)task->thread.sp;
81}
Soeren Sandmann Pedersen9c0729d2010-11-05 05:59:39 -040082
Josh Poimboeufe18bccc2016-09-16 14:18:16 -050083void show_trace_log_lvl(struct task_struct *task, struct pt_regs *regs,
84 unsigned long *stack, char *log_lvl);
Frederic Weisbeckerc9cf4db2010-05-19 21:35:17 +020085
Frederic Weisbeckerc9cf4db2010-05-19 21:35:17 +020086extern unsigned int code_bytes;
87
88/* The form of the top of the frame on the stack */
89struct stack_frame {
90 struct stack_frame *next_frame;
91 unsigned long return_address;
92};
93
94struct stack_frame_ia32 {
95 u32 next_frame;
96 u32 return_address;
97};
98
Frederic Weisbeckerb0f82b82010-05-20 07:47:21 +020099static inline unsigned long caller_frame_pointer(void)
Frederic Weisbeckerc9cf4db2010-05-19 21:35:17 +0200100{
101 struct stack_frame *frame;
102
Josh Poimboeuf4b8afaf2016-08-24 11:50:17 -0500103 frame = __builtin_frame_address(0);
Frederic Weisbeckerc9cf4db2010-05-19 21:35:17 +0200104
105#ifdef CONFIG_FRAME_POINTER
Frederic Weisbeckerb0f82b82010-05-20 07:47:21 +0200106 frame = frame->next_frame;
Frederic Weisbeckerc9cf4db2010-05-19 21:35:17 +0200107#endif
108
109 return (unsigned long)frame;
110}
111
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700112#endif /* _ASM_X86_STACKTRACE_H */