[IMPROVE] now modules are buildable with tizen 3.10 kernel
authorAlexander Aksenov <a.aksenov@samsung.com>
Tue, 12 Nov 2013 08:48:10 +0000 (12:48 +0400)
committerAlexander Aksenov <a.aksenov@samsung.com>
Thu, 14 Nov 2013 07:41:51 +0000 (11:41 +0400)
Added generic swap_do_mmap() function;
structs hlist_node, that are swap_hlist_for_each_entry_* second arguments,
are declared with DECLARE_NODE_PTR_FOR_HLIST.

Change-Id: Id9e264c49987816d3d1bd93eb056c94000d0f68a
Signed-off-by: Alexander Aksenov <a.aksenov@samsung.com>
kprobe/dbi_insn_slots.c
kprobe/dbi_kprobes.c
kprobe/dbi_kprobes_deps.h
ks_manager/ks_manager.c
uprobe/swap_uprobes.c
us_manager/sspt/sspt_debug.h
us_manager/sspt/sspt_file.c
us_manager/us_manager_common.h [new file with mode: 0644]
us_manager/us_slot_manager.c

index e3d508b..fb4f6d1 100644 (file)
@@ -168,7 +168,7 @@ void *alloc_insn_slot(struct slot_manager *sm)
 {
        void *free_slot;
        struct fixed_alloc *fa;
-       struct hlist_node *pos;
+       DECLARE_NODE_PTR_FOR_HLIST(pos);
 
        swap_hlist_for_each_entry_rcu(fa, pos, &sm->page_list, hlist) {
                free_slot = chunk_allocate(&fa->chunk, sm->slot_size);
@@ -190,7 +190,7 @@ EXPORT_SYMBOL_GPL(alloc_insn_slot);
 void free_insn_slot(struct slot_manager *sm, void *slot)
 {
        struct fixed_alloc *fa;
-       struct hlist_node *pos;
+       DECLARE_NODE_PTR_FOR_HLIST(pos);
 
        swap_hlist_for_each_entry_rcu(fa, pos, &sm->page_list, hlist) {
                if (!chunk_check_ptr(&fa->chunk, slot, PAGE_SIZE))
index a595057..9048765 100644 (file)
@@ -181,8 +181,8 @@ struct kprobe_ctlblk *get_kprobe_ctlblk(void)
 struct kprobe *get_kprobe(void *addr)
 {
        struct hlist_head *head;
-       struct hlist_node *node;
        struct kprobe *p;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        head = &kprobe_table[hash_ptr (addr, KPROBE_HASH_BITS)];
        swap_hlist_for_each_entry_rcu(p, node, head, hlist) {
@@ -278,8 +278,8 @@ void kprobes_inc_nmissed_count(struct kprobe *p)
 /* Called with kretprobe_lock held */
 struct kretprobe_instance *get_free_rp_inst(struct kretprobe *rp)
 {
-       struct hlist_node *node;
        struct kretprobe_instance *ri;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        swap_hlist_for_each_entry(ri, node, &rp->free_instances, uflist) {
                return ri;
@@ -298,8 +298,8 @@ EXPORT_SYMBOL_GPL(get_free_rp_inst);
 /* Called with kretprobe_lock held */
 struct kretprobe_instance *get_free_rp_inst_no_alloc(struct kretprobe *rp)
 {
-       struct hlist_node *node;
        struct kretprobe_instance *ri;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        swap_hlist_for_each_entry(ri, node, &rp->free_instances, uflist) {
                return ri;
@@ -311,8 +311,8 @@ struct kretprobe_instance *get_free_rp_inst_no_alloc(struct kretprobe *rp)
 /* Called with kretprobe_lock held */
 struct kretprobe_instance *get_used_rp_inst(struct kretprobe *rp)
 {
-       struct hlist_node *node;
        struct kretprobe_instance *ri;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        swap_hlist_for_each_entry(ri, node, &rp->used_instances, uflist) {
                return ri;
@@ -657,12 +657,14 @@ int trampoline_probe_handler(struct kprobe *p, struct pt_regs *regs)
 {
        struct kretprobe_instance *ri = NULL;
        struct hlist_head *head;
-       struct hlist_node *node, *tmp;
        unsigned long flags, orig_ret_address = 0;
        unsigned long trampoline_address = (unsigned long)&kretprobe_trampoline;
 
        struct kprobe_ctlblk *kcb;
 
+       struct hlist_node *tmp;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
+
        preempt_disable();
        kcb = get_kprobe_ctlblk();
 
@@ -834,7 +836,7 @@ static void dbi_unregister_kretprobe_top(struct kretprobe *rp)
 {
        unsigned long flags;
        struct kretprobe_instance *ri;
-       struct hlist_node *node;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        dbi_unregister_kprobe(&rp->kp);
 
index 3442c32..852e528 100644 (file)
 #include <ksyms/ksyms.h>
 
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0)
+#define DECLARE_NODE_PTR_FOR_HLIST(var_name)
 #define swap_hlist_for_each_entry_rcu(tpos, pos, head, member) hlist_for_each_entry_rcu(tpos, head, member)
 #define swap_hlist_for_each_entry_safe(tpos, pos, n, head, member) hlist_for_each_entry_safe(tpos, n, head, member)
 #define swap_hlist_for_each_entry(tpos, pos, head, member) hlist_for_each_entry(tpos, head, member)
 #else /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 9, 0) */
+#define DECLARE_NODE_PTR_FOR_HLIST(var_name) struct hlist_node *var_name
 #define swap_hlist_for_each_entry_rcu(tpos, pos, head, member) hlist_for_each_entry_rcu(tpos, pos, head, member)
 #define swap_hlist_for_each_entry_safe(tpos, pos, n, head, member) hlist_for_each_entry_safe(tpos, pos, n, head, member)
 #define swap_hlist_for_each_entry(tpos, pos, head, member) hlist_for_each_entry(tpos, pos, head, member)
index 2866b6a..0999123 100644 (file)
@@ -67,7 +67,7 @@ static void remove_probe_to_list(struct probe *p)
 static struct probe *find_probe(unsigned long addr)
 {
        struct probe *p;
-       struct hlist_node *node;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        /* check if such probe does exist */
        swap_hlist_for_each_entry(p, node, &list_probes, hlist)
@@ -131,7 +131,8 @@ EXPORT_SYMBOL_GPL(ksm_unregister_probe);
 int ksm_unregister_probe_all(void)
 {
        struct probe *p;
-       struct hlist_node *node, *n;
+       struct hlist_node *n;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        swap_hlist_for_each_entry_safe(p, node, n, &list_probes, hlist) {
                do_ksm_unregister_probe(p);
index 4254a8b..acb9760 100644 (file)
@@ -55,8 +55,8 @@ void print_kprobe_hash_table(void)
 {
        int i;
        struct hlist_head *head;
-       struct hlist_node *node;
        struct kprobe *p;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        // print uprobe table
        for (i = 0; i < KPROBE_TABLE_SIZE; ++i) {
@@ -72,8 +72,8 @@ void print_kretprobe_hash_table(void)
 {
        int i;
        struct hlist_head *head;
-       struct hlist_node *node;
        struct kprobe *p;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        // print uprobe table
        for (i = 0; i < KPROBE_TABLE_SIZE; ++i) {
@@ -89,8 +89,8 @@ void print_uprobe_hash_table(void)
 {
        int i;
        struct hlist_head *head;
-       struct hlist_node *node;
        struct kprobe *p;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        // print uprobe table
        for (i = 0; i < UPROBE_TABLE_SIZE; ++i) {
@@ -286,8 +286,8 @@ static void init_uretprobe_inst_table(void)
 struct kprobe *get_ukprobe(void *addr, pid_t tgid)
 {
        struct hlist_head *head;
-       struct hlist_node *node;
        struct kprobe *p;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        head = &uprobe_table[hash_ptr(addr, UPROBE_HASH_BITS)];
        swap_hlist_for_each_entry_rcu(p, node, head, hlist) {
@@ -316,8 +316,8 @@ static void add_uprobe_table(struct kprobe *p)
 static struct kprobe *get_ukprobe_bis_arm(void *addr, pid_t tgid)
 {
        struct hlist_head *head;
-       struct hlist_node *node;
        struct kprobe *p;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        /* TODO: test - two processes invokes instrumented function */
        head = &uprobe_insn_slot_table[hash_ptr(addr, UPROBE_HASH_BITS)];
@@ -333,8 +333,8 @@ static struct kprobe *get_ukprobe_bis_arm(void *addr, pid_t tgid)
 static struct kprobe *get_ukprobe_bis_thumb(void *addr, pid_t tgid)
 {
        struct hlist_head *head;
-       struct hlist_node *node;
        struct kprobe *p;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        /* TODO: test - two processes invokes instrumented function */
        head = &uprobe_insn_slot_table[hash_ptr(addr, UPROBE_HASH_BITS)];
@@ -357,8 +357,8 @@ struct kprobe *get_ukprobe_by_insn_slot(void *addr, pid_t tgid, struct pt_regs *
 struct kprobe *get_ukprobe_by_insn_slot(void *addr, pid_t tgid, struct pt_regs *regs)
 {
        struct hlist_head *head;
-       struct hlist_node *node;
        struct kprobe *p;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        addr -= UPROBES_TRAMP_RET_BREAK_IDX;
 
@@ -426,8 +426,8 @@ static void recycle_urp_inst(struct uretprobe_instance *ri)
 /* Called with uretprobe_lock held */
 static struct uretprobe_instance *get_used_urp_inst(struct uretprobe *rp)
 {
-       struct hlist_node *node;
        struct uretprobe_instance *ri;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        swap_hlist_for_each_entry(ri, node, &rp->used_instances, uflist) {
                return ri;
@@ -439,8 +439,8 @@ static struct uretprobe_instance *get_used_urp_inst(struct uretprobe *rp)
 /* Called with uretprobe_lock held */
 struct uretprobe_instance *get_free_urp_inst_no_alloc(struct uretprobe *rp)
 {
-       struct hlist_node *node;
        struct uretprobe_instance *ri;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        swap_hlist_for_each_entry(ri, node, &rp->free_instances, uflist) {
                return ri;
@@ -490,8 +490,8 @@ static int alloc_nodes_uretprobe(struct uretprobe *rp)
 /* Called with uretprobe_lock held */
 static struct uretprobe_instance *get_free_urp_inst(struct uretprobe *rp)
 {
-       struct hlist_node *node;
        struct uretprobe_instance *ri;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        swap_hlist_for_each_entry(ri, node, &rp->free_instances, uflist) {
                return ri;
@@ -691,8 +691,9 @@ int trampoline_uprobe_handler(struct kprobe *p, struct pt_regs *regs)
 {
        struct uretprobe_instance *ri = NULL;
        struct hlist_head *head;
-       struct hlist_node *node, *tmp;
        unsigned long flags, tramp_addr, orig_ret_addr = 0;
+       struct hlist_node *tmp;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        tramp_addr = arch_get_trampoline_addr(p, regs);
        spin_lock_irqsave(&uretprobe_lock, flags);
@@ -899,8 +900,9 @@ out:
 int dbi_disarm_urp_inst_for_task(struct task_struct *parent, struct task_struct *task)
 {
        struct uretprobe_instance *ri;
-       struct hlist_node *node, *tmp;
        struct hlist_head *head = uretprobe_inst_table_head(parent->mm);
+       struct hlist_node *tmp;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        swap_hlist_for_each_entry_safe(ri, node, tmp, head, hlist) {
                if (parent == ri->task) {
@@ -963,9 +965,10 @@ void dbi_unregister_uretprobe(struct uretprobe *rp)
 void dbi_unregister_all_uprobes(struct task_struct *task)
 {
        struct hlist_head *head;
-       struct hlist_node *node, *tnode;
        struct kprobe *p;
        int i;
+       struct hlist_node *tnode;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        for (i = 0; i < UPROBE_TABLE_SIZE; ++i) {
                head = &uprobe_table[i];
index 7d8fc48..d51581f 100644 (file)
@@ -71,10 +71,10 @@ static inline void print_file_probes(const struct sspt_file *file)
        int i;
        unsigned long table_size;
        struct sspt_page *page = NULL;
-       struct hlist_node *node = NULL;
        struct hlist_head *head = NULL;
        static unsigned char *NA = "N/A";
        unsigned char *name;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        if (file == NULL) {
                printk("### file_p == NULL\n");
index a20037d..72f3af8 100644 (file)
@@ -68,10 +68,11 @@ struct sspt_file *sspt_file_create(struct dentry *dentry, int page_cnt)
 
 void sspt_file_free(struct sspt_file *file)
 {
-       struct hlist_node *p, *n;
        struct hlist_head *head;
        struct sspt_page *page;
        int i, table_size = (1 << file->page_probes_hash_bits);
+       struct hlist_node *n;
+       DECLARE_NODE_PTR_FOR_HLIST(p);
 
        for (i = 0; i < table_size; ++i) {
                head = &file->page_probes_table[i];
@@ -94,9 +95,9 @@ static void sspt_add_page(struct sspt_file *file, struct sspt_page *page)
 
 static struct sspt_page *sspt_find_page(struct sspt_file *file, unsigned long offset)
 {
-       struct hlist_node *node;
        struct hlist_head *head;
        struct sspt_page *page;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        head = &file->page_probes_table[hash_ptr((void *)offset, file->page_probes_hash_bits)];
        swap_hlist_for_each_entry(page, node, head, hlist) {
@@ -166,8 +167,9 @@ int sspt_file_check_install_pages(struct sspt_file *file)
 {
        int i, table_size;
        struct sspt_page *page;
-       struct hlist_node *node, *tmp;
        struct hlist_head *head;
+       struct hlist_node *tmp;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        table_size = (1 << file->page_probes_hash_bits);
        for (i = 0; i < table_size; ++i) {
@@ -185,11 +187,11 @@ int sspt_file_check_install_pages(struct sspt_file *file)
 void sspt_file_install(struct sspt_file *file)
 {
        struct sspt_page *page = NULL;
-       struct hlist_node *node = NULL;
        struct hlist_head *head = NULL;
        int i, table_size = (1 << file->page_probes_hash_bits);
        unsigned long page_addr;
        struct mm_struct *mm;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        for (i = 0; i < table_size; ++i) {
                head = &file->page_probes_table[i];
@@ -211,8 +213,9 @@ int sspt_file_uninstall(struct sspt_file *file, struct task_struct *task, enum U
        int i, err = 0;
        int table_size = (1 << file->page_probes_hash_bits);
        struct sspt_page *page;
-       struct hlist_node *node, *tmp;
        struct hlist_head *head;
+       struct hlist_node *tmp;
+       DECLARE_NODE_PTR_FOR_HLIST(node);
 
        for (i = 0; i < table_size; ++i) {
                head = &file->page_probes_table[i];
diff --git a/us_manager/us_manager_common.h b/us_manager/us_manager_common.h
new file mode 100644 (file)
index 0000000..d6fc074
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ *  SWAP uprobe manager
+ *  modules/us_manager/us_slot_manager.c
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * Copyright (C) Samsung Electronics, 2013
+ *
+ * 2013         Alexander Aksenov: SWAP us_manager implement
+ *
+ */
+
+
+#include <linux/mm.h>
+#include <linux/version.h>
+
+
+static inline unsigned long swap_do_mmap(struct file *filp, unsigned long addr,
+                                        unsigned long len, unsigned long prot,
+                                        unsigned long flag,
+                                        unsigned long offset)
+{
+#if LINUX_VERSION_CODE == KERNEL_VERSION(3, 10, 0)
+       unsigned long populate;
+
+       return do_mmap_pgoff(filp, addr, len, prot, flag, offset, &populate);
+#else /* LINUX_VERSION_CODE == KERNEL_VERSION(3, 10, 0) */
+       return do_mmap(filp, addr, len, prot, flag, offset);
+#endif
+}
index 4a371e9..4558d9a 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/list.h>
 #include <kprobe/dbi_insn_slots.h>
 #include <kprobe/arch/asm/dbi_kprobes.h>
+#include "us_manager_common.h"
 
 static unsigned long alloc_user_pages(struct task_struct *task, unsigned long len, unsigned long prot, unsigned long flags)
 {
@@ -53,7 +54,7 @@ static unsigned long alloc_user_pages(struct task_struct *task, unsigned long le
                }
                // FIXME: its seems to be bad decision to replace 'current' pointer temporarily
                current_thread_info()->task = task;
-               ret = do_mmap(NULL, 0, len, prot, flags, 0);
+               ret = swap_do_mmap(NULL, 0, len, prot, flags, 0);
                current_thread_info()->task = otask;
                if (!atomic) {
                        downgrade_write (&mm->mmap_sem);