Merge branch 'tizen_2.4' into tizen_2.4_dev
[kernel/swap-modules.git] / uprobe / arch / arm / swap-asm / swap_uprobes.h
1 /**
2  * @file uprobe/arch/asm-arm/swap_uprobes.h
3  * @author Alexey Gerenkov <a.gerenkov@samsung.com> User-Space Probes initial
4  * implementation; Support x86/ARM/MIPS for both user and kernel spaces.
5  * @author Ekaterina Gorelkina <e.gorelkina@samsung.com>: redesign module for
6  * separating core and arch parts
7  *
8  * @section LICENSE
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23  *
24  * @section COPYRIGHT
25  *
26  * Copyright (C) Samsung Electronics, 2006-2010
27  *
28  * @section DESCRIPTION
29  *
30  * Arch-dependent uprobe interface declaration.
31  */
32
33
34 #ifndef _ARM_SWAP_UPROBES_H
35 #define _ARM_SWAP_UPROBES_H
36
37
38 #include <linux/uaccess.h>
39 #include <swap-asm/swap_kprobes.h>      /* FIXME: for UPROBES_TRAMP_LEN */
40
41
42 struct task_struct;
43 struct uprobe;
44 struct uretprobe;
45 struct uretprobe_instance;
46
47 typedef unsigned long uprobe_opcode_t;
48
49 /**
50  * @struct arch_insn
51  * @brief Architecture depend copy of original instruction.
52  * @var arch_insn::insn
53  * Copy of the original instruction.
54  */
55 struct arch_insn {
56         uprobe_opcode_t *insn;
57 };
58
59 /**
60  * @struct arch_tramp
61  * @brief Stores arch-dependent trampolines.
62  */
63 struct arch_tramp {
64         unsigned long tramp_arm[UPROBES_TRAMP_LEN];     /**< ARM trampoline */
65         unsigned long tramp_thumb[UPROBES_TRAMP_LEN];   /**< Thumb trampoline */
66         void *utramp;                                   /**< Pointer to trampoline */
67 };
68
69
70 static inline u32 swap_get_urp_float(struct pt_regs *regs)
71 {
72         return regs->ARM_r0;
73 }
74
75 static inline u64 swap_get_urp_double(struct pt_regs *regs)
76 {
77
78         return regs->ARM_r0 | (u64)regs->ARM_r1 << 32;
79 }
80
81 static inline void arch_ujprobe_return(void)
82 {
83 }
84
85 int arch_prepare_uprobe(struct uprobe *up);
86
87 int setjmp_upre_handler(struct uprobe *p, struct pt_regs *regs);
88 static inline int longjmp_break_uhandler(struct uprobe *p, struct pt_regs *regs)
89 {
90         return 0;
91 }
92
93 void arch_opcode_analysis_uretprobe(struct uretprobe *rp);
94 int arch_prepare_uretprobe(struct uretprobe_instance *ri, struct pt_regs *regs);
95 int arch_disarm_urp_inst(struct uretprobe_instance *ri,
96                          struct task_struct *task, unsigned long tr);
97 unsigned long arch_tramp_by_ri(struct uretprobe_instance *ri);
98
99 unsigned long arch_get_trampoline_addr(struct uprobe *p, struct pt_regs *regs);
100 void arch_set_orig_ret_addr(unsigned long orig_ret_addr, struct pt_regs *regs);
101 void arch_remove_uprobe(struct uprobe *up);
102 int arch_arm_uprobe(struct uprobe *p);
103 void arch_disarm_uprobe(struct uprobe *p, struct task_struct *task);
104
105 static inline unsigned long swap_get_uarg(struct pt_regs *regs, unsigned long n)
106 {
107         u32 *ptr, addr = 0;
108
109         switch (n) {
110         case 0:
111                 return regs->ARM_r0;
112         case 1:
113                 return regs->ARM_r1;
114         case 2:
115                 return regs->ARM_r2;
116         case 3:
117                 return regs->ARM_r3;
118         }
119
120         ptr = (u32 *)regs->ARM_sp + n - 4;
121         if (get_user(addr, ptr))
122                 printk(KERN_INFO "failed to dereference a pointer, ptr=%p\n",
123                        ptr);
124
125         return addr;
126 }
127
128 static inline void swap_put_uarg(struct pt_regs *regs, unsigned long n,
129                                  unsigned long val)
130 {
131         u32 *ptr;
132
133         switch (n) {
134         case 0:
135                 regs->ARM_r0 = val;
136                 break;
137         case 1:
138                 regs->ARM_r1 = val;
139                 break;
140         case 2:
141                 regs->ARM_r2 = val;
142                 break;
143         case 3:
144                 regs->ARM_r3 = val;
145                 break;
146         default:
147                 ptr = (u32 *)regs->ARM_sp + n - 4;
148                 if (put_user(val, ptr))
149                         pr_err("failed to dereference a pointer[%p]\n", ptr);
150         }
151 }
152
153 int swap_arch_init_uprobes(void);
154 void swap_arch_exit_uprobes(void);
155
156 #endif /* _ARM_SWAP_UPROBES_H */