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);
68 for (i = 0; i < lib->cnt_func; ++i) {
69 ret = mod_func_inst(lib->func[i], pfg, dentry, mt);
77 static int get_pfg_by_app_info(struct app_info_data *app_info, struct pf_group **pfg)
79 struct dentry *dentry;
81 switch (app_info->app_type) {
83 *pfg = get_pf_group_by_tgid(app_info->tgid);
85 case AT_TIZEN_NATIVE_APP:
87 dentry = dentry_by_path(app_info->exec_path);
91 *pfg = get_pf_group_by_dentry(dentry);
94 printk("ERROR: app_type=%0x%x\n", app_info->app_type);
101 static int mod_us_app_inst(struct app_inst_data *app_inst, enum MOD_TYPE mt)
104 struct pf_group *pfg;
105 struct dentry *dentry;
107 ret = get_pfg_by_app_info(app_inst->app_info, &pfg);
111 for (i = 0; i < app_inst->cnt_func; ++i) {
113 dentry = dentry_by_path(app_inst->app_info->exec_path);
117 ret = mod_func_inst(app_inst->func[i], pfg, dentry, mt);
122 for (i = 0; i < app_inst->cnt_lib; ++i) {
123 ret = mod_lib_inst(app_inst->lib[i], pfg, mt);
131 int mod_us_inst(struct us_inst_data *us_inst, enum MOD_TYPE mt)
134 for (i = 0; i < us_inst->cnt; ++i) {
135 mod_us_app_inst(us_inst->app_inst[i], mt);