Merge branch 'tizen_2.4' into tizen_2.4_dev
[kernel/swap-modules.git] / uprobe / arch / x86 / swap-asm / swap_uprobes.h
1 /**
2  * @file uprobe/arch/asm-x86/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 #ifndef _X86_SWAP_UPROBES_H
34 #define _X86_SWAP_UPROBES_H
35
36
37 #include <swap-asm/swap_kprobes.h>      /* FIXME: for UPROBES_TRAMP_LEN */
38
39
40 struct uprobe;
41 struct uretprobe;
42 struct uretprobe_instance;
43
44 typedef u8 uprobe_opcode_t;
45
46 /**
47  * @struct arch_insn
48  * @brief Architecture depend copy of original instruction.
49  * @var arch_insn::insn
50  * Copy of the original instruction.
51  * @var arch_insn::boostable
52  * If this flag is not 0, this kprobe can be boost when its
53  * post_handler and break_handler is not set.
54  */
55 struct arch_insn {
56         uprobe_opcode_t *insn;
57         int boostable;
58 };
59
60 /**
61  * @struct arch_tramp
62  * @brief Stores x86 trampoline
63  */
64 struct arch_tramp {
65         u8 tramp[UPROBES_TRAMP_LEN + BP_INSN_SIZE]; /**< BP for uretprobe */
66 };
67
68
69 static inline u32 swap_get_urp_float(struct pt_regs *regs)
70 {
71         u32 st0;
72
73         asm volatile ("fstps    %0" : "=m" (st0));
74
75         return st0;
76 }
77
78 static inline u64 swap_get_urp_double(struct pt_regs *regs)
79 {
80         u64 st1;
81
82         asm volatile ("fstpl    %0" : "=m" (st1));
83
84         return st1;
85 }
86
87 static inline void arch_ujprobe_return(void)
88 {
89 }
90
91 int arch_prepare_uprobe(struct uprobe *up);
92 int setjmp_upre_handler(struct uprobe *p, struct pt_regs *regs);
93 static inline int longjmp_break_uhandler(struct uprobe *p, struct pt_regs *regs)
94 {
95         return 0;
96 }
97
98 static inline int arch_opcode_analysis_uretprobe(struct uretprobe *rp)
99 {
100         return 0;
101 }
102
103 int arch_prepare_uretprobe(struct uretprobe_instance *ri, struct pt_regs *regs);
104 int arch_disarm_urp_inst(struct uretprobe_instance *ri,
105                          struct task_struct *task, unsigned long tr);
106 unsigned long arch_tramp_by_ri(struct uretprobe_instance *ri);
107 unsigned long arch_get_trampoline_addr(struct uprobe *p, struct pt_regs *regs);
108 void arch_set_orig_ret_addr(unsigned long orig_ret_addr, struct pt_regs *regs);
109 void arch_remove_uprobe(struct uprobe *up);
110 int arch_arm_uprobe(struct uprobe *p);
111 void arch_disarm_uprobe(struct uprobe *p, struct task_struct *task);
112
113 static inline unsigned long swap_get_uarg(struct pt_regs *regs, unsigned long n)
114 {
115         u32 *ptr, addr = 0;
116
117         /* 1 - return address saved on top of the stack */
118         ptr = (u32 *)regs->sp + n + 1;
119         if (get_user(addr, ptr))
120                 printk(KERN_INFO "failed to dereference a pointer, ptr=%p\n",
121                        ptr);
122
123         return addr;
124 }
125
126 static inline void swap_put_uarg(struct pt_regs *regs, unsigned long n,
127                                  unsigned long val)
128 {
129         u32 *ptr;
130
131         /* 1 - return address saved on top of the stack */
132         ptr = (u32 *)regs->sp + n + 1;
133         if (put_user(val, ptr))
134                 printk(KERN_INFO "failed to dereference a pointer, ptr=%p\n",
135                        ptr);
136 }
137
138 int swap_arch_init_uprobes(void);
139 void swap_arch_exit_uprobes(void);
140
141 #endif /* _X86_SWAP_UPROBES_H */