ARM: use swap_access_process_vm() for user memory access
[platform/kernel/swap-modules.git] / kprobe / swap_kprobes_deps.h
1 /**
2  * @file kprobe/swap_kprobes_deps.h
3  * @author Alexey Gerenkov <a.gerenkov@samsung.com> User-Space Probes initial implementation;
4  * Support x86/ARM/MIPS for both user and kernel spaces.
5  * @author Ekaterina Gorelkina <e.gorelkina@samsung.com>: redesign module for separating core and arch parts
6  *
7  * @section LICENSE
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * @section COPYRIGHT
24  *
25  * Copyright (C) Samsung Electronics, 2006-2010
26  *
27  * @section DESCRIPTION
28  *
29  * SWAP kprobe kernel-dependent dependencies.
30  */
31
32 #ifndef _SWAP_KPROBES_DEPS_H
33 #define _SWAP_KPROBES_DEPS_H
34
35 #include <linux/version.h>      /* LINUX_VERSION_CODE, KERNEL_VERSION() */
36 #include <linux/sched.h>
37 #include <linux/mm.h>
38 #include <linux/hugetlb.h>
39 #include <linux/mempolicy.h>
40 #include <linux/highmem.h>
41 #include <linux/pagemap.h>
42 #include <ksyms/ksyms.h>
43
44 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
45 #define DECLARE_NODE_PTR_FOR_HLIST(var_name)
46 #define swap_hlist_for_each_entry_rcu(tpos, pos, head, member) \
47         hlist_for_each_entry_rcu(tpos, head, member)
48 #define swap_hlist_for_each_entry_safe(tpos, pos, n, head, member) \
49         hlist_for_each_entry_safe(tpos, n, head, member)
50 #define swap_hlist_for_each_entry(tpos, pos, head, member) \
51         hlist_for_each_entry(tpos, head, member)
52 #else /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0) */
53 #define DECLARE_NODE_PTR_FOR_HLIST(var_name) struct hlist_node *var_name
54 #define swap_hlist_for_each_entry_rcu(tpos, pos, head, member) \
55         hlist_for_each_entry_rcu(tpos, pos, head, member)
56 #define swap_hlist_for_each_entry_safe(tpos, pos, n, head, member) \
57         hlist_for_each_entry_safe(tpos, pos, n, head, member)
58 #define swap_hlist_for_each_entry(tpos, pos, head, member) \
59         hlist_for_each_entry(tpos, pos, head, member)
60
61 #define list_first_entry_or_null(ptr, type, member) \
62         (!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL)
63
64 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0) */
65
66 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 12))
67 #define synchronize_sched       synchronize_kernel
68 #endif
69
70
71 /*
72  * swap_preempt_enable_no_resched()
73  */
74 #if (defined(MODULE) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0)))
75
76 #ifdef CONFIG_PREEMPT_COUNT
77 #define swap_preempt_enable_no_resched() \
78 do { \
79         barrier(); \
80         preempt_count_dec(); \
81 } while (0)
82 #else /* !CONFIG_PREEMPT_COUNT */
83 #define swap_preempt_enable_no_resched() barrier()
84 #endif /* CONFIG_PREEMPT_COUNT */
85
86 #else /* !(defined(MODULE) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)) */
87 #define swap_preempt_enable_no_resched() preempt_enable_no_resched()
88 #endif /* !(defined(MODULE) && (LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)) */
89
90
91 #if LINUX_VERSION_CODE > KERNEL_VERSION(3, 1, 0)
92     #define task_job(task) (task->jobctl)
93 #else /* LINUX_VERSION_CODE > KERNEL_VERSION(3, 1, 0) */
94     #define task_job(task) (task->group_stop)
95 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(3, 1, 0) */
96
97
98
99 /* --------------------- Declaration of module dependencies ----------------- */
100
101 #define DECLARE_MOD_FUNC_DEP(name, ret, ...) ret(*__ref_##name)(__VA_ARGS__)
102 #define DECLARE_MOD_CB_DEP(name, ret, ...) ret(*name)(__VA_ARGS__)
103
104
105 /* ---------------- Implementation of module dependencies wrappers ---------- */
106
107 #define DECLARE_MOD_DEP_WRAPPER(name, ret, ...) ret name(__VA_ARGS__)
108 #define IMP_MOD_DEP_WRAPPER(name, ...) \
109 { \
110         return __ref_##name(__VA_ARGS__); \
111 }
112
113
114 /* --------------------- Module dependencies initialization ----------------- */
115
116 #define INIT_MOD_DEP_VAR(dep, name) \
117 { \
118         __ref_##dep = (void *) swap_ksyms(#name); \
119         if (!__ref_##dep) { \
120                 DBPRINTF(#name " is not found! Oops. Where is it?"); \
121                 return -ESRCH; \
122         } \
123 }
124
125 #define INIT_MOD_DEP_CB(dep, name) \
126 { \
127         dep = (void *) swap_ksyms(#name); \
128         if (!dep) { \
129                 DBPRINTF(#name " is not found! Oops. Where is it?"); \
130                 return -ESRCH; \
131         } \
132 }
133
134
135 int init_module_dependencies(void);
136
137
138 #if defined(CONFIG_ARM) || defined(CONFIG_ARM64)
139
140 int swap_access_process_vm(struct task_struct *tsk, unsigned long addr,
141                            void *buf, int len, int write);
142
143 # define read_proc_vm_atomic(tsk, addr, buf, len) \
144         swap_access_process_vm(tsk, addr, buf, len, 0)
145 # define write_proc_vm_atomic(tsk, addr, buf, len) \
146         swap_access_process_vm(tsk, addr, buf, len, 1)
147
148 #else /* defined(CONFIG_ARM) || defined(CONFIG_ARM64) */
149
150 int access_process_vm_atomic(struct task_struct *tsk, unsigned long addr,
151                              void *buf, int len, int write);
152
153 # define read_proc_vm_atomic(tsk, addr, buf, len) \
154         access_process_vm_atomic(tsk, addr, buf, len, 0)
155 # define write_proc_vm_atomic(tsk, addr, buf, len) \
156         access_process_vm_atomic(tsk, addr, buf, len, 1)
157
158 #endif /* defined(CONFIG_ARM) || defined(CONFIG_ARM64) */
159
160 int page_present(struct mm_struct *mm, unsigned long addr);
161
162 #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)
163 unsigned long swap_do_mmap(struct file *file, unsigned long addr,
164                            unsigned long len, unsigned long prot,
165                            unsigned long flags, vm_flags_t vm_flags,
166                            unsigned long pgoff, unsigned long *populate);
167 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
168 unsigned long swap_do_mmap_pgoff(struct file *file, unsigned long addr,
169                                  unsigned long len, unsigned long prot,
170                                  unsigned long flags, unsigned long pgoff,
171                                  unsigned long *populate);
172 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)
173 unsigned long swap_do_mmap_pgoff(struct file *file, unsigned long addr,
174                                  unsigned long len, unsigned long prot,
175                                  unsigned long flags, unsigned long pgoff);
176 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0) */
177
178 #if LINUX_VERSION_CODE > KERNEL_VERSION(3, 16, 0)
179 #define swap_hlist_add_after(node, prev) hlist_add_behind(node, prev)
180 #else /* LINUX_VERSION_CODE > KERNEL_VERSION(3, 16, 0) */
181 #define swap_hlist_add_after(node, prev) hlist_add_after(node, prev)
182 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(3, 16, 0) */
183
184 #if LINUX_VERSION_CODE > KERNEL_VERSION(3, 18, 0)
185 #define __get_cpu_var(var) (*this_cpu_ptr(&(var)))
186 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(3, 18, 0) */
187
188 #endif /* _SWAP_KPROBES_DEPS_H */