1 #include <linux/module.h>
2 #include <linux/version.h>
3 #include <linux/errno.h>
4 #include <linux/namei.h>
5 #include <us_manager/pf/pf_group.h>
6 #include "msg_parser.h"
9 /* FIXME: create get_dentry() and put_dentry() */
10 static struct dentry *dentry_by_path(const char *path)
12 struct dentry *dentry;
13 #if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38)
15 if (kern_path(path, LOOKUP_FOLLOW, &st_path) != 0) {
16 #else /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */
18 if (path_lookup(path, LOOKUP_FOLLOW, &nd) != 0) {
19 #endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */
20 printk("failed to lookup dentry for path %s!\n", path);
24 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)
27 #elif LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 38)
28 dentry = nd.path.dentry;
30 #else /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */
31 dentry = st_path.dentry;
33 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25) */
38 static int mod_func_inst(struct func_inst_data *func, struct pf_group *pfg,
39 struct dentry *dentry, enum MOD_TYPE mt)
45 ret = pf_register_probe(pfg, dentry, func->addr, func->args);
48 ret = pf_unregister_probe(pfg, dentry, func->addr);
51 printk("ERROR: mod_type=0x%x\n", mt);
58 static int mod_lib_inst(struct lib_inst_data *lib, struct pf_group *pfg,
62 struct dentry *dentry;
64 dentry = dentry_by_path(lib->path);
66 printk("Cannot get dentry by path %s\n", lib->path);
70 for (i = 0; i < lib->cnt_func; ++i) {
71 ret = mod_func_inst(lib->func[i], pfg, dentry, mt);
73 printk("Cannot mod func inst, ret = %d\n", ret);
81 static int get_pfg_by_app_info(struct app_info_data *app_info, struct pf_group **pfg)
83 struct dentry *dentry;
85 dentry = dentry_by_path(app_info->exec_path);
89 switch (app_info->app_type) {
91 *pfg = get_pf_group_by_tgid(app_info->tgid, dentry);
93 case AT_TIZEN_NATIVE_APP:
95 *pfg = get_pf_group_by_dentry(dentry, dentry);
98 printk("ERROR: app_type=%0x%x\n", app_info->app_type);
105 static int mod_us_app_inst(struct app_inst_data *app_inst, enum MOD_TYPE mt)
108 struct pf_group *pfg;
109 struct dentry *dentry;
111 ret = get_pfg_by_app_info(app_inst->app_info, &pfg);
113 printk("Cannot get pfg by app info, ret = %d\n", ret);
117 for (i = 0; i < app_inst->cnt_func; ++i) {
119 dentry = dentry_by_path(app_inst->app_info->exec_path);
120 if (dentry == NULL) {
121 printk("Cannot find dentry by path %s\n",
122 app_inst->app_info->exec_path);
126 ret = mod_func_inst(app_inst->func[i], pfg, dentry, mt);
128 printk("Cannot mod func inst, ret = \n", ret);
133 for (i = 0; i < app_inst->cnt_lib; ++i) {
134 ret = mod_lib_inst(app_inst->lib[i], pfg, mt);
136 printk("Cannot mod lib inst, ret = %d\n", ret);
144 int mod_us_inst(struct us_inst_data *us_inst, enum MOD_TYPE mt)
149 for (i = 0; i < us_inst->cnt; ++i) {
150 ret = mod_us_app_inst(us_inst->app_inst[i], mt);
152 printk("Cannot mod us app inst, ret = %d\n", ret);