Merge remote-tracking branches 'asoc/topic/mc13783', 'asoc/topic/msm8916', 'asoc...
[linux-2.6-block.git] / arch / x86 / include / asm / unwind.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
7c7900f8
JP
2#ifndef _ASM_X86_UNWIND_H
3#define _ASM_X86_UNWIND_H
4
5#include <linux/sched.h>
6#include <linux/ftrace.h>
7#include <asm/ptrace.h>
8#include <asm/stacktrace.h>
9
b02fcf9b
JP
10#define IRET_FRAME_OFFSET (offsetof(struct pt_regs, ip))
11#define IRET_FRAME_SIZE (sizeof(struct pt_regs) - IRET_FRAME_OFFSET)
12
7c7900f8
JP
13struct unwind_state {
14 struct stack_info stack_info;
15 unsigned long stack_mask;
16 struct task_struct *task;
17 int graph_idx;
af085d90 18 bool error;
11af8474 19#if defined(CONFIG_UNWINDER_ORC)
ee9f8fce
JP
20 bool signal, full_regs;
21 unsigned long sp, bp, ip;
22 struct pt_regs *regs;
11af8474 23#elif defined(CONFIG_UNWINDER_FRAME_POINTER)
a8b7a923 24 bool got_irq;
ee9f8fce 25 unsigned long *bp, *orig_sp, ip;
946c1911 26 struct pt_regs *regs;
7c7900f8
JP
27#else
28 unsigned long *sp;
29#endif
30};
31
32void __unwind_start(struct unwind_state *state, struct task_struct *task,
33 struct pt_regs *regs, unsigned long *first_frame);
7c7900f8 34bool unwind_next_frame(struct unwind_state *state);
cfee9edd 35unsigned long unwind_get_return_address(struct unwind_state *state);
ee9f8fce 36unsigned long *unwind_get_return_address_ptr(struct unwind_state *state);
cfee9edd 37
7c7900f8
JP
38static inline bool unwind_done(struct unwind_state *state)
39{
40 return state->stack_info.type == STACK_TYPE_UNKNOWN;
41}
42
af085d90
JP
43static inline bool unwind_error(struct unwind_state *state)
44{
45 return state->error;
46}
47
7c7900f8 48static inline
ee9f8fce
JP
49void unwind_start(struct unwind_state *state, struct task_struct *task,
50 struct pt_regs *regs, unsigned long *first_frame)
7c7900f8 51{
ee9f8fce 52 first_frame = first_frame ? : get_stack_pointer(task, regs);
7c7900f8 53
ee9f8fce 54 __unwind_start(state, task, regs, first_frame);
946c1911
JP
55}
56
11af8474 57#if defined(CONFIG_UNWINDER_ORC) || defined(CONFIG_UNWINDER_FRAME_POINTER)
b02fcf9b
JP
58/*
59 * WARNING: The entire pt_regs may not be safe to dereference. In some cases,
60 * only the iret frame registers are accessible. Use with caution!
61 */
946c1911
JP
62static inline struct pt_regs *unwind_get_entry_regs(struct unwind_state *state)
63{
64 if (unwind_done(state))
65 return NULL;
66
67 return state->regs;
7c7900f8 68}
ee9f8fce
JP
69#else
70static inline struct pt_regs *unwind_get_entry_regs(struct unwind_state *state)
7c7900f8
JP
71{
72 return NULL;
73}
ee9f8fce 74#endif
7c7900f8 75
11af8474 76#ifdef CONFIG_UNWINDER_ORC
ee9f8fce
JP
77void unwind_init(void);
78void unwind_module_init(struct module *mod, void *orc_ip, size_t orc_ip_size,
79 void *orc, size_t orc_size);
80#else
81static inline void unwind_init(void) {}
82static inline
83void unwind_module_init(struct module *mod, void *orc_ip, size_t orc_ip_size,
84 void *orc, size_t orc_size) {}
85#endif
86
87/*
88 * This disables KASAN checking when reading a value from another task's stack,
89 * since the other task could be running on another CPU and could have poisoned
90 * the stack in the meantime.
91 */
92#define READ_ONCE_TASK_STACK(task, x) \
93({ \
94 unsigned long val; \
95 if (task == current) \
96 val = READ_ONCE(x); \
97 else \
98 val = READ_ONCE_NOCHECK(x); \
99 val; \
100})
101
102static inline bool task_on_another_cpu(struct task_struct *task)
946c1911 103{
ee9f8fce
JP
104#ifdef CONFIG_SMP
105 return task != current && task->on_cpu;
106#else
107 return false;
108#endif
946c1911
JP
109}
110
7c7900f8 111#endif /* _ASM_X86_UNWIND_H */