2017-11-01 15:07:57 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2010-05-19 21:35:17 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 1991, 1992 Linus Torvalds
|
|
|
|
|
* Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
|
|
|
|
|
*/
|
|
|
|
|
|
2008-10-22 22:26:29 -07:00
|
|
|
#ifndef _ASM_X86_STACKTRACE_H
|
|
|
|
|
#define _ASM_X86_STACKTRACE_H
|
2006-09-26 10:52:34 +02:00
|
|
|
|
2010-05-19 21:35:17 +02:00
|
|
|
#include <linux/uaccess.h>
|
2010-11-05 05:59:39 -04:00
|
|
|
#include <linux/ptrace.h>
|
2019-04-14 17:59:55 +02:00
|
|
|
|
|
|
|
|
#include <asm/cpu_entry_area.h>
|
2016-08-13 12:38:18 -04:00
|
|
|
#include <asm/switch_to.h>
|
2010-05-19 21:35:17 +02:00
|
|
|
|
2016-09-14 21:07:42 -05:00
|
|
|
enum stack_type {
|
|
|
|
|
STACK_TYPE_UNKNOWN,
|
|
|
|
|
STACK_TYPE_TASK,
|
|
|
|
|
STACK_TYPE_IRQ,
|
|
|
|
|
STACK_TYPE_SOFTIRQ,
|
2017-12-04 17:25:07 -08:00
|
|
|
STACK_TYPE_ENTRY,
|
2016-09-14 21:07:42 -05:00
|
|
|
STACK_TYPE_EXCEPTION,
|
|
|
|
|
STACK_TYPE_EXCEPTION_LAST = STACK_TYPE_EXCEPTION + N_EXCEPTION_STACKS-1,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct stack_info {
|
|
|
|
|
enum stack_type type;
|
|
|
|
|
unsigned long *begin, *end, *next_sp;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bool in_task_stack(unsigned long *stack, struct task_struct *task,
|
|
|
|
|
struct stack_info *info);
|
|
|
|
|
|
2017-12-04 17:25:07 -08:00
|
|
|
bool in_entry_stack(unsigned long *stack, struct stack_info *info);
|
2017-12-04 15:07:13 +01:00
|
|
|
|
2016-09-14 21:07:42 -05:00
|
|
|
int get_stack_info(unsigned long *stack, struct task_struct *task,
|
|
|
|
|
struct stack_info *info, unsigned long *visit_mask);
|
2020-09-07 15:15:45 +02:00
|
|
|
bool get_stack_info_noinstr(unsigned long *stack, struct task_struct *task,
|
|
|
|
|
struct stack_info *info);
|
2016-09-14 21:07:42 -05:00
|
|
|
|
2021-09-15 17:12:59 +02:00
|
|
|
static __always_inline
|
|
|
|
|
bool get_stack_guard_info(unsigned long *stack, struct stack_info *info)
|
|
|
|
|
{
|
|
|
|
|
/* make sure it's not in the stack proper */
|
|
|
|
|
if (get_stack_info_noinstr(stack, current, info))
|
|
|
|
|
return false;
|
|
|
|
|
/* but if it is in the page below it, we hit a guard */
|
|
|
|
|
return get_stack_info_noinstr((void *)stack + PAGE_SIZE, current, info);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-18 11:46:23 -06:00
|
|
|
const char *stack_type_name(enum stack_type type);
|
2016-09-14 21:07:42 -05:00
|
|
|
|
|
|
|
|
static inline bool on_stack(struct stack_info *info, void *addr, size_t len)
|
|
|
|
|
{
|
|
|
|
|
void *begin = info->begin;
|
|
|
|
|
void *end = info->end;
|
|
|
|
|
|
|
|
|
|
return (info->type != STACK_TYPE_UNKNOWN &&
|
|
|
|
|
addr >= begin && addr < end &&
|
|
|
|
|
addr + len > begin && addr + len <= end);
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-19 21:35:17 +02:00
|
|
|
#ifdef CONFIG_X86_32
|
|
|
|
|
#define STACKSLOTS_PER_LINE 8
|
|
|
|
|
#else
|
|
|
|
|
#define STACKSLOTS_PER_LINE 4
|
|
|
|
|
#endif
|
|
|
|
|
|
2010-11-05 05:59:39 -04:00
|
|
|
#ifdef CONFIG_FRAME_POINTER
|
2016-08-24 11:50:17 -05:00
|
|
|
static inline unsigned long *
|
|
|
|
|
get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
|
2010-11-05 05:59:39 -04:00
|
|
|
{
|
|
|
|
|
if (regs)
|
2016-08-24 11:50:17 -05:00
|
|
|
return (unsigned long *)regs->bp;
|
2010-11-05 05:59:39 -04:00
|
|
|
|
2016-09-16 08:05:20 -05:00
|
|
|
if (task == current)
|
2016-08-24 11:50:17 -05:00
|
|
|
return __builtin_frame_address(0);
|
2010-11-05 05:59:39 -04:00
|
|
|
|
2017-01-09 12:00:24 -06:00
|
|
|
return &((struct inactive_task_frame *)task->thread.sp)->bp;
|
2010-11-05 05:59:39 -04:00
|
|
|
}
|
|
|
|
|
#else
|
2016-08-24 11:50:17 -05:00
|
|
|
static inline unsigned long *
|
|
|
|
|
get_frame_pointer(struct task_struct *task, struct pt_regs *regs)
|
2010-11-05 05:59:39 -04:00
|
|
|
{
|
2016-08-24 11:50:17 -05:00
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
#endif /* CONFIG_FRAME_POINTER */
|
|
|
|
|
|
|
|
|
|
static inline unsigned long *
|
|
|
|
|
get_stack_pointer(struct task_struct *task, struct pt_regs *regs)
|
|
|
|
|
{
|
|
|
|
|
if (regs)
|
2019-05-07 23:25:54 +02:00
|
|
|
return (unsigned long *)regs->sp;
|
2016-08-24 11:50:17 -05:00
|
|
|
|
2016-09-16 08:05:20 -05:00
|
|
|
if (task == current)
|
2016-08-24 11:50:17 -05:00
|
|
|
return __builtin_frame_address(0);
|
|
|
|
|
|
|
|
|
|
return (unsigned long *)task->thread.sp;
|
2010-11-05 05:59:39 -04:00
|
|
|
}
|
|
|
|
|
|
2010-05-19 21:35:17 +02:00
|
|
|
/* The form of the top of the frame on the stack */
|
|
|
|
|
struct stack_frame {
|
|
|
|
|
struct stack_frame *next_frame;
|
|
|
|
|
unsigned long return_address;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct stack_frame_ia32 {
|
|
|
|
|
u32 next_frame;
|
|
|
|
|
u32 return_address;
|
|
|
|
|
};
|
|
|
|
|
|
2018-08-28 17:49:01 +02:00
|
|
|
void show_opcodes(struct pt_regs *regs, const char *loglvl);
|
2018-04-17 18:11:22 +02:00
|
|
|
void show_ip(struct pt_regs *regs, const char *loglvl);
|
2008-10-22 22:26:29 -07:00
|
|
|
#endif /* _ASM_X86_STACKTRACE_H */
|