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
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.
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.
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.
25 * Copyright (C) Samsung Electronics, 2006-2010
27 * @section DESCRIPTION
29 * SWAP kprobe kernel-dependent dependencies.
32 #ifndef _SWAP_KPROBES_DEPS_H
33 #define _SWAP_KPROBES_DEPS_H
35 #include <linux/version.h> /* LINUX_VERSION_CODE, KERNEL_VERSION() */
37 #include <linux/hugetlb.h>
38 #include <linux/mempolicy.h>
39 #include <linux/highmem.h>
40 #include <linux/pagemap.h>
41 #include <ksyms/ksyms.h>
43 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
44 #define DECLARE_NODE_PTR_FOR_HLIST(var_name)
45 #define swap_hlist_for_each_entry_rcu(tpos, pos, head, member) \
46 hlist_for_each_entry_rcu(tpos, head, member)
47 #define swap_hlist_for_each_entry_safe(tpos, pos, n, head, member) \
48 hlist_for_each_entry_safe(tpos, n, head, member)
49 #define swap_hlist_for_each_entry(tpos, pos, head, member) \
50 hlist_for_each_entry(tpos, head, member)
51 #else /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0) */
52 #define DECLARE_NODE_PTR_FOR_HLIST(var_name) struct hlist_node *var_name
53 #define swap_hlist_for_each_entry_rcu(tpos, pos, head, member) \
54 hlist_for_each_entry_rcu(tpos, pos, head, member)
55 #define swap_hlist_for_each_entry_safe(tpos, pos, n, head, member) \
56 hlist_for_each_entry_safe(tpos, pos, n, head, member)
57 #define swap_hlist_for_each_entry(tpos, pos, head, member) \
58 hlist_for_each_entry(tpos, pos, head, member)
60 #define list_first_entry_or_null(ptr, type, member) \
61 (!list_empty(ptr) ? list_first_entry(ptr, type, member) : NULL)
63 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0) */
65 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 12))
66 #define synchronize_sched synchronize_kernel
70 #if LINUX_VERSION_CODE > KERNEL_VERSION(3, 1, 0)
71 #define task_job(task) (task->jobctl)
72 #else /* LINUX_VERSION_CODE > KERNEL_VERSION(3, 1, 0) */
73 #define task_job(task) (task->group_stop)
74 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(3, 1, 0) */
78 /* --------------------- Declaration of module dependencies ----------------- */
80 #define DECLARE_MOD_FUNC_DEP(name, ret, ...) ret(*__ref_##name)(__VA_ARGS__)
81 #define DECLARE_MOD_CB_DEP(name, ret, ...) ret(*name)(__VA_ARGS__)
84 /* ---------------- Implementation of module dependencies wrappers ---------- */
86 #define DECLARE_MOD_DEP_WRAPPER(name, ret, ...) ret name(__VA_ARGS__)
87 #define IMP_MOD_DEP_WRAPPER(name, ...) \
89 return __ref_##name(__VA_ARGS__); \
93 /* --------------------- Module dependencies initialization ----------------- */
95 #define INIT_MOD_DEP_VAR(dep, name) \
97 __ref_##dep = (void *) swap_ksyms(#name); \
99 DBPRINTF(#name " is not found! Oops. Where is it?"); \
104 #define INIT_MOD_DEP_CB(dep, name) \
106 dep = (void *) swap_ksyms(#name); \
108 DBPRINTF(#name " is not found! Oops. Where is it?"); \
114 int init_module_dependencies(void);
116 int access_process_vm_atomic(struct task_struct *tsk, unsigned long addr,
117 void *buf, int len, int write);
119 #define read_proc_vm_atomic(tsk, addr, buf, len) \
120 access_process_vm_atomic(tsk, addr, buf, len, 0)
121 #define write_proc_vm_atomic(tsk, addr, buf, len) \
122 access_process_vm_atomic(tsk, addr, buf, len, 1)
123 int page_present(struct mm_struct *mm, unsigned long addr);
125 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
126 unsigned long swap_do_mmap_pgoff(struct file *file, unsigned long addr,
127 unsigned long len, unsigned long prot,
128 unsigned long flags, unsigned long pgoff,
129 unsigned long *populate);
130 #elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)
131 unsigned long swap_do_mmap_pgoff(struct file *file, unsigned long addr,
132 unsigned long len, unsigned long prot,
133 unsigned long flags, unsigned long pgoff);
134 #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0) */
136 #if LINUX_VERSION_CODE > KERNEL_VERSION(3, 16, 0)
137 #define swap_hlist_add_after(node, prev) hlist_add_behind(node, prev)
138 #else /* LINUX_VERSION_CODE > KERNEL_VERSION(3, 16, 0) */
139 #define swap_hlist_add_after(node, prev) hlist_add_after(node, prev)
140 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(3, 16, 0) */
142 #if LINUX_VERSION_CODE > KERNEL_VERSION(3, 18, 0)
143 #define __get_cpu_var(var) (*this_cpu_ptr(&(var)))
144 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(3, 18, 0) */
146 #endif /* _SWAP_KPROBES_DEPS_H */