Merge branch 'address-masking'
[linux-2.6-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 18
3c83a9ad 19struct uprobe;
2b144498 20struct vm_area_struct;
d4b3b638
SD
21struct mm_struct;
22struct inode;
3820b4d2 23struct notifier_block;
72e6ae28 24struct page;
0326f5a9 25
da1816b1
ON
26#define UPROBE_HANDLER_REMOVE 1
27#define UPROBE_HANDLER_MASK 1
28
ded49c55
AA
29#define MAX_URETPROBE_DEPTH 64
30
2b144498 31struct uprobe_consumer {
cc01bd04
AN
32 /*
33 * handler() can return UPROBE_HANDLER_REMOVE to signal the need to
34 * unregister uprobe for current process. If UPROBE_HANDLER_REMOVE is
35 * returned, filter() callback has to be implemented as well and it
36 * should return false to "confirm" the decision to uninstall uprobe
37 * for the current process. If filter() is omitted or returns true,
38 * UPROBE_HANDLER_REMOVE is effectively ignored.
39 */
2b144498 40 int (*handler)(struct uprobe_consumer *self, struct pt_regs *regs);
ea024870
AA
41 int (*ret_handler)(struct uprobe_consumer *self,
42 unsigned long func,
43 struct pt_regs *regs);
59da880a 44 bool (*filter)(struct uprobe_consumer *self, struct mm_struct *mm);
2b144498 45
cc01bd04 46 struct list_head cons_node;
2b144498
SD
47};
48
2b144498 49#ifdef CONFIG_UPROBES
c912dae6
ON
50#include <asm/uprobes.h>
51
0326f5a9
SD
52enum uprobe_task_state {
53 UTASK_RUNNING,
0326f5a9
SD
54 UTASK_SSTEP,
55 UTASK_SSTEP_ACK,
56 UTASK_SSTEP_TRAPPED,
57};
58
59/*
60 * uprobe_task: Metadata of a task while it singlesteps.
61 */
62struct uprobe_task {
63 enum uprobe_task_state state;
0326f5a9 64
32473431
ON
65 union {
66 struct {
67 struct arch_uprobe_task autask;
68 unsigned long vaddr;
69 };
70
71 struct {
72 struct callback_head dup_xol_work;
73 unsigned long dup_xol_addr;
74 };
75 };
0326f5a9 76
32473431 77 struct uprobe *active_uprobe;
0326f5a9 78 unsigned long xol_vaddr;
32473431 79
cfa7f3d2
AN
80 struct arch_uprobe *auprobe;
81
32473431
ON
82 struct return_instance *return_instances;
83 unsigned int depth;
0326f5a9
SD
84};
85
97da8976
ON
86struct return_instance {
87 struct uprobe *uprobe;
88 unsigned long func;
7b868e48 89 unsigned long stack; /* stack pointer */
97da8976
ON
90 unsigned long orig_ret_vaddr; /* original return address */
91 bool chained; /* true, if instance is nested */
92
93 struct return_instance *next; /* keep as stack */
94};
95
86dcb702
ON
96enum rp_check {
97 RP_CHECK_CALL,
db087ef6 98 RP_CHECK_CHAIN_CALL,
86dcb702
ON
99 RP_CHECK_RET,
100};
101
c912dae6 102struct xol_area;
d4b3b638
SD
103
104struct uprobes_state {
105 struct xol_area *xol_area;
106};
647c42df 107
aad42dd4 108extern void __init uprobes_init(void);
271a9c35
BH
109extern int set_swbp(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
110extern int set_orig_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long vaddr);
111extern bool is_swbp_insn(uprobe_opcode_t *insn);
112extern bool is_trap_insn(uprobe_opcode_t *insn);
113extern unsigned long uprobe_get_swbp_addr(struct pt_regs *regs);
b02ef20a 114extern unsigned long uprobe_get_trap_addr(struct pt_regs *regs);
6d43743e 115extern int uprobe_write_opcode(struct arch_uprobe *auprobe, struct mm_struct *mm, unsigned long vaddr, uprobe_opcode_t);
3c83a9ad
ON
116extern struct uprobe *uprobe_register(struct inode *inode, loff_t offset, loff_t ref_ctr_offset, struct uprobe_consumer *uc);
117extern int uprobe_apply(struct uprobe *uprobe, struct uprobe_consumer *uc, bool);
04b01625
PZ
118extern void uprobe_unregister_nosync(struct uprobe *uprobe, struct uprobe_consumer *uc);
119extern void uprobe_unregister_sync(void);
7b2d81d4 120extern int uprobe_mmap(struct vm_area_struct *vma);
cbc91f71 121extern void uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end);
32cdba1e
ON
122extern void uprobe_start_dup_mmap(void);
123extern void uprobe_end_dup_mmap(void);
f8ac4ec9 124extern void uprobe_dup_mmap(struct mm_struct *oldmm, struct mm_struct *newmm);
0326f5a9 125extern void uprobe_free_utask(struct task_struct *t);
3ab67966 126extern void uprobe_copy_process(struct task_struct *t, unsigned long flags);
0326f5a9
SD
127extern int uprobe_post_sstep_notifier(struct pt_regs *regs);
128extern int uprobe_pre_sstep_notifier(struct pt_regs *regs);
129extern void uprobe_notify_resume(struct pt_regs *regs);
130extern bool uprobe_deny_signal(void);
c2d3f25d 131extern bool arch_uprobe_skip_sstep(struct arch_uprobe *aup, struct pt_regs *regs);
d4b3b638 132extern void uprobe_clear_state(struct mm_struct *mm);
3820b4d2
DL
133extern int arch_uprobe_analyze_insn(struct arch_uprobe *aup, struct mm_struct *mm, unsigned long addr);
134extern int arch_uprobe_pre_xol(struct arch_uprobe *aup, struct pt_regs *regs);
135extern int arch_uprobe_post_xol(struct arch_uprobe *aup, struct pt_regs *regs);
136extern bool arch_uprobe_xol_was_trapped(struct task_struct *tsk);
137extern int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val, void *data);
138extern void arch_uprobe_abort_xol(struct arch_uprobe *aup, struct pt_regs *regs);
139extern unsigned long arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs *regs);
86dcb702 140extern bool arch_uretprobe_is_alive(struct return_instance *ret, enum rp_check ctx, struct pt_regs *regs);
271a9c35
BH
141extern bool arch_uprobe_ignore(struct arch_uprobe *aup, struct pt_regs *regs);
142extern void arch_uprobe_copy_ixol(struct page *page, unsigned long vaddr,
72e6ae28 143 void *src, unsigned long len);
ff474a78
JO
144extern void uprobe_handle_trampoline(struct pt_regs *regs);
145extern void *arch_uprobe_trampoline(unsigned long *psize);
146extern unsigned long uprobe_get_trampoline_vaddr(void);
0326f5a9 147#else /* !CONFIG_UPROBES */
d4b3b638
SD
148struct uprobes_state {
149};
b02ef20a 150
aad42dd4
NA
151static inline void uprobes_init(void)
152{
153}
154
b02ef20a
ON
155#define uprobe_get_trap_addr(regs) instruction_pointer(regs)
156
3c83a9ad 157static inline struct uprobe *
e04332eb 158uprobe_register(struct inode *inode, loff_t offset, loff_t ref_ctr_offset, struct uprobe_consumer *uc)
2b144498 159{
3c83a9ad 160 return ERR_PTR(-ENOSYS);
2b144498 161}
bdf8647c 162static inline int
3c83a9ad 163uprobe_apply(struct uprobe* uprobe, struct uprobe_consumer *uc, bool add)
bdf8647c
ON
164{
165 return -ENOSYS;
166}
7b2d81d4 167static inline void
04b01625
PZ
168uprobe_unregister_nosync(struct uprobe *uprobe, struct uprobe_consumer *uc)
169{
170}
171static inline void uprobe_unregister_sync(void)
2b144498
SD
172{
173}
7b2d81d4 174static inline int uprobe_mmap(struct vm_area_struct *vma)
2b144498
SD
175{
176 return 0;
177}
cbc91f71
SD
178static inline void
179uprobe_munmap(struct vm_area_struct *vma, unsigned long start, unsigned long end)
682968e0
SD
180{
181}
32cdba1e
ON
182static inline void uprobe_start_dup_mmap(void)
183{
184}
185static inline void uprobe_end_dup_mmap(void)
186{
187}
f8ac4ec9
ON
188static inline void
189uprobe_dup_mmap(struct mm_struct *oldmm, struct mm_struct *newmm)
190{
191}
0326f5a9
SD
192static inline void uprobe_notify_resume(struct pt_regs *regs)
193{
194}
195static inline bool uprobe_deny_signal(void)
196{
197 return false;
198}
0326f5a9
SD
199static inline void uprobe_free_utask(struct task_struct *t)
200{
201}
3ab67966 202static inline void uprobe_copy_process(struct task_struct *t, unsigned long flags)
0326f5a9
SD
203{
204}
d4b3b638
SD
205static inline void uprobe_clear_state(struct mm_struct *mm)
206{
207}
0326f5a9 208#endif /* !CONFIG_UPROBES */
2b144498 209#endif /* _LINUX_UPROBES_H */