[FEATURE] create new interface for uprobe 66/39866/1
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Wed, 25 Mar 2015 07:45:47 +0000 (10:45 +0300)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Mon, 18 May 2015 11:42:13 +0000 (14:42 +0300)
Change-Id: Ib652667abc169529b1b00126d0d9759291297282
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
us_manager/Kbuild
us_manager/probes/probe_info_new.c [new file with mode: 0644]
us_manager/probes/probe_info_new.h [new file with mode: 0644]
us_manager/probes/probes.h
us_manager/us_manager.c

index 6481da5..e4d8f9d 100644 (file)
@@ -10,4 +10,5 @@ swap_us_manager-y := us_manager.o us_slot_manager.o helper.o debugfs_us_manager.
                      pf/proc_filters.o pf/pf_group.o \
                      img/img_proc.o img/img_file.o img/img_ip.o \
                      probes/probes.o \
+                     probes/probe_info_new.o \
                      usm_msg.o
diff --git a/us_manager/probes/probe_info_new.c b/us_manager/probes/probe_info_new.c
new file mode 100644 (file)
index 0000000..6754804
--- /dev/null
@@ -0,0 +1,259 @@
+/*
+ * 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, 2015
+ *
+ * 2015         Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+
+#include <linux/module.h>
+#include <us_manager/sspt/ip.h>
+#include <us_manager/pf/pf_group.h>
+#include "probes.h"
+#include "probe_info_new.h"
+#include "register_probes.h"
+
+
+/*
+ * handlers
+ */
+static int urp_entry_handler(struct uretprobe_instance *ri, struct pt_regs *regs)
+{
+       struct uretprobe *rp = ri->rp;
+
+       if (rp) {
+               struct us_ip *ip = container_of(rp, struct us_ip, retprobe);
+               struct probe_info_new *info_new;
+
+               info_new = probe_info_get_val(ip->info, struct probe_info_new *);
+               if (info_new->entry_handler)
+                       return info_new->entry_handler(ri, regs);
+
+       }
+
+       return 0;
+}
+
+static int urp_ret_handler(struct uretprobe_instance *ri, struct pt_regs *regs)
+{
+       struct uretprobe *rp = ri->rp;
+
+       if (rp) {
+               struct us_ip *ip = container_of(rp, struct us_ip, retprobe);
+               struct probe_info_new *info_new;
+
+               info_new = probe_info_get_val(ip->info, struct probe_info_new *);
+               if (info_new->ret_handler)
+                       return info_new->ret_handler(ri, regs);
+       }
+
+       return 0;
+}
+
+static int uprobe_handler(struct kprobe *p, struct pt_regs *regs)
+{
+       struct uprobe *up = container_of(p, struct uprobe, kp);
+       struct us_ip *ip = container_of(up, struct us_ip, uprobe);
+       struct probe_info_new *info_new;
+
+       info_new = probe_info_get_val(ip->info, struct probe_info_new *);
+       if (info_new->handler)
+               return info_new->handler(p, regs);
+
+       return 0;
+}
+
+
+
+
+
+/*
+ * register/unregister interface
+ */
+int pin_register(struct probe_new *probe, struct pf_group *pfg,
+                struct dentry *dentry)
+{
+       int ret;
+       struct probe_info *info;
+       struct probe_info_new *info_new = probe->info;
+
+       info = probe_info_create(struct probe_info_new *, info_new->type);
+       if (info == NULL)
+               return -ENOMEM;
+
+       probe_info_set_val(info, struct probe_info_new *, info_new);
+
+       ret = pf_register_probe(pfg, dentry, probe->offset, info);
+       if (ret) {
+               probe_info_free(info);
+               return ret;
+       }
+
+       info_new->info = info;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(pin_register);
+
+int pin_unregister(struct probe_new *probe, struct pf_group *pfg,
+                  struct dentry *dentry)
+{
+       int ret;
+       struct probe_info_new *info_new = probe->info;
+
+       ret = pf_unregister_probe(pfg, dentry, probe->offset);
+       if (ret) {
+               /* error */
+               return ret;
+       }
+
+       probe_info_free(info_new->info);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(pin_unregister);
+
+
+
+
+
+/*
+ * SWAP_NEW_UP
+ */
+static int up_copy(struct probe_info *dst, const struct probe_info *src)
+{
+       return 0;
+}
+
+static void up_cleanup(struct probe_info *probe_i)
+{
+}
+
+static struct uprobe *up_get_uprobe(struct us_ip *ip)
+{
+       return &ip->uprobe;
+}
+
+static int up_register_probe(struct us_ip *ip)
+{
+       return swap_register_uprobe(&ip->uprobe);
+}
+
+static void up_unregister_probe(struct us_ip *ip, int disarm)
+{
+       __swap_unregister_uprobe(&ip->uprobe, disarm);
+}
+
+static void up_init(struct us_ip *ip)
+{
+       ip->uprobe.kp.pre_handler = uprobe_handler;
+}
+
+static void up_uninit(struct us_ip *ip)
+{
+}
+
+static struct probe_iface up_iface = {
+       .init = up_init,
+       .uninit = up_uninit,
+       .reg = up_register_probe,
+       .unreg = up_unregister_probe,
+       .get_uprobe = up_get_uprobe,
+       .copy = up_copy,
+       .cleanup = up_cleanup
+};
+
+
+
+
+
+/*
+ * SWAP_NEW_URP
+ */
+static int urp_copy(struct probe_info *dst, const struct probe_info *src)
+{
+       return 0;
+}
+
+static void urp_cleanup(struct probe_info *probe_i)
+{
+}
+
+static struct uprobe *urp_get_uprobe(struct us_ip *ip)
+{
+       return &ip->retprobe.up;
+}
+
+static int urp_register_probe(struct us_ip *ip)
+{
+       return swap_register_uretprobe(&ip->retprobe);
+}
+
+static void urp_unregister_probe(struct us_ip *ip, int disarm)
+{
+       __swap_unregister_uretprobe(&ip->retprobe, disarm);
+}
+
+static void urp_init(struct us_ip *ip)
+{
+       ip->retprobe.entry_handler = urp_entry_handler;
+       ip->retprobe.handler = urp_ret_handler;
+       ip->retprobe.maxactive = 0;
+       /* FIXME: make dynamic size field 'data_size' */
+       ip->retprobe.data_size = sizeof(void *);
+}
+
+static void urp_uninit(struct us_ip *ip)
+{
+}
+
+static struct probe_iface urp_iface = {
+       .init = urp_init,
+       .uninit = urp_uninit,
+       .reg = urp_register_probe,
+       .unreg = urp_unregister_probe,
+       .get_uprobe = urp_get_uprobe,
+       .copy = urp_copy,
+       .cleanup = urp_cleanup
+};
+
+
+
+
+/*
+ * init/exit()
+ */
+int pin_init(void)
+{
+       int ret;
+
+       ret = swap_register_probe_type(SWAP_NEW_UP, &up_iface);
+       if (ret)
+               return ret;
+
+       ret = swap_register_probe_type(SWAP_NEW_URP, &urp_iface);
+       if (ret)
+               swap_unregister_probe_type(SWAP_NEW_UP);
+
+       return ret;
+}
+
+void pin_exit(void)
+{
+       swap_unregister_probe_type(SWAP_NEW_URP);
+       swap_unregister_probe_type(SWAP_NEW_UP);
+}
diff --git a/us_manager/probes/probe_info_new.h b/us_manager/probes/probe_info_new.h
new file mode 100644 (file)
index 0000000..0d71348
--- /dev/null
@@ -0,0 +1,88 @@
+#ifndef _PROBE_INFO_NEW_H
+#define _PROBE_INFO_NEW_H
+
+/*
+ * 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, 2015
+ *
+ * 2015         Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+
+#include <kprobe/swap_kprobes.h>
+#include <uprobe/swap_uprobes.h>
+
+
+struct dentry;
+struct pf_group;
+
+
+struct probe_info_new {
+       enum probe_t type;
+       union {
+               struct {
+                       kprobe_pre_handler_t handler;
+               };
+
+               struct {
+                       uretprobe_handler_t entry_handler;
+                       uretprobe_handler_t ret_handler;
+                       /*
+                        * FIXME: make dynamic size,
+                        *        currently data_size = sizeof(void *)
+                        */
+                       size_t data_size;
+               };
+       };
+
+       /* private */
+       struct probe_info *info;
+};
+
+
+struct probe_new {
+       unsigned long offset;
+       struct probe_info_new *info;
+};
+
+
+#define MAKE_UPROBE(_handler)                          \
+       {                                               \
+               .type = SWAP_NEW_UP,                    \
+               .handler = _handler                     \
+       }
+
+#define MAKE_URPROBE(_entry, _ret, _size)              \
+       {                                               \
+               .type = SWAP_NEW_URP,                   \
+               .entry_handler = _entry,                \
+               .ret_handler = _ret,                    \
+               .data_size = _size                      \
+       }
+
+
+int pin_register(struct probe_new *probe, struct pf_group *pfg,
+                struct dentry *dentry);
+int pin_unregister(struct probe_new *probe, struct pf_group *pfg,
+                  struct dentry *dentry);
+
+
+int pin_init(void);
+void pin_exit(void);
+
+
+#endif /* _PROBE_INFO_NEW_H */
index dbd3392..b82eec7 100644 (file)
@@ -52,6 +52,8 @@ enum probe_t {
        SWAP_WEBPROBE = 3,          /* Webprobe */
        SWAP_GET_CALLER = 4,        /* Get caller probe. Supports preload */
        SWAP_GET_CALL_TYPE = 5,     /* Get call type probe. Supports preload */
+       SWAP_NEW_UP,
+       SWAP_NEW_URP,
        SWAP_PROBE_MAX_VAL          /* Probes max value. */
 };
 
index b19cbc6..a5974be 100644 (file)
@@ -26,6 +26,7 @@
 #include <linux/mutex.h>
 #include "pf/pf_group.h"
 #include "sspt/sspt_proc.h"
+#include "probes/probe_info_new.h"
 #include "helper.h"
 #include "us_manager.h"
 #include "usm_msg.h"
@@ -221,7 +222,13 @@ static int init_us_manager(void)
 {
        int ret;
 
+       ret = pin_init();
+       if (ret)
+               return ret;
+
        ret = init_us_filter();
+       if (ret)
+               pin_exit();
 
        return ret;
 }
@@ -232,6 +239,7 @@ static void exit_us_manager(void)
                do_usm_stop();
 
        exit_us_filter();
+       pin_exit();
 }
 
 SWAP_LIGHT_INIT_MODULE(usm_once, init_us_manager, exit_us_manager,