[REFACTOR] remove unnecessary functions declaration
[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/uprobe/swap_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 <kprobe/dbi_kprobes.h>
31 #include <uprobe/arch/asm/swap_uprobes.h>
32
33
34 struct uprobe {
35         struct kprobe kp;
36         struct task_struct *task;
37         struct slot_manager *sm;
38         struct arch_specific_tramp atramp;
39 };
40
41 typedef unsigned long (*uprobe_pre_entry_handler_t)(void *priv_arg, struct pt_regs * regs);
42
43 struct ujprobe {
44         struct uprobe up;
45         /* probe handling code to jump to */
46         void *entry;
47         // handler whichw willb bec called before 'entry'
48         uprobe_pre_entry_handler_t pre_entry;
49         void *priv_arg;
50         char *args;
51 };
52
53 struct uretprobe_instance;
54
55 typedef int (*uretprobe_handler_t)(struct uretprobe_instance *, struct pt_regs *);
56
57 /*
58  * Function-return probe -
59  * Note:
60  * User needs to provide a handler function, and initialize maxactive.
61  * maxactive - The maximum number of instances of the probed function that
62  * can be active concurrently.
63  * nmissed - tracks the number of times the probed function's return was
64  * ignored, due to maxactive being too low.
65  *
66  */
67 struct uretprobe {
68         struct uprobe up;
69         uretprobe_handler_t handler;
70         uretprobe_handler_t entry_handler;
71         int maxactive;
72         int nmissed;
73         struct hlist_head free_instances;
74         struct hlist_head used_instances;
75
76 #ifdef CONFIG_ARM
77         /* probe with noreturn (bl,blx) */
78         unsigned arm_noret:1;
79         unsigned thumb_noret:1;
80 #endif
81 };
82
83 struct uretprobe_instance {
84         /* either on free list or used list */
85         struct hlist_node uflist;
86         struct hlist_node hlist;
87         struct uretprobe *rp;
88         kprobe_opcode_t *ret_addr;
89         kprobe_opcode_t *sp;
90         struct task_struct *task;
91 };
92
93 int dbi_register_uprobe(struct uprobe *p);
94 void dbi_unregister_uprobe(struct uprobe *p);
95 void __dbi_unregister_uprobe(struct uprobe *up, int disarm);
96
97 int dbi_register_ujprobe(struct ujprobe *jp);
98 void dbi_unregister_ujprobe(struct ujprobe *jp);
99 void __dbi_unregister_ujprobe(struct ujprobe *jp, int disarm);
100
101 int dbi_register_uretprobe(struct uretprobe *rp);
102 void dbi_unregister_uretprobe(struct uretprobe *rp);
103 void __dbi_unregister_uretprobe(struct uretprobe *rp, int disarm);
104
105 void dbi_unregister_all_uprobes(struct task_struct *task);
106 void dbi_discard_pending_uretprobes(struct task_struct *task);
107
108 void swap_ujprobe_return(void);
109 struct kprobe *get_ukprobe(void *addr, pid_t tgid);
110 struct kprobe *get_ukprobe_by_insn_slot(void *addr, pid_t tgid, struct pt_regs *regs);
111
112 static inline struct uprobe *kp2up(struct kprobe *p)
113 {
114         return container_of(p, struct uprobe, kp);
115 }
116
117 static inline struct kprobe *up2kp(struct uprobe *p)
118 {
119         return &p->kp;
120 }
121
122 void disarm_uprobe(struct kprobe *p, struct task_struct *task);
123
124 int trampoline_uprobe_handler(struct kprobe *p, struct pt_regs *regs);
125
126 void add_uprobe_table(struct kprobe *p);
127
128 #endif /*  _DBI_UPROBES_H */