From 63aaec23a57321fc32fee4a3daf3147bd9b954ae Mon Sep 17 00:00:00 2001 From: Vyacheslav Cherkashin Date: Wed, 10 Jul 2013 12:28:46 +0400 Subject: [PATCH] [IMPROVE] implementation add/remove US inst --- parser/Kbuild | 3 +- parser/msg_cmd.c | 20 +++---- parser/us_inst.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++ parser/us_inst.h | 13 +++++ us_manager/pf/pf_group.c | 2 + 5 files changed, 161 insertions(+), 14 deletions(-) create mode 100644 parser/us_inst.c create mode 100644 parser/us_inst.h diff --git a/parser/Kbuild b/parser/Kbuild index d344223..1c1f36b 100644 --- a/parser/Kbuild +++ b/parser/Kbuild @@ -5,4 +5,5 @@ swap_message_parser-y := swap_msg_parser.o \ msg_parser.o \ msg_buf.o \ msg_cmd.o \ - features.o + features.o \ + us_inst.o diff --git a/parser/msg_cmd.c b/parser/msg_cmd.c index 2b5c9a3..3489c0d 100644 --- a/parser/msg_cmd.c +++ b/parser/msg_cmd.c @@ -3,6 +3,7 @@ #include "msg_buf.h" #include "features.h" #include "parser_defs.h" +#include "us_inst.h" static int set_app_info(struct app_info_data *app_info) { @@ -18,16 +19,6 @@ static int set_config(struct conf_data *conf) 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)) { @@ -68,8 +59,11 @@ int msg_start(struct msg_buf *mb) } /* TODO implement the processing */ - set_config(conf); + ret = set_config(conf); + if (ret) + goto free_us_inst; + ret = mod_us_inst(us_inst, MT_ADD); free_us_inst: destroy_us_inst_data(us_inst); @@ -135,7 +129,7 @@ int msg_swap_inst_add(struct msg_buf *mb) goto free_us_inst; } - /* TODO implement the processing */ + ret = mod_us_inst(us_inst, MT_ADD); free_us_inst: destroy_us_inst_data(us_inst); @@ -159,7 +153,7 @@ int msg_swap_inst_remove(struct msg_buf *mb) goto free_us_inst; } - /* TODO implement the processing */ + ret = mod_us_inst(us_inst, MT_DEL); free_us_inst: destroy_us_inst_data(us_inst); diff --git a/parser/us_inst.c b/parser/us_inst.c new file mode 100644 index 0000000..106ec08 --- /dev/null +++ b/parser/us_inst.c @@ -0,0 +1,137 @@ +#include +#include +#include +#include +#include +#include "msg_parser.h" +#include "us_inst.h" + +/* FIXME: create get_dentry() and put_dentry() */ +static struct dentry *dentry_by_path(const char *path) +{ + struct dentry *dentry; +#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) + struct path st_path; + if (kern_path(path, LOOKUP_FOLLOW, &st_path) != 0) { +#else /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */ + struct nameidata nd; + if (path_lookup(path, LOOKUP_FOLLOW, &nd) != 0) { +#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */ + printk("failed to lookup dentry for path %s!\n", path); + return NULL; + } + +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25) + dentry = nd.dentry; + path_release(&nd); +#elif LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 38) + dentry = nd.path.dentry; + path_put(&nd.path); +#else /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */ + dentry = st_path.dentry; + path_put(&st_path); +#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25) */ + return dentry; +} + + +static int mod_func_inst(struct func_inst_data *func, struct pf_group *pfg, + struct dentry *dentry, enum MOD_TYPE mt) +{ + int ret; + + switch (mt) { + case MT_ADD: + ret = pf_register_probe(pfg, dentry, func->addr, func->args); + break; + case MT_DEL: + ret = pf_unregister_probe(pfg, dentry, func->addr); + break; + default: + printk("ERROR: mod_type=0x%x\n", mt); + ret = -EINVAL; + } + + return ret; +} + +static int mod_lib_inst(struct lib_inst_data *lib, struct pf_group *pfg, + enum MOD_TYPE mt) +{ + int ret, i; + struct dentry *dentry; + + dentry = dentry_by_path(lib->path); + if (dentry == NULL) + return -EINVAL; + + for (i = 0; i < lib->cnt_func; ++i) { + ret = mod_func_inst(lib->func[i], pfg, dentry, mt); + if (ret) + return ret; + } + + return ret; +} + +static int get_pfg_by_app_info(struct app_info_data *app_info, struct pf_group **pfg) +{ + struct dentry *dentry; + + switch (app_info->app_type) { + case AT_PID: + *pfg = get_pf_group_by_tgid(app_info->tgid); + break; + case AT_TIZEN_NATIVE_APP: + case AT_COMMON_EXEC: + dentry = dentry_by_path(app_info->exec_path); + if (dentry == NULL) + return -EINVAL; + + *pfg = get_pf_group_by_dentry(dentry); + break; + default: + printk("ERROR: app_type=%0x%x\n", app_info->app_type); + return -EINVAL; + } + + return 0; +} + +static int mod_us_app_inst(struct app_inst_data *app_inst, enum MOD_TYPE mt) +{ + int ret, i; + struct pf_group *pfg; + struct dentry *dentry; + + ret = get_pfg_by_app_info(app_inst->app_info, &pfg); + if (ret) + return ret; + + for (i = 0; i < app_inst->cnt_func; ++i) { + /* TODO: */ + dentry = dentry_by_path(app_inst->app_info->exec_path); + if (dentry == NULL) + return -EINVAL; + + ret = mod_func_inst(app_inst->func[i], pfg, dentry, mt); + if (ret) + return ret; + } + + for (i = 0; i < app_inst->cnt_lib; ++i) { + ret = mod_lib_inst(app_inst->lib[i], pfg, mt); + if (ret) + return ret; + } + + return 0; +} + +int mod_us_inst(struct us_inst_data *us_inst, enum MOD_TYPE mt) +{ + u32 i; + for (i = 0; i < us_inst->cnt; ++i) { + mod_us_app_inst(us_inst->app_inst[i], mt); + } +} diff --git a/parser/us_inst.h b/parser/us_inst.h new file mode 100644 index 0000000..0f8e7e6 --- /dev/null +++ b/parser/us_inst.h @@ -0,0 +1,13 @@ +#ifndef _US_INST_H +#define _US_INST_H + +enum MOD_TYPE { + MT_ADD, + MT_DEL +}; + +struct us_inst_data; + +int mod_us_inst(struct us_inst_data *us_inst, enum MOD_TYPE mt); + +#endif /* _US_INST_H */ diff --git a/us_manager/pf/pf_group.c b/us_manager/pf/pf_group.c index d11661e..93e6ff5 100644 --- a/us_manager/pf/pf_group.c +++ b/us_manager/pf/pf_group.c @@ -173,6 +173,7 @@ struct pf_group *get_pf_group_by_tgid(pid_t tgid) return pfg; } +EXPORT_SYMBOL_GPL(get_pf_group_by_tgid); void put_pf_group(struct pf_group *pfg) { @@ -191,6 +192,7 @@ int pf_unregister_probe(struct pf_group *pfg, struct dentry *dentry, { return img_proc_del_ip(pfg->i_proc, dentry, offset); } +EXPORT_SYMBOL_GPL(pf_unregister_probe); static void install_page_by_pfg(struct pf_group *pfg, struct task_struct *task, unsigned long page_addr) -- 2.7.4