fsi: Add regmap and refactor sbefifo
[linux-block.git] / include / linux / uprobes.h
CommitLineData
1a59d1b8 1/* SPDX-License-Identifier: GPL-2.0-or-later */
2b144498
SD
2#ifndef _LINUX_UPROBES_H
3#define _LINUX_UPROBES_H
4/*
7b2d81d4 5 * User-space Probes (UProbes)
2b144498 6 *
35aa621b 7 * Copyright (C) IBM Corporation, 2008-2012
2b144498
SD
8 * Authors:
9 * Srikar Dronamraju
10 * Jim Keniston
90eec103 11 * Copyright (C) 2011-2012 Red Hat, Inc., Peter Zijlstra
2b144498
SD
12 */
13
14#include <linux/errno.h>
15#include <linux/rbtree.h>
32473431 16#include <linux/types.h>
e8f4aa60 17#include <linux/wait.h>
2b144498
SD
18
19struct vm_area_struct;
d4b3b638
SD
20struct mm_struct;
21struct inode;
3820b4d2 22struct notifier_block;
72e6ae28 23struct page;
0326f5a9 24
da1816b1
ON
25#define UPROBE_HANDLER_REMOVE 1
26#define UPROBE_HANDLER_MASK 1
27
ded49c55
AA
28#define MAX_URETPROBE_DEPTH 64
29
8a7f2fa0
ON
30enum uprobe_filter_ctx {
31 UPROBE_FILTER_REGISTER,
32 UPROBE_FILTER_UNREGISTER,
33 UPROBE_FILTER_MMAP,
34};
35
2b144498
SD
36struct uprobe_consumer {
37 int (*handler)(struct uprobe_consumer *self, struct pt_regs *regs);
ea024870
AA
38 int (*ret_handler)(struct uprobe_consumer *self,
39 unsigned long func,
40 struct pt_regs *regs);
8a7f2fa0
ON
41 bool (*filter)(struct uprobe_consumer *self,
42 enum uprobe_filter_ctx ctx,
43 struct mm_struct *mm);
2b144498
SD
44
45 struct uprobe_consumer *next;
46};
47
2b144498 48#ifdef CONFIG_UPROBES
c912dae6
ON
49#include <asm/uprobes.h>
50
0326f5a9
SD
51enum uprobe_task_state {
52 UTASK_RUNNING,
0326f5a9
SD
53 UTASK_SSTEP,
54 UTASK_SSTEP_ACK,
55 UTASK_SSTEP_TRAPPED,
56};
57
58/*
59 * uprobe_task: Metadata of a task while it singlesteps.
60 */
61struct uprobe_task {
62 enum uprobe_task_state state;
0326f5a9 63
32473431
ON
64 union {
65 struct {
66 struct arch_uprobe_task autask;
67 unsigned long vaddr;
68 };
69
70 struct {
71 struct callback_head dup_xol_work;
72 unsigned long dup_xol_addr;
73 };
74 };
0326f5a9 75
32473431 76 struct uprobe *active_uprobe;
0326f5a9 77 unsigned long xol_vaddr;
32473431
ON
78
79 struct return_instance *return_instances;
80 unsigned int depth;
0326f5a9
SD
81};
82
97da8976
ON
83struct return_instance {
84 struct uprobe *uprobe;
85 unsigned long func;
7b868e48 86 unsigned long stack; /* stack pointer */
97da8976
ON
87 unsigned long orig_ret_vaddr; /* original return address */
88 bool chained; /* true, if instance is nested */
89
90 struct return_instance *next; /* keep as stack */
91};
92
86dcb702
ON
93enum rp_check {
94 RP_CHECK_CALL,
db087ef6 95 RP_CHECK_CHAIN_CALL,
86dcb702
ON
96 RP_CHECK_RET,
97};
98
c912dae6 99struct xol_area;
d4b3b638
SD
100
101struct uprobes_state {
102 struct xol_area *xol_area;
103};
647c42df 104
aad42dd4 105extern void __init uprobes_init(void);
271a9c35
BH
106extern int set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
107extern int set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
108extern bool is_swbp_insn(uprobe_opcode_t *insn);
109extern bool is_trap_insn(uprobe_opcode_t *insn);
110extern unsigned long uprobe_get_swbp_addr(struct pt_regs *regs);
b02ef20a 111extern unsigned long uprobe_get_trap_addr(struct pt_regs *regs);
6d43743e 112extern int uprobe_write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm, unsigned long vaddr, uprobe_opcode_t);
e3343e6a 113extern int uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
1cc33161 114extern int uprobe_register_refctr(struct inode *inode, loff_t offset, loff_t ref_ctr_offset, struct uprobe_consumer *uc);
bdf8647c 115extern int uprobe_apply(struct inode *inode, loff_t offset, struct uprobe_consumer *uc, bool);
e3343e6a 116extern void uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *uc);
7b2d81d4 117extern int uprobe_mmap(struct vm_area_struct *vma);
cbc91f71 118extern void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end);
32cdba1e
ON
119extern void uprobe_start_dup_mmap(void);
120extern void uprobe_end_dup_mmap(void);
f8ac4ec9 121extern void uprobe_dup_mmap(struct mm_struct *oldmm, struct mm_struct *newmm);
0326f5a9 122extern void uprobe_free_utask(struct task_struct *t);
3ab67966 123extern void uprobe_copy_process(struct task_struct *t, unsigned long flags);
0326f5a9
SD
124extern int uprobe_post_sstep_notifier(struct pt_regs *regs);
125extern int uprobe_pre_sstep_notifier(struct pt_regs *regs);
126extern void uprobe_notify_resume(struct pt_regs *regs);
127extern bool uprobe_deny_signal(void);
c2d3f25d 128extern bool arch_uprobe_skip_sstep(struct arch_uprobe *aup, struct pt_regs *regs);
d4b3b638 129extern void uprobe_clear_state(struct mm_struct *mm);
3820b4d2
DL
130extern int arch_uprobe_analyze_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long addr);
131extern int arch_uprobe_pre_xol(struct arch_uprobe *aup, struct pt_regs *regs);
132extern int arch_uprobe_post_xol(struct arch_uprobe *aup, struct pt_regs *regs);
133extern bool arch_uprobe_xol_was_trapped(struct task_struct *tsk);
134extern int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val, void *data);
135extern void arch_uprobe_abort_xol(struct arch_uprobe *aup, struct pt_regs *regs);
136extern unsigned long arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs *regs);
86dcb702 137extern bool arch_uretprobe_is_alive(struct return_instance *ret, enum rp_check ctx, struct pt_regs *regs);
271a9c35
BH
138extern bool arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
139extern void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
72e6ae28 140 void *src, unsigned long len);
0326f5a9 141#else /* !CONFIG_UPROBES */
d4b3b638
SD
142struct uprobes_state {
143};
b02ef20a 144
aad42dd4
NA
145static inline void uprobes_init(void)
146{
147}
148
b02ef20a
ON
149#define uprobe_get_trap_addr(regs) instruction_pointer(regs)
150
7b2d81d4 151static inline int
e3343e6a 152uprobe_register(struct inode *inode, loff_t offset, struct uprobe_consumer *uc)
1cc33161
RB
153{
154 return -ENOSYS;
155}
156static inline int uprobe_register_refctr(struct inode *inode, loff_t offset, loff_t ref_ctr_offset, struct uprobe_consumer *uc)
2b144498
SD
157{
158 return -ENOSYS;
159}
bdf8647c
ON
160static inline int
161uprobe_apply(struct inode *inode, loff_t offset, struct uprobe_consumer *uc, bool add)
162{
163 return -ENOSYS;
164}
7b2d81d4 165static inline void
e3343e6a 166uprobe_unregister(struct inode *inode, loff_t offset, struct uprobe_consumer *uc)
2b144498
SD
167{
168}
7b2d81d4 169static inline int uprobe_mmap(struct vm_area_struct *vma)
2b144498
SD
170{
171 return 0;
172}
cbc91f71
SD
173static inline void
174uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end)
682968e0
SD
175{
176}
32cdba1e
ON
177static inline void uprobe_start_dup_mmap(void)
178{
179}
180static inline void uprobe_end_dup_mmap(void)
181{
182}
f8ac4ec9
ON
183static inline void
184uprobe_dup_mmap(struct mm_struct *oldmm, struct mm_struct *newmm)
185{
186}
0326f5a9
SD
187static inline void uprobe_notify_resume(struct pt_regs *regs)
188{
189}
190static inline bool uprobe_deny_signal(void)
191{
192 return false;
193}
0326f5a9
SD
194static inline void uprobe_free_utask(struct task_struct *t)
195{
196}
3ab67966 197static inline void uprobe_copy_process(struct task_struct *t, unsigned long flags)
0326f5a9
SD
198{
199}
d4b3b638
SD
200static inline void uprobe_clear_state(struct mm_struct *mm)
201{
202}
0326f5a9 203#endif /* !CONFIG_UPROBES */
2b144498 204#endif /* _LINUX_UPROBES_H */