[FEATURE] create sspt_feature
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Fri, 23 Aug 2013 17:02:34 +0000 (21:02 +0400)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Fri, 23 Aug 2013 17:02:34 +0000 (21:02 +0400)
us_manager/Kbuild
us_manager/sspt/sspt_feature.c [new file with mode: 0644]
us_manager/sspt/sspt_feature.h [new file with mode: 0644]
us_manager/sspt/sspt_proc.c
us_manager/sspt/sspt_proc.h

index 9d52c7c..31e1353 100644 (file)
@@ -3,6 +3,7 @@ EXTRA_CFLAGS := $(extra_cflags)
 obj-m := swap_us_manager.o
 swap_us_manager-y := us_manager.o us_slot_manager.o helper.o \
                      sspt/ip.o sspt/sspt_page.o sspt/sspt_file.o sspt/sspt_proc.o \
+                     sspt/sspt_feature.o \
                      pf/proc_filters.o pf/pf_group.o \
                      img/img_proc.o img/img_file.o img/img_ip.o \
                      us_def_handler.o
diff --git a/us_manager/sspt/sspt_feature.c b/us_manager/sspt/sspt_feature.c
new file mode 100644 (file)
index 0000000..9d6eaa0
--- /dev/null
@@ -0,0 +1,165 @@
+/*
+ *  Dynamic Binary Instrumentation Module based on KProbes
+ *  modules/us_manager/sspt/sspt_feature.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         Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+#include "sspt_feature.h"
+#include <linux/module.h>
+#include <linux/slab.h>
+#include <linux/list.h>
+
+
+struct sspt_feature {
+       struct list_head feature_list;
+};
+
+struct sspt_feature_img {
+       struct list_head list;
+
+       void *(*alloc)(void);
+       void (*free)(void *data);
+};
+
+struct sspt_feature_data {
+       struct list_head list;
+
+       struct sspt_feature_img *img;
+       void *data;
+};
+
+static LIST_HEAD(feature_list);
+
+static struct sspt_feature_data *create_feature_data(struct sspt_feature_img *img)
+{
+       struct sspt_feature_data *fd;
+
+       fd = kmalloc(sizeof(*fd), GFP_ATOMIC);
+       if (fd) {
+               INIT_LIST_HEAD(&fd->list);
+               fd->img = img;
+               fd->data = img->alloc();
+       }
+
+       return fd;
+}
+
+static void destroy_feature_data(struct sspt_feature_data *fd)
+{
+       fd->img->free(fd->data);
+       kfree(fd);
+}
+
+struct sspt_feature *sspt_create_feature(void)
+{
+       struct sspt_feature *f;
+
+       f = kmalloc(sizeof(*f), GFP_ATOMIC);
+       if (f) {
+               INIT_LIST_HEAD(&f->feature_list);
+
+               struct sspt_feature_data *fd;
+               struct sspt_feature_img *fi;
+
+               list_for_each_entry(fi, &feature_list, list) {
+                       fd = create_feature_data(fi);
+
+                       /* add to list */
+                       list_add(&fd->list, &f->feature_list);
+               }
+       }
+
+       return f;
+}
+
+void sspt_destroy_feature(struct sspt_feature *f)
+{
+       struct sspt_feature_data *fd, *n;
+
+       list_for_each_entry_safe(fd, n, &f->feature_list, list) {
+               /* delete from list */
+               list_del(&fd->list);
+               destroy_feature_data(fd);
+       }
+
+       kfree(f);
+}
+
+static struct sspt_feature_img *create_feature_img(void *(*alloc)(void),
+                                                  void (*free)(void *data))
+{
+       struct sspt_feature_img *fi;
+
+       fi = kmalloc(sizeof(*fi), GFP_ATOMIC);
+       if(fi) {
+               INIT_LIST_HEAD(&fi->list);
+               fi->alloc = alloc;
+               fi->free = free;
+
+               /* add to list */
+               list_add(&fi->list, &feature_list);
+       }
+
+       return fi;
+}
+
+static void destroy_feature_img(struct sspt_feature_img *fi)
+{
+       /* delete from list */
+       list_del(&fi->list);
+
+       kfree(fi);
+}
+
+void *sspt_get_feature_data(struct sspt_feature *f, sspt_feature_id_t id)
+{
+       struct sspt_feature_img *img = (struct sspt_feature_img *)id;
+       struct sspt_feature_data *fd;
+
+       list_for_each_entry(fd, &f->feature_list, list) {
+               if (img == fd->img)
+                       return fd->data;
+       }
+
+       return NULL;
+}
+EXPORT_SYMBOL_GPL(sspt_get_feature_data);
+
+sspt_feature_id_t sspt_register_feature(void *(*alloc)(void), void (*free)(void *data))
+{
+       struct sspt_feature_img *fi;
+
+       fi = create_feature_img(alloc, free);
+
+       /* TODO: add to already instrumentation process */
+
+       return (sspt_feature_id_t)fi;
+}
+EXPORT_SYMBOL_GPL(sspt_register_feature);
+
+void sspt_unregister_feature(sspt_feature_id_t id)
+{
+       struct sspt_feature_img *fi = (struct sspt_feature_img *)id;
+
+       /* TODO: remove from instrumentation process */
+       destroy_feature_img(fi);
+}
+EXPORT_SYMBOL_GPL(sspt_unregister_feature);
diff --git a/us_manager/sspt/sspt_feature.h b/us_manager/sspt/sspt_feature.h
new file mode 100644 (file)
index 0000000..ca372ed
--- /dev/null
@@ -0,0 +1,41 @@
+#ifndef _SSPT_FEATUER_H
+#define _SSPT_FEATUER_H
+
+/*
+ *  Dynamic Binary Instrumentation Module based on KProbes
+ *  modules/us_manager/sspt/sspt_feature.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, 2013
+ *
+ * 2013         Vyacheslav Cherkashin <v.cherkashin@samsung.com>
+ *
+ */
+
+struct sspt_feature;
+
+typedef void * sspt_feature_id_t;
+#define SSPT_FEATURE_ID_BAD    NULL
+
+struct sspt_feature *sspt_create_feature(void);
+void sspt_destroy_feature(struct sspt_feature *f);
+
+void *sspt_get_feature_data(struct sspt_feature *f, sspt_feature_id_t id);
+sspt_feature_id_t sspt_register_feature(void *(*alloc)(void),
+                                       void (*free)(void *data));
+void sspt_unregister_feature(sspt_feature_id_t id);
+
+#endif /* _SSPT_FEATUER_H */
index ac9a14e..73b21e6 100644 (file)
@@ -25,6 +25,8 @@
 #include "sspt.h"
 #include "sspt_proc.h"
 #include "sspt_page.h"
+#include "sspt_feature.h"
+#include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/list.h>
 #include <us_slot_manager.h>
@@ -60,6 +62,12 @@ struct sspt_proc *sspt_proc_create(struct task_struct *task, void *priv)
        struct sspt_proc *proc = kmalloc(sizeof(*proc), GFP_ATOMIC);
 
        if (proc) {
+               proc->feature = sspt_create_feature();
+               if (proc->feature == NULL) {
+                       kfree(proc);
+                       return NULL;
+               }
+
                INIT_LIST_HEAD(&proc->list);
                proc->tgid = task ? task->tgid : 0;
                proc->task = task;
@@ -86,6 +94,7 @@ void sspt_proc_free(struct sspt_proc *proc)
                sspt_file_free(file);
        }
 
+       sspt_destroy_feature(proc->feature);
        kfree(proc);
 }
 
@@ -101,6 +110,7 @@ struct sspt_proc *sspt_proc_get_by_task(struct task_struct *task)
 
        return NULL;
 }
+EXPORT_SYMBOL_GPL(sspt_proc_get_by_task);
 
 void on_each_proc(void (*func)(struct sspt_proc *proc))
 {
index b722adc..fee42e1 100644 (file)
@@ -43,6 +43,7 @@ struct sspt_proc {
        struct slot_manager *sm;
        struct list_head file_list;
        unsigned first_install:1;
+       struct sspt_feature *feature;
 };