26a99f1c0541b730a4532d4d3db480faa5dcdc6a
[kernel/swap-modules.git] / uprobe / swap_uprobes.h
1 #ifndef _DBI_UPROBES_H
2 #define _DBI_UPROBES_H
3
4 /*
5  *  Dynamic Binary Instrumentation Module based on KProbes
6  *  modules/kprobe/dbi_uprobes.h
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21  *
22  * Copyright (C) Samsung Electronics, 2006-2010
23  *
24  * 2008-2009    Alexey Gerenkov <a.gerenkov@samsung.com> User-Space
25  *              Probes initial implementation; Support x86/ARM/MIPS for both user and kernel spaces.
26  * 2010         Ekaterina Gorelkina <e.gorelkina@samsung.com>: redesign module for separating core and arch parts
27  *
28  */
29
30 #include "dbi_kprobes.h"
31
32 struct uprobe {
33         struct kprobe kp;
34         struct task_struct *task;
35 };
36
37 typedef unsigned long (*uprobe_pre_entry_handler_t)(void *priv_arg, struct pt_regs * regs);
38
39 struct ujprobe {
40         struct uprobe up;
41         /* probe handling code to jump to */
42         void *entry;
43         // handler whichw willb bec called before 'entry'
44         uprobe_pre_entry_handler_t pre_entry;
45         void *priv_arg;
46 };
47
48 struct uretprobe_instance;
49
50 typedef int (*uretprobe_handler_t)(struct uretprobe_instance *, struct pt_regs *, void *);
51
52 /*
53  * Function-return probe -
54  * Note:
55  * User needs to provide a handler function, and initialize maxactive.
56  * maxactive - The maximum number of instances of the probed function that
57  * can be active concurrently.
58  * nmissed - tracks the number of times the probed function's return was
59  * ignored, due to maxactive being too low.
60  *
61  */
62 struct uretprobe {
63         struct uprobe up;
64         uretprobe_handler_t handler;
65         void *priv_arg;
66         int maxactive;
67         int nmissed;
68         struct hlist_head free_instances;
69         struct hlist_head used_instances;
70 };
71
72 struct uretprobe_instance {
73         /* either on free list or used list */
74         struct hlist_node uflist;
75         struct hlist_node hlist;
76         struct uretprobe *rp;
77         kprobe_opcode_t *ret_addr;
78         kprobe_opcode_t *sp;
79         struct task_struct *task;
80 };
81
82 int dbi_register_uprobe(struct uprobe *p, int atomic);
83 void dbi_unregister_uprobe(struct uprobe *p, int atomic);
84
85 int dbi_register_ujprobe(struct ujprobe *jp, int atomic);
86 void dbi_unregister_ujprobe(struct ujprobe *jp, int atomic);
87
88 int dbi_register_uretprobe(struct uretprobe *rp, int atomic);
89 void dbi_unregister_uretprobe(struct uretprobe *rp, int atomic);
90
91 void dbi_unregister_all_uprobes(struct task_struct *task, int atomic);
92
93 void dbi_uprobe_return(void);
94 struct kprobe *get_ukprobe(void *addr, pid_t tgid);
95 struct kprobe *get_ukprobe_by_insn_slot(void *addr, pid_t tgid, struct pt_regs *regs);
96
97 static inline struct uprobe *kp2up(struct kprobe *p)
98 {
99         return container_of(p, struct uprobe, kp);
100 }
101
102 static inline struct kprobe *up2kp(struct uprobe *p)
103 {
104         return &p->kp;
105 }
106
107 void disarm_uprobe(struct uprobe *p);
108
109 int trampoline_uprobe_handler(struct kprobe *p, struct pt_regs *regs);
110
111 #endif /*  _DBI_UPROBES_H */