[IMPROVE] add implementation the syscall instrumentation
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Mon, 8 Jul 2013 16:17:37 +0000 (20:17 +0400)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Mon, 8 Jul 2013 16:17:37 +0000 (20:17 +0400)
parser/Kbuild
parser/features.c [new file with mode: 0644]
parser/features.h [new file with mode: 0644]
parser/msg_cmd.c
parser/msg_cmd.h
parser/swap_msg_parser.c

index 8ea23a2..d344223 100644 (file)
@@ -4,4 +4,5 @@ obj-m := swap_message_parser.o
 swap_message_parser-y := swap_msg_parser.o \
                          msg_parser.o \
                          msg_buf.o \
-                         msg_cmd.o
+                         msg_cmd.o \
+                         features.o
diff --git a/parser/features.c b/parser/features.c
new file mode 100644 (file)
index 0000000..e07ad12
--- /dev/null
@@ -0,0 +1,284 @@
+#include <linux/types.h>
+#include <linux/module.h>
+#include "features.h"
+#include <ks_features/ks_features.h>
+
+enum features_list {
+       syscall_file    = (1 << 10),    /* File operation syscalls tracing */
+       syscall_ipc     = (1 << 11),    /* IPC syscall tracing */
+       syscall_process = (1 << 12),    /* Process syscalls tracing */
+       syscall_signal  = (1 << 13),    /* Signal syscalls tracing */
+       syscall_network = (1 << 14),    /* Network syscalls tracing */
+       syscall_desc    = (1 << 15),    /* Descriptor syscalls tracing */
+       context_switch  = (1 << 16),    /* Context switch tracing */
+       func_sampling   = (1 << 19)     /* Function sampling */
+};
+
+int set_syscall_file(void)
+{
+       int ret;
+
+       ret = set_feature(FID_FILE);
+
+       return ret;
+}
+
+int unset_syscall_file(void)
+{
+       int ret;
+
+       ret = unset_feature(FID_FILE);
+
+       return ret;
+}
+
+int set_syscall_ipc(void)
+{
+       int ret;
+
+       ret = set_feature(FID_IPC);
+
+       return ret;
+}
+
+int unset_syscall_ipc(void)
+{
+       int ret;
+
+       ret = unset_feature(FID_IPC);
+
+       return ret;
+}
+
+int set_syscall_process(void)
+{
+       int ret;
+
+       ret = set_feature(FID_PROCESS);
+
+       return ret;
+}
+
+int unset_syscall_process(void)
+{
+       int ret;
+
+       ret = unset_feature(FID_PROCESS);
+
+       return ret;
+}
+
+int set_syscall_signal(void)
+{
+       int ret;
+
+       ret = set_feature(FID_SIGNAL);
+
+       return ret;
+}
+
+int unset_syscall_signal(void)
+{
+       int ret;
+
+       ret = unset_feature(FID_SIGNAL);
+
+       return ret;
+}
+
+int set_syscall_network(void)
+{
+       int ret;
+
+       ret = set_feature(FID_NET);
+
+       return ret;
+}
+
+int unset_syscall_network(void)
+{
+       int ret;
+
+       ret = unset_feature(FID_NET);
+
+       return ret;
+}
+
+int set_syscall_desc(void)
+{
+       int ret;
+
+       ret = set_feature(FID_DESC);
+
+       return ret;
+}
+
+int unset_syscall_desc(void)
+{
+       int ret;
+
+       ret = unset_feature(FID_DESC);
+
+       return ret;
+}
+
+int set_context_switch(void)
+{
+       printk("### set_context_switch\n");
+
+       return -EINVAL;
+}
+
+int unset_context_switch(void)
+{
+       printk("### unset_context_switch\n");
+
+       return -EINVAL;
+}
+
+int set_func_sampling(void)
+{
+       printk("### set_func_sampling\n");
+
+       return -EINVAL;
+}
+
+int unset_func_sampling(void)
+{
+       printk("### unset_func_sampling\n");
+
+       return -EINVAL;
+}
+
+struct feature_item {
+       char *name;
+       int (*set)(void);
+       int (*unset)(void);
+};
+
+static struct feature_item feature_syscall_file = {
+       .name = "file operation syscalls",
+       .set = set_syscall_file,
+       .unset = unset_syscall_file
+};
+
+static struct feature_item feature_syscall_ipc = {
+       .name = "IPC syscall",
+       .set = set_syscall_ipc,
+       .unset = unset_syscall_ipc
+};
+
+static struct feature_item feature_syscall_process = {
+       .name = "process syscalls",
+       .set = set_syscall_process,
+       .unset = unset_syscall_process
+};
+
+static struct feature_item feature_syscall_signal = {
+       .name = "signal syscalls",
+       .set = set_syscall_signal,
+       .unset = unset_syscall_signal
+};
+
+static struct feature_item feature_syscall_network = {
+       .name = "network syscalls",
+       .set = set_syscall_network,
+       .unset = unset_syscall_network
+};
+
+static struct feature_item feature_syscall_desc = {
+       .name = "descriptor syscalls",
+       .set = set_syscall_desc,
+       .unset = unset_syscall_desc
+};
+
+static struct feature_item feature_context_switch = {
+       .name = "context switch",
+       .set = set_context_switch,
+       .unset = unset_context_switch
+};
+
+static struct feature_item feature_func_sampling = {
+       .name = "function sampling",
+       .set = set_func_sampling,
+       .unset = unset_func_sampling
+};
+
+static struct feature_item *feature_list[] = {
+ /*  0 */      NULL,
+ /*  1 */      NULL,
+ /*  2 */      NULL,
+ /*  3 */      NULL,
+ /*  4 */      NULL,
+ /*  5 */      NULL,
+ /*  6 */      NULL,
+ /*  7 */      NULL,
+ /*  8 */      NULL,
+ /*  9 */      NULL,
+ /* 10 */      &feature_syscall_file,
+ /* 11 */      &feature_syscall_ipc,
+ /* 12 */      &feature_syscall_process,
+ /* 13 */      &feature_syscall_signal,
+ /* 14 */      &feature_syscall_network,
+ /* 15 */      &feature_syscall_desc,
+ /* 16 */      &feature_context_switch,
+ /* 17 */      NULL,
+ /* 18 */      NULL,
+ /* 19 */      &feature_func_sampling
+};
+
+enum {
+       SIZE_FEATURE_LIST = sizeof(feature_list) / sizeof(struct feature_item *),
+};
+
+static u64 feature_inst = 0;
+static u64 feature_mask = 0;
+
+int init_features(void)
+{
+       int i;
+       for (i = 0; i < SIZE_FEATURE_LIST; ++i) {
+               printk("### f init_feature_mask[%2d]=%p\n", i, feature_list[i]);
+               if (feature_list[i] != NULL) {
+                       feature_mask |= ((u64)1) << i;
+                       printk("### f name=%s\n", feature_list[i]->name);
+               }
+       }
+
+       return 0;
+}
+
+void uninit_features(void)
+{
+}
+
+int set_features(u64 features)
+{
+       int i, ret;
+       u64 feature_XOR;
+
+       features &= feature_mask;
+       feature_XOR = features ^ feature_inst;
+
+       for (i = 0; feature_XOR && i < SIZE_FEATURE_LIST; ++i) {
+               if ((feature_XOR & 1) && feature_list[i] != NULL) {
+                       if (features & 1)
+                               ret = feature_list[i]->set();
+                       else
+                               ret = feature_list[i]->unset();
+
+                       if (ret) {
+                               char *func = features & 1 ? "set" : "unset";
+                               print_err("%s '%s' ret=%d\n",
+                                         func, feature_list[i]->name, ret);
+
+                               return ret;
+                       }
+               }
+
+               features >>= 1;
+               feature_XOR >>= 1;
+       }
+
+       return 0;
+}
diff --git a/parser/features.h b/parser/features.h
new file mode 100644 (file)
index 0000000..ae0310a
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef _FEATURES_H
+#define _FEATURES_H
+
+#include <linux/types.h>
+
+int init_features(void);
+void uninit_features(void);
+
+int set_features(u64 features);
+
+#endif /* _FEATURES_H */
index 5675002..2b5c9a3 100644 (file)
@@ -1,8 +1,33 @@
 #include <linux/errno.h>
 #include "msg_parser.h"
 #include "msg_buf.h"
+#include "features.h"
 #include "parser_defs.h"
 
+static int set_app_info(struct app_info_data *app_info)
+{
+       return 0;
+}
+
+static int set_config(struct conf_data *conf)
+{
+       int ret;
+
+       ret = set_features(conf->use_features);
+
+       return ret;
+}
+
+static int add_us_inst(struct us_inst_data *us_inst)
+{
+       return 0;
+}
+
+static int remove_us_inst(struct us_inst_data *us_inst)
+{
+       return 0;
+}
+
 int msg_keep_alive(struct msg_buf *mb)
 {
        if (!is_end_mb(mb)) {
@@ -43,6 +68,8 @@ int msg_start(struct msg_buf *mb)
        }
 
        /* TODO implement the processing */
+       set_config(conf);
+
 
 free_us_inst:
        destroy_us_inst_data(us_inst);
@@ -84,6 +111,7 @@ int msg_config(struct msg_buf *mb)
        }
 
        /* TODO implement the processing */
+       set_config(conf);
 
 free_conf_data:
        destroy_conf_data(conf);
@@ -138,3 +166,17 @@ free_us_inst:
 
        return ret;
 }
+
+int init_cmd(void)
+{
+       int ret;
+
+       ret = init_features();
+
+       return ret;
+}
+
+void uninit_cmd(void)
+{
+       uninit_features();
+}
index 9d2afc9..3cd43c8 100644 (file)
@@ -3,6 +3,9 @@
 
 struct msg_buf;
 
+int init_cmd(void);
+void uninit_cmd(void);
+
 int msg_keep_alive(struct msg_buf *mb);
 int msg_start(struct msg_buf *mb);
 int msg_stop(struct msg_buf *mb);
index 53a730d..bf11d18 100644 (file)
@@ -91,13 +91,17 @@ static void unregister_msg_handler(void)
 
 static int __init swap_parser_init(void)
 {
+       int ret;
        register_msg_handler();
 
-       return 0;
+       ret = init_cmd();
+
+       return ret;
 }
 
 static void __exit swap_parser_exit(void)
 {
+       uninit_cmd();
        unregister_msg_handler();
 }