[REFACTOR] apps and libonly in one list
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Mon, 6 May 2013 11:57:05 +0000 (15:57 +0400)
committerVyacheslav Cherkashin <v.cherkashin@samsung.com>
Mon, 6 May 2013 11:57:05 +0000 (15:57 +0400)
driver/helper.c
driver/sspt/sspt_procs.c
driver/us_proc_inst.c

index 91acea7..c716d3d 100644 (file)
@@ -69,15 +69,15 @@ static int ret_handler_pf(struct kretprobe_instance *ri, struct pt_regs *regs)
                        pid_t tgid = find_proc_by_task(task, us_proc_info.m_f_dentry);
                        if (tgid) {
                                us_proc_info.tgid = gl_nNotifyTgid = tgid;
+                               procs = sspt_procs_get_by_task_or_new(task);
 
-                               us_proc_info.pp->sm = create_sm_us(task);
                                /* install probes in already mapped memory */
-                               install_proc_probes(task, us_proc_info.pp);
+                               install_proc_probes(task, procs);
                        }
                }
 
                if (us_proc_info.tgid == task->tgid) {
-                       procs = us_proc_info.pp;
+                       procs = sspt_procs_get_by_task_or_new(task);
                }
        }
 
@@ -112,15 +112,9 @@ static void recover_child(struct task_struct *child_task, struct sspt_procs *pro
 
 static void rm_uprobes_child(struct task_struct *task)
 {
-       if (is_libonly()) {
-               struct sspt_procs *procs = sspt_procs_get_by_task(current);
-               if(procs) {
-                       recover_child(task, procs);
-               }
-       } else {
-               if(us_proc_info.tgid == current->tgid) {
-                       recover_child(task, us_proc_info.pp);
-               }
+       struct sspt_procs *procs = sspt_procs_get_by_task(current);
+       if(procs) {
+               recover_child(task, procs);
        }
 }
 
@@ -165,7 +159,7 @@ static int mr_pre_handler(struct kprobe *p, struct pt_regs *regs)
                procs = sspt_procs_get_by_task(task);
        } else {
                if (task->tgid == us_proc_info.tgid) {
-                       procs = us_proc_info.pp;
+                       procs = sspt_procs_get_by_task(task);
                        us_proc_info.tgid = 0;
                }
        }
@@ -256,14 +250,7 @@ static int unmap_pre_handler(struct kprobe *p, struct pt_regs *regs)
                goto out;
        }
 
-       if (is_libonly()) {
-               procs = sspt_procs_get_by_task(task);
-       } else {
-               if (task->tgid == us_proc_info.tgid) {
-                       procs = us_proc_info.pp;
-               }
-       }
-
+       procs = sspt_procs_get_by_task(task);
        if (procs) {
                if (remove_unmap_probes(task, procs, start, len)) {
                        printk("ERROR do_munmap: start=%lx, len=%x\n", start, len);
index e2be70c..bae8d68 100644 (file)
@@ -96,17 +96,10 @@ void sspt_procs_free_all(void)
                return;
        }
 
-       if (strcmp(us_proc_info.path,"*") == 0) {
-               // app
-               sspt_procs_free(us_proc_info.pp);
-               us_proc_info.pp = NULL;
-       } else {
-               // libonly
-               struct sspt_procs *procs, *n;
-               list_for_each_entry_safe(procs, n, &proc_probes_list, list) {
-                       list_del(&procs->list);
-                       sspt_procs_free(procs);
-               }
+       struct sspt_procs *procs, *n;
+       list_for_each_entry_safe(procs, n, &proc_probes_list, list) {
+               list_del(&procs->list);
+               sspt_procs_free(procs);
        }
 }
 
index 5024f1e..d3f84f0 100644 (file)
@@ -233,6 +233,7 @@ int deinst_usr_space_proc (void)
 {
        int iRet = 0, found = 0;
        struct task_struct *task = NULL;
+       struct sspt_procs *procs;
 
        if (!is_us_instrumentation()) {
                return 0;
@@ -243,52 +244,16 @@ int deinst_usr_space_proc (void)
        if (iRet)
                EPRINTF ("uninstall_kernel_probe(do_munmap) result=%d!", iRet);
 
-       if (is_libonly()) {
-               struct sspt_procs *procs;
 
-               for_each_process(task)  {
-                       procs = sspt_procs_get_by_task(task);
-                       if (procs) {
-                               int ret = uninstall_us_proc_probes(task, procs, US_UNREGS_PROBE);
-                               if (ret) {
-                                       EPRINTF ("failed to uninstall IPs (%d)!", ret);
-                               }
-
-                               dbi_unregister_all_uprobes(task);
-                       }
-               }
-       }
-       else
-       {
-               if (us_proc_info.tgid == 0)
-                       return 0;
-                       rcu_read_lock ();
-               for_each_process (task)
-               {
-                       if (task->tgid == us_proc_info.tgid)
-                       {
-                               found = 1;
-                               get_task_struct (task);
-                               break;
-                       }
-               }
-               rcu_read_unlock ();
-               if (found)
-               {
-                       int i, ret;
-                       // uninstall IPs
-                       ret = uninstall_us_proc_probes(task, us_proc_info.pp, US_UNREGS_PROBE);
-                       if (ret != 0) {
-                               EPRINTF ("failed to uninstall IPs %d!", ret);
+       for_each_process(task) {
+               procs = sspt_procs_get_by_task(task);
+               if (procs) {
+                       int ret = uninstall_us_proc_probes(task, procs, US_UNREGS_PROBE);
+                       if (ret) {
+                               EPRINTF ("failed to uninstall IPs (%d)!", ret);
                        }
 
-                       put_task_struct (task);
-
-                       printk("### 1 ### dbi_unregister_all_uprobes:\n");
                        dbi_unregister_all_uprobes(task);
-                       us_proc_info.tgid = 0;
-                       for(i = 0; i < us_proc_info.libs_count; i++)
-                               us_proc_info.p_libs[i].loaded = 0;
                }
        }
 
@@ -342,14 +307,15 @@ int inst_usr_space_proc (void)
        }
        else
        {
-               ret = find_task_by_path (us_proc_info.path, &task, NULL);
-               if ( task  )
-               {
-                       DPRINTF("task found. installing probes");
+               ret = find_task_by_path(us_proc_info.path, &task, NULL);
+               if (task) {
+                       struct sspt_procs *procs;
+
+                       procs = sspt_procs_get_by_task_or_new(task);
+
                        us_proc_info.tgid = task->pid;
-                       us_proc_info.pp->sm = create_sm_us(task);
-                       install_proc_probes(task, us_proc_info.pp);
-                       put_task_struct (task);
+                       install_proc_probes(task, procs);
+                       put_task_struct(task);
                }
        }