[FIX] wrong parameters
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Mon, 11 Nov 2013 09:02:23 +0000 (13:02 +0400)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Mon, 11 Nov 2013 12:52:20 +0000 (12:52 +0000)
Change-Id: Iced9d6fd6a7a571cb1cb40ce0f64bac4e4a1e470
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
build.sh
kprobe/arch/asm-arm/dbi_kprobes.h
kprobe/arch/asm-x86/dbi_kprobes.h
uprobe/arch/asm-arm/swap_uprobes.h
uprobe/arch/asm-x86/swap_uprobes.h
writer/swap_writer_module.c

index cc00af4..0576b50 100755 (executable)
--- a/build.sh
+++ b/build.sh
@@ -54,7 +54,7 @@ make CROSS_COMPILE=${cross_compile} ARCH=${arch} -C ${kernel_dir} M=${driver_dir
 writer_module_name=swap_writer.ko
 writer_inc=${modules_inc}
 make CROSS_COMPILE=${cross_compile} ARCH=${arch} -C ${kernel_dir} M=${writer_dir} \
-       extra_cflags="-Werror -I${modules_dir}" modules || exit 1
+       extra_cflags="-Werror -I${modules_dir} -I${kprobe_dir} -I${kprobe_arch_dir} -I${uprobe_arch_dir}" modules || exit 1
 
 kprobe_module_name=swap_kprobe.ko
 make CROSS_COMPILE=${cross_compile} ARCH=${arch} -C ${kernel_dir} M=${kprobe_dir} \
index 28503c6..218d6f1 100644 (file)
@@ -521,6 +521,11 @@ static inline unsigned long swap_get_karg(struct pt_regs *regs, unsigned long n)
        return *((unsigned long *)regs->ARM_sp + n - 4);
 }
 
+static inline unsigned long swap_get_sarg(struct pt_regs *regs, unsigned long n)
+{
+       return swap_get_karg(regs, n);
+}
+
 int arch_init_kprobes(void);
 void arch_exit_kprobes(void);
 
index 3262d7e..1e29813 100644 (file)
@@ -246,6 +246,12 @@ static inline unsigned long swap_get_karg(struct pt_regs *regs, unsigned long n)
        return *((unsigned long *)kernel_stack_pointer(regs) + n - 2);
 }
 
+static inline unsigned long swap_get_sarg(struct pt_regs *regs, unsigned long n)
+{
+       /* 1 - return address saved on top of the stack */
+       return *((unsigned long *)kernel_stack_pointer(regs) + n + 1);
+}
+
 int arch_init_kprobes(void);
 void arch_exit_kprobes(void);
 
index 664e1c1..2f61ae9 100644 (file)
@@ -35,6 +35,9 @@
 struct kprobe;
 struct pt_regs;
 struct task_struct;
+struct uprobe;
+struct uretprobe;
+struct uretprobe_instance;
 
 
 static inline void arch_ujprobe_return(void)
index 51215a4..2700cf5 100644 (file)
 
 #include <asm/dbi_kprobes.h>
 
+
+struct uprobe;
+struct uretprobe;
+struct uretprobe_instance;
+
+
 static inline void arch_ujprobe_return(void)
 {
 }
index d5579b5..1ee0dac 100644 (file)
@@ -34,6 +34,8 @@
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <asm/uaccess.h>
+#include <asm/dbi_kprobes.h>
+#include <asm/swap_uprobes.h>
 
 #include <buffer/swap_buffer_module.h>
 #include <buffer/swap_buffer_errors.h>
@@ -496,40 +498,28 @@ static char *pack_msg_func_entry(char *payload, const char *fmt, struct pt_regs
        return payload + sizeof(*mfe);
 }
 
-static size_t count_char(const char *str, char ch)
+static unsigned long get_arg(struct pt_regs *regs, unsigned long n)
 {
-       size_t count = 0;
-       for ( ;*str; ++str)
-               if (*str == ch)
-                       ++count;
-
-       return count;
+       return user_mode(regs) ?
+                       swap_get_uarg(regs, n) :        /* US argument */
+                       swap_get_sarg(regs, n);         /* sys_call argument */
 }
 
 static int pack_args(char *buf, int len, const char *fmt, struct pt_regs *regs)
 {
-       enum { args_cnt = 16 };
        char *buf_old = buf;
-       unsigned long arg, args[args_cnt];
        u32 *tmp_u32;
        u64 *tmp_u64;
        int i,          /* the index of the argument */
-           cnt,        /* the number of arguments */
            fmt_i,      /* format index */
            fmt_len;    /* the number of parameters, in format */
 
        fmt_len = strlen(fmt);
-       cnt = fmt_len + count_char(fmt, 'w');
-
-       /* FIXME: when the number of arguments is greater than args_cnt */
-       cnt = cnt < args_cnt ? cnt : args_cnt;
-       get_args(args, cnt, regs);
 
-       for (i = 0, fmt_i = 0; (fmt_i < fmt_len) && (i < cnt); ++i, ++fmt_i) {
+       for (i = 0, fmt_i = 0; fmt_i < fmt_len; ++i, ++fmt_i) {
                if (len < 2)
                        return -ENOMEM;
 
-               arg = args[i];
                *buf = fmt[fmt_i];
                buf += 1;
                len -= 1;
@@ -538,43 +528,42 @@ static int pack_args(char *buf, int len, const char *fmt, struct pt_regs *regs)
                case 'b': /* 1 byte(bool) */
                        if (len < 1)
                                return -ENOMEM;
-                       *buf = (char)!!arg;
+                       *buf = (char)!!get_arg(regs, i);
                        buf += 1;
                        len -= 1;
                        break;
                case 'c': /* 1 byte(char) */
                        if (len < 1)
                                return -ENOMEM;
-                       *buf = (char)arg;
+                       *buf = (char)get_arg(regs, i);
                        buf += 1;
                        len -= 1;
                        break;
-
                case 'f': /* 4 byte(float) */
                case 'd': /* 4 byte(int) */
                        if (len < 4)
                                return -ENOMEM;
                        tmp_u32 = (u32 *)buf;
-                       *tmp_u32 = (u32)arg;
+                       *tmp_u32 = (u32)get_arg(regs, i);
                        buf += 4;
                        len -= 4;
                        break;
-
                case 'x': /* 8 byte(long) */
                case 'p': /* 8 byte(pointer) */
                        if (len < 8)
                                return -ENOMEM;
                        tmp_u64 = (u64 *)buf;
-                       *tmp_u64 = (u64)arg;
+                       *tmp_u64 = (u64)get_arg(regs, i);
                        buf += 8;
                        len -= 8;
                        break;
                case 'w': /* 8 byte(double) */
-                       if (len < 8 && (i + 1) < cnt)
+                       if (len < 8)
                                return -ENOMEM;
                        tmp_u64 = (u64 *)buf;
-                       *tmp_u64 = *((u64 *)&args[i]);
+                       *tmp_u64 = get_arg(regs, i);
                        ++i;
+                       *tmp_u64 |= (u64)get_arg(regs, i) << 32;
                        buf += 8;
                        len -= 8;
                        break;
@@ -584,7 +573,7 @@ static int pack_args(char *buf, int len, const char *fmt, struct pt_regs *regs)
                        const char __user *user_s;
                        int len_s, ret;
 
-                       user_s = (const char __user *)arg;
+                       user_s = (const char __user *)get_arg(regs, i);
                        len_s = strnlen_user(user_s, max_str_len);
                        if (len < len_s)
                                return -ENOMEM;