[IMPROVE] add private field in struct proc_filter
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Sun, 14 Jul 2013 11:33:54 +0000 (15:33 +0400)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Sun, 14 Jul 2013 11:33:54 +0000 (15:33 +0400)
for calculation lowest address and highest address binary file,
when sending message process info

parser/us_inst.c
us_manager/pf/pf_group.c
us_manager/pf/pf_group.h
us_manager/pf/proc_filters.c
us_manager/pf/proc_filters.h
us_manager/sspt/sspt.h
us_manager/sspt/sspt_proc.c
us_manager/sspt/sspt_proc.h
writer/swap_writer_module.c
writer/swap_writer_module.h

index d930966..6f39b1a 100644 (file)
@@ -82,17 +82,17 @@ static int get_pfg_by_app_info(struct app_info_data *app_info, struct pf_group *
 {
        struct dentry *dentry;
 
+       dentry = dentry_by_path(app_info->exec_path);
+       if (dentry == NULL)
+               return -EINVAL;
+
        switch (app_info->app_type) {
        case AT_PID:
-               *pfg = get_pf_group_by_tgid(app_info->tgid);
+               *pfg = get_pf_group_by_tgid(app_info->tgid, dentry);
                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);
+               *pfg = get_pf_group_by_dentry(dentry, dentry);
                break;
        default:
                printk("ERROR: app_type=%0x%x\n", app_info->app_type);
index 93e6ff5..a2e4d79 100644 (file)
@@ -98,7 +98,7 @@ static struct sspt_proc *get_proc_by_pfg_or_new(struct pf_group *pfg,
        if (proc == NULL) {
                struct pl_struct *pls;
 
-               proc = sspt_proc_get_by_task_or_new(task);
+               proc = sspt_proc_get_by_task_or_new(task, pfg->filter->priv);
                copy_proc_form_img_to_sspt(pfg->i_proc, proc);
 
                pls = create_pl_struct(proc);
@@ -137,7 +137,7 @@ static void del_pfg_by_list(struct pf_group *pfg)
        list_del(&pfg->list);
 }
 
-struct pf_group *get_pf_group_by_dentry(struct dentry *dentry)
+struct pf_group *get_pf_group_by_dentry(struct dentry *dentry, void *priv)
 {
        struct pf_group *pfg;
        struct proc_filter *filter;
@@ -147,7 +147,7 @@ struct pf_group *get_pf_group_by_dentry(struct dentry *dentry)
                        return pfg;
        }
 
-       filter = create_pf_by_dentry(dentry);
+       filter = create_pf_by_dentry(dentry, priv);
        pfg = create_pfg(filter);
 
        add_pfg_by_list(pfg);
@@ -156,7 +156,7 @@ struct pf_group *get_pf_group_by_dentry(struct dentry *dentry)
 }
 EXPORT_SYMBOL_GPL(get_pf_group_by_dentry);
 
-struct pf_group *get_pf_group_by_tgid(pid_t tgid)
+struct pf_group *get_pf_group_by_tgid(pid_t tgid, void *priv)
 {
        struct pf_group *pfg;
        struct proc_filter *filter;
@@ -166,7 +166,7 @@ struct pf_group *get_pf_group_by_tgid(pid_t tgid)
                        return pfg;
        }
 
-       filter = create_pf_by_tgid(tgid);
+       filter = create_pf_by_tgid(tgid, priv);
        pfg = create_pfg(filter);
 
        add_pfg_by_list(pfg);
@@ -276,7 +276,8 @@ void install_all(void)
 
                list_for_each_entry(pfg, &pfg_list, list) {
                        if (check_task_f(pfg->filter, task)) {
-                               proc = sspt_proc_get_by_task_or_new(task);
+                               proc = sspt_proc_get_by_task_or_new(task,
+                                                       pfg->filter->priv);
                                sspt_proc_install(proc);
                        }
                }
index 2062ffe..0278e0b 100644 (file)
@@ -6,8 +6,8 @@
 struct dentry;
 struct pf_group;
 
-struct pf_group *get_pf_group_by_dentry(struct dentry *dentry);
-struct pf_group *get_pf_group_by_tgid(pid_t tgid);
+struct pf_group *get_pf_group_by_dentry(struct dentry *dentry, void *priv);
+struct pf_group *get_pf_group_by_tgid(pid_t tgid, void *priv);
 void put_pf_group(struct pf_group *pfg);
 
 int pf_register_probe(struct pf_group *pfg, struct dentry *dentry,
index 43004a0..4b6eeb0 100644 (file)
@@ -52,21 +52,23 @@ static struct proc_filter *create_pf(void)
        return pf;
 }
 
-struct proc_filter *create_pf_by_dentry(struct dentry *dentry)
+struct proc_filter *create_pf_by_dentry(struct dentry *dentry, void *priv)
 {
        struct proc_filter *pf = create_pf();
 
        pf->call = &call_by_dentry;
        pf->data = (void *)dentry;
+       pf->priv = priv;
 
        return pf;
 }
-struct proc_filter *create_pf_by_tgid(pid_t tgid)
+struct proc_filter *create_pf_by_tgid(pid_t tgid, void *priv)
 {
        struct proc_filter *pf = create_pf();
 
        pf->call = &call_by_tgid;
        pf->data = (void *)tgid;
+       pf->priv = priv;
 
        return pf;
 }
index 315d18d..41ae1d4 100644 (file)
@@ -9,12 +9,13 @@ struct proc_filter {
        struct task_struct *(*call)(struct proc_filter *self,
                                    struct task_struct *task);
        void *data;
+       void *priv;
 };
 
 #define check_task_f(filter, task) filter->call(filter, task)
 
-struct proc_filter *create_pf_by_dentry(struct dentry *dentry);
-struct proc_filter *create_pf_by_tgid(pid_t tgid);
+struct proc_filter *create_pf_by_dentry(struct dentry *dentry, void *priv);
+struct proc_filter *create_pf_by_tgid(pid_t tgid, void *priv);
 void free_pf(struct proc_filter *pf);
 
 int check_pf_by_dentry(struct proc_filter *filter, struct dentry *dentry);
index 669a52b..1e71141 100644 (file)
@@ -51,7 +51,8 @@ static inline struct sspt_proc *get_file_probes(inst_us_proc_t *task_inst_info)
        int i, ret;
        struct pf_group *pfg;
 
-       pfg = get_pf_group_by_dentry(task_inst_info->m_f_dentry);
+       pfg = get_pf_group_by_dentry(task_inst_info->m_f_dentry,
+                                    task_inst_info->m_f_dentry);
 
        for (i = 0; i < task_inst_info->libs_count; ++i) {
                int k, j;
index 4a9df7f..4572322 100644 (file)
@@ -56,7 +56,7 @@
 
 static LIST_HEAD(proc_probes_list);
 
-struct sspt_proc *sspt_proc_create(struct task_struct *task)
+struct sspt_proc *sspt_proc_create(struct task_struct *task, void *priv)
 {
        struct sspt_proc *proc = kmalloc(sizeof(*proc), GFP_ATOMIC);
 
@@ -72,7 +72,7 @@ struct sspt_proc *sspt_proc_create(struct task_struct *task)
                list_add(&proc->list, &proc_probes_list);
        }
 
-       proc_info_msg(task);
+       proc_info_msg(task, priv);
 
        return proc;
 }
@@ -105,11 +105,12 @@ struct sspt_proc *sspt_proc_get_by_task(struct task_struct *task)
        return NULL;
 }
 
-struct sspt_proc *sspt_proc_get_by_task_or_new(struct task_struct *task)
+struct sspt_proc *sspt_proc_get_by_task_or_new(struct task_struct *task,
+                                              void *priv)
 {
        struct sspt_proc *proc = sspt_proc_get_by_task(task);
        if (proc == NULL) {
-               proc = sspt_proc_create(task);
+               proc = sspt_proc_create(task, priv);
        }
 
        return proc;
index 0603266..aed27b9 100644 (file)
@@ -46,11 +46,12 @@ struct sspt_proc {
 };
 
 
-struct sspt_proc *sspt_proc_create(struct task_struct *task);
+struct sspt_proc *sspt_proc_create(struct task_struct *task, void *priv);
 void sspt_proc_free(struct sspt_proc *proc);
 
 struct sspt_proc *sspt_proc_get_by_task(struct task_struct *task);
-struct sspt_proc *sspt_proc_get_by_task_or_new(struct task_struct *task);
+struct sspt_proc *sspt_proc_get_by_task_or_new(struct task_struct *task,
+                                              void *priv);
 void sspt_proc_free_all(void);
 
 struct sspt_file *sspt_proc_find_file(struct sspt_proc *proc, struct dentry *dentry);
index 0711702..34b531f 100644 (file)
@@ -201,14 +201,36 @@ static int check_vma(struct vm_area_struct *vma)
                        !(vma->vm_flags & (VM_READ | VM_MAYREAD)));
 }
 
+static struct vm_area_struct *find_vma_by_dentry(struct mm_struct *mm,
+                                         struct dentry *dentry)
+{
+       struct vm_area_struct *vma;
+
+       down_write(&mm->mmap_sem);
+       for (vma = mm->mmap; vma; vma = vma->vm_next) {
+               if (check_vma(vma) && vma->vm_file &&
+                   (vma->vm_file->f_dentry == dentry))
+                       goto out;
+       }
+
+       vma = NULL;
+
+out:
+       up_write(&mm->mmap_sem);
+
+       return vma;
+}
+
 static char *pack_proc_info_part(char *bin_path, struct mm_struct *mm)
 {
        struct proc_info_part *pip;
        struct vm_area_struct *vma;
        char *lib_obj, *end_path = NULL;
        int lib_cnt = 0;
+       char bin_path_def[] = "";
 
-       end_path = pack_path(bin_path, mm->exe_file);
+       memcpy(bin_path, bin_path_def, sizeof(bin_path_def));
+       end_path = bin_path + sizeof(bin_path_def);
 
        pip = (struct proc_info_part *)end_path;
        lib_obj = pip->libs;
@@ -226,29 +248,32 @@ static char *pack_proc_info_part(char *bin_path, struct mm_struct *mm)
        return lib_obj;
 }
 
-static char *pack_proc_info(char *payload, struct task_struct *task)
+static char *pack_proc_info(char *payload, struct task_struct *task,
+                           void *priv)
 {
        struct proc_info *pi = (struct proc_info *)payload;
+       struct dentry *dentry_exec = (struct dentry *)priv;
+       struct vm_area_struct *vma = find_vma_by_dentry(task->mm, dentry_exec);
 
        pi->pid = task->tgid;
 
        /* FIXME: */
        pi->start_time = timespec2time(&task->start_time);
-       pi->low_addr = 2;
-       pi->high_addr = 3;
-       pi->app_type = 4;
-       pi->bin_type = 5;
+       pi->low_addr = vma ? vma->vm_start : 0;
+       pi->high_addr = vma ? vma->vm_end : 0;
+       pi->app_type = 1;       /* TODO: hardcode for Tizen*/
+       pi->bin_type = 0;       /* TODO: determined in US */
 
        return pack_proc_info_part(pi->bin_path, task->mm);
 }
 
-int proc_info_msg(struct task_struct *task)
+int proc_info_msg(struct task_struct *task, void *priv)
 {
        char *buf, *payload, *buf_end;
 
        buf = get_current_buf();
        payload = pack_basic_msg_fmt(buf, MSG_PROC_INFO);
-       buf_end = pack_proc_info(payload, task);
+       buf_end = pack_proc_info(payload, task, priv);
 
        set_len_msg(buf, buf_end);
 
index 74cd776..358c162 100644 (file)
@@ -23,7 +23,7 @@ struct pt_regs;
 int init_msg(size_t buf_size);
 void uninit_msg(void);
 
-int proc_info_msg(struct task_struct *task);
+int proc_info_msg(struct task_struct *task, void *priv);
 int sample_msg(struct pt_regs *regs);
 
 int entry_event(const char *fmt, struct pt_regs *regs,