setv PID command added
authorLeonid Astakhov <l.astakhov@samsung.com>
Wed, 27 Apr 2011 05:46:35 +0000 (09:46 +0400)
committerLeonid Astakhov <l.astakhov@samsung.com>
Wed, 27 Apr 2011 05:46:35 +0000 (09:46 +0400)
driver/debug.h
driver/device_driver.c
driver/ec_ioctl.h
driver/storage.c
driver/storage.h
driver/us_proc_inst.c
kprobe/arch/asm-arm/dbi_kprobes.c
kprobe/dbi_insn_slots.c
kprobe/dbi_kprobes_deps.c
kprobe/dbi_uprobes.c

index e1590f0..54b1f53 100644 (file)
@@ -21,7 +21,7 @@
 #include <linux/kernel.h>
 #include <linux/string.h>      // strrchr
 
-#undef __DEBUG
+// #undef __DEBUG
 
 #ifdef __DEBUG
 #define DPRINTF(format, args...) do { \
index a0ca315..767a0a0 100644 (file)
@@ -370,6 +370,23 @@ static int device_ioctl (struct inode *inode UNUSED, struct file *file UNUSED, u
 
                break;
        }
+       case EC_IOCTL_SET_PID:
+       {
+               unsigned int _pid;
+
+               result = copy_from_user(&_pid, (void *)arg, sizeof(unsigned int));
+               if (result) {
+                       EPRINTF("Cannot copy pid!");
+                       result = -1;
+                       break;
+               }
+
+               inst_pid = _pid;
+
+               DPRINTF("EC_IOCTL_SET_PID pid:%d", inst_pid);
+
+               break;
+       }
        case EC_IOCTL_SET_PROFILEBUNDLE:
        {
                size_t size;
index bc58f7d..2428235 100644 (file)
@@ -72,6 +72,8 @@ typedef enum
        EC_IOCTL_GET_PREDEF_UPROBES,
        EC_IOCTL_GET_PREDEF_UPROBES_SIZE,
 
+       EC_IOCTL_SET_PID,
+
 } EC_IOCTL_CMD;
 
 typedef struct
index 34aa826..c03be30 100644 (file)
@@ -30,6 +30,7 @@ char *p_buffer = NULL;
 inst_us_proc_t us_proc_info;
 char *deps;
 char *bundle;
+unsigned int inst_pid = 0;
 struct hlist_head kernel_probes;
 int event_mask = 0L;
 struct cond cond_list;
@@ -513,6 +514,19 @@ int SetBufferSize(unsigned int nSize) {
        return 0;
 }
 
+int SetPid(unsigned int pid)
+{
+       if (GetECState() != EC_STATE_IDLE)
+       {
+               EPRINTF("PID changes are allowed in IDLE state only (%d)!", GetECState());
+               return -1;
+       }
+
+       inst_pid = pid;
+       DPRINTF("SetPid pid:%d\n", pid);
+       return 0;
+}
+
 void ResetSingleBuffer(void) {
 }
 
@@ -840,6 +854,13 @@ int link_bundle()
        }
        p += sizeof(u_int32_t);
 
+       /* Pid */
+       if (SetPid(*(u_int32_t *)p) == -1) {
+               EPRINTF("Cannot set pid!\n");
+               return -1;
+       }
+       p += sizeof(u_int32_t);
+
        /* Kernel probes */
        nr_kern_probes = *(u_int32_t *)p;
        p += sizeof(u_int32_t);
@@ -926,6 +947,7 @@ int link_bundle()
                path_release(&nd);
 #else
                d_lib->m_f_dentry = nd.path.dentry;
+               d_lib->m_vfs_mount = nd.path.mnt;
                path_put(&nd.path);
 #endif
 
index fcc7e3e..f299889 100644 (file)
@@ -18,6 +18,7 @@
 #if !defined(__STORAGE_H__)
 #define __STORAGE_H__
 
+#include <linux/mount.h>
 #include "picl.h"
 #include "ec_ioctl.h"
 #include "ec_probe.h"
@@ -43,6 +44,8 @@ extern unsigned int GetBufferSize(void);
 extern int SetBufferSize(unsigned int nSize);
 extern int ResetBuffer(void);
 
+extern int SetPid(unsigned int pid);
+
 //extern spinlock_t buffer_spinlock;
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
@@ -119,6 +122,9 @@ extern struct hlist_head kernel_probes;
 // event mask
 extern int event_mask;
 
+// process pid to instrument
+extern unsigned int inst_pid;
+
 typedef struct
 {
        char *name;
@@ -147,11 +153,13 @@ typedef struct
 } us_proc_vtp_data_t;
 
 typedef struct dentry *STRUCT_DENTRY_PTR;
+typedef struct vfsmount *STRUCT_VFSMOUNT_PTR;
 
 typedef struct
 {
        char *path;
        STRUCT_DENTRY_PTR m_f_dentry;
+       STRUCT_VFSMOUNT_PTR m_vfs_mount;
        unsigned ips_count;
        us_proc_ip_t *p_ips;
        unsigned vtps_count;
index 33edb6a..6540c62 100644 (file)
@@ -184,6 +184,10 @@ static int find_task_by_path (const char *path, struct task_struct **p_task, str
 
        rcu_read_lock ();
        for_each_process (task) {
+
+               if  ( 0 != inst_pid && ( inst_pid != task->pid ) )
+                       continue;
+
                mm = get_task_mm (task);
                if (!mm)
                        continue;
@@ -194,7 +198,7 @@ static int find_task_by_path (const char *path, struct task_struct **p_task, str
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)
                                if (vma->vm_file->f_dentry == nd.dentry) {
 #else
-                                       if (vma->vm_file->f_dentry == nd.path.dentry) {
+                                       if (vma->vm_file->f_dentry == nd.path.dentry  ) {
 #endif
                                                if (!*p_task) {
                                                        *p_task = task;
@@ -320,15 +324,23 @@ static int install_mapped_ips (struct task_struct *task, inst_us_proc_t* task_in
        unsigned int old_ips_count, old_vtps_count;
        struct mm_struct *mm;
 
+       char path_buffer[256];
+
        mm = atomic ? task->active_mm : get_task_mm (task);
        if (!mm) {
                return task_inst_info->unres_ips_count + task_inst_info->unres_vtps_count;
        }
 
+//     DPRINTF("installing probes...");
+
        old_ips_count = task_inst_info->unres_ips_count;
        old_vtps_count = task_inst_info->unres_vtps_count;
+
        if(!atomic) 
                down_read (&mm->mmap_sem);
+
+//     DPRINTF("locked for read");
+
        vma = mm->mmap;
        while (vma) {
                // skip non-text section
@@ -352,33 +364,64 @@ static int install_mapped_ips (struct task_struct *task, inst_us_proc_t* task_in
                 * After process was forked, some time it inherits parent process environment.
                 * We need to renew instrumentation when we detect that process gets own environment.
                 */
-               if (vma->vm_flags & VM_EXECUTABLE) {
-                   if (!task_inst_info->m_f_dentry) {
-                       task_inst_info->m_f_dentry = vma->vm_file->f_dentry;
-                       printk("initiate dentry tgid = %d\n", task->tgid, task->comm);
-                   } else if (task_inst_info->m_f_dentry != vma->vm_file->f_dentry) {
-                       printk("we have detected that detry was changed tgid = %d\n", task->tgid, task->comm);
-                       for (i = 0; i < task_inst_info->libs_count; i++) {
-                           task_inst_info->p_libs[i].loaded = 0;
-                           for (k = 0; k < task_inst_info->p_libs[i].ips_count; k++) {
-                               task_inst_info->p_libs[i].p_ips[k].installed = 0;
-                               task_inst_info->unres_ips_count++;
-                           }
 
-                           for (k = 0; k < task_inst_info->p_libs[i].vtps_count; k++) {
-                               task_inst_info->p_libs[i].p_vtps[k].installed = 0;
-                               task_inst_info->unres_vtps_count++;
-                           }
+//         DPRINTF("vma_start:%x vma_end:%x", vma->vm_start, vma->vm_end );
 
-                           task_inst_info->m_f_dentry = vma->vm_file->f_dentry;
-                       }
+               if (vma->vm_flags & VM_EXECUTABLE)
+               {
+
+//                     DPRINTF("VM_EXECUTABLE");
+
+                   if (!task_inst_info->m_f_dentry)
+                   {
+                               task_inst_info->m_f_dentry = vma->vm_file->f_dentry;
+                               printk("initiate dentry tgid = %d\n", task->tgid, task->comm);
+                   }
+                   else if (task_inst_info->m_f_dentry != vma->vm_file->f_dentry)
+                   {
+                               printk("we have detected that detry was changed tgid = %d\n", task->tgid, task->comm);
+                               for (i = 0; i < task_inst_info->libs_count; i++)
+                               {
+                                       task_inst_info->p_libs[i].loaded = 0;
+                                       for (k = 0; k < task_inst_info->p_libs[i].ips_count; k++)
+                                       {
+                                               task_inst_info->p_libs[i].p_ips[k].installed = 0;
+                                               task_inst_info->unres_ips_count++;
+                                       }
+
+                                       for (k = 0; k < task_inst_info->p_libs[i].vtps_count; k++)
+                                       {
+                                               task_inst_info->p_libs[i].p_vtps[k].installed = 0;
+                                               task_inst_info->unres_vtps_count++;
+                                       }
+
+                                       task_inst_info->m_f_dentry = vma->vm_file->f_dentry;
+                               }
                    }
                }
+
+//             DPRINTF("Instrumenting libs. libcount:%d", task_inst_info->libs_count );
                
-               for (i = 0; i < task_inst_info->libs_count; i++) {      
+               for (i = 0; i < task_inst_info->libs_count; i++)
+               {
+//                     struct path tmp_path;
+//
+//                     tmp_path.dentry = task_inst_info->p_libs[i].m_f_dentry;
+//                     tmp_path.mnt = task_inst_info->p_libs[i].m_vfs_mount;
+//
+//                     char* p_path = d_path ( &tmp_path, path_buffer, 255 );
+//
+//                     DPRINTF("f_dentry:%x m_f_dentry:%x path:%s", vma->vm_file->f_dentry, task_inst_info->p_libs[i].m_f_dentry, p_path );
+
                        //TODO: test - try to instrument non-existing libs
-                       if (vma->vm_file->f_dentry == task_inst_info->p_libs[i].m_f_dentry) {
-                               if(!(vma->vm_flags & VM_EXECUTABLE) && !task_inst_info->p_libs[i].loaded) {
+                       if (vma->vm_file->f_dentry == task_inst_info->p_libs[i].m_f_dentry)
+                       {
+//                             DPRINTF("vm_flags:%x loaded:%x ips_count:%d vtps_count:%d", vma->vm_flags, task_inst_info->p_libs[i].loaded,
+//                                             task_inst_info->p_libs[i].ips_count, task_inst_info->p_libs[i].vtps_count );
+
+                               if(!(vma->vm_flags & VM_EXECUTABLE) && !task_inst_info->p_libs[i].loaded)
+                               {
+//                                     DPRINTF("!VM_EXECUTABLE && !loaded");
                                        char *p;
                                        DPRINTF ("post dyn lib event %s/%s", current->comm, task_inst_info->p_libs[i].path);
                                        // if we installed something, post library info for those IPs
@@ -392,11 +435,15 @@ static int install_mapped_ips (struct task_struct *task, inst_us_proc_t* task_in
                                                        task->tgid, p, vma->vm_start, vma->vm_end-vma->vm_start);
                                }
 
-                               for (k = 0; k < task_inst_info->p_libs[i].ips_count; k++) {
+                               for (k = 0; k < task_inst_info->p_libs[i].ips_count; k++)
+                               {
+//                                     DPRINTF("ips_count current:%d", k);
                                        if (!task_inst_info->p_libs[i].p_ips[k].installed)
                                        {
+//                                             DPRINTF("!installed");
                                                addr = task_inst_info->p_libs[i].p_ips[k].offset;
-                                               if (!(vma->vm_flags & VM_EXECUTABLE)) {
+                                               if (!(vma->vm_flags & VM_EXECUTABLE))
+                                               {
                                                        /* In the case of prelinking addr is already an
                                                         * absolute address so we do not need to add
                                                         * library base address to it.  We use a rule of
@@ -406,7 +453,8 @@ static int install_mapped_ips (struct task_struct *task, inst_us_proc_t* task_in
                                                        if (addr < vma->vm_start)
                                                                addr += vma->vm_start;
                                                }
-                                               if (page_present (mm, addr)) {
+                                               if (page_present (mm, addr))
+                                               {
                                                        DPRINTF ("pid %d, %s sym is loaded at %lx/%lx.", task->pid, task_inst_info->p_libs[i].path, task_inst_info->p_libs[i].p_ips[k].offset, addr);
                                                        task_inst_info->p_libs[i].p_ips[k].jprobe.kp.addr = (kprobe_opcode_t *) addr;
                                                        task_inst_info->p_libs[i].p_ips[k].retprobe.kp.addr = (kprobe_opcode_t *) addr;
@@ -414,20 +462,26 @@ static int install_mapped_ips (struct task_struct *task, inst_us_proc_t* task_in
                                                        task_inst_info->unres_ips_count--;
                                                        
                                                        err = register_usprobe (task, mm, &task_inst_info->p_libs[i].p_ips[k], atomic, 0);
-                                                       if (err != 0) {
+                                                       if (err != 0)
+                                                       {
                                                                DPRINTF ("failed to install IP at %lx/%p. Error %d!", task_inst_info->p_libs[i].p_ips[k].offset, 
                                                                                task_inst_info->p_libs[i].p_ips[k].jprobe.kp.addr, err);
                                                        }
                                                }
                                        }
                                }
-                               for (k = 0; k < task_inst_info->p_libs[i].vtps_count; k++) {
+                               for (k = 0; k < task_inst_info->p_libs[i].vtps_count; k++)
+                               {
+//                                     DPRINTF("vtps_count current:%d", k);
                                        if (!task_inst_info->p_libs[i].p_vtps[k].installed)
                                        {
+//                                             DPRINTF("!installed");
                                                addr = task_inst_info->p_libs[i].p_vtps[k].addr;
                                                if (!(vma->vm_flags & VM_EXECUTABLE))
                                                        addr += vma->vm_start;
-                                               if (page_present (mm, addr)) {
+                                               if (page_present (mm, addr))
+                                               {
+                                                       DPRINTF ("pid %d, %s sym is loaded at %lx/%lx.", task->pid, task_inst_info->p_libs[i].path, task_inst_info->p_libs[i].p_ips[k].offset, addr);
                                                        task_inst_info->p_libs[i].p_vtps[k].jprobe.kp.tgid = task_inst_info->tgid;
                                                        task_inst_info->p_libs[i].p_vtps[k].jprobe.kp.addr = (kprobe_opcode_t *) addr;
                                                        task_inst_info->p_libs[i].p_vtps[k].jprobe.entry = (kprobe_opcode_t *) us_vtp_event_handler;
@@ -437,7 +491,8 @@ static int install_mapped_ips (struct task_struct *task, inst_us_proc_t* task_in
                                                        task_inst_info->unres_vtps_count--;
                                                        
                                                        err = register_ujprobe (task, mm, &task_inst_info->p_libs[i].p_vtps[k].jprobe, atomic);
-                                                       if (err != 0) {
+                                                       if (err != 0)
+                                                       {
                                                                EPRINTF ("failed to install VTP at %p. Error %d!", 
                                                                                task_inst_info->p_libs[i].p_vtps[k].jprobe.kp.addr, err);
                                                        }
@@ -685,6 +740,9 @@ int inst_usr_space_proc (void)
        if (!us_proc_info.path)
                return 0;
 
+       DPRINTF("User space instr");
+
+
        for (i = 0; i < us_proc_info.libs_count; i++)
                us_proc_info.p_libs[i].loaded = 0;
        /* check whether process is already running
@@ -708,6 +766,7 @@ int inst_usr_space_proc (void)
                                        task_inst_info = copy_task_inst_info (task, &us_proc_info);
                                        put_task_inst_node(task, task_inst_info);
                                }
+                               DPRINTF("trying process");
                                install_mapped_ips (task, task_inst_info, 1);
                                //put_task_struct (task);
                                task_inst_info = NULL;
@@ -717,8 +776,9 @@ int inst_usr_space_proc (void)
        else
        {
                ret = find_task_by_path (us_proc_info.path, &task, NULL);
-                       if (task)
+               if ( task  )
                {
+                       DPRINTF("task found. installing probes");
                        us_proc_info.tgid = task->pid;
                        install_mapped_ips (task, &us_proc_info, 0);
                        put_task_struct (task);
index 394026b..1717912 100644 (file)
@@ -317,6 +317,7 @@ int arch_check_insn_arm (struct arch_specific_insn *ainsn)
                ARM_INSN_MATCH (BX, ainsn->insn[0]) ||
                ARM_INSN_MATCH (BXJ, ainsn->insn[0]))
        {
+               printk ("Bad insn arch_check_insn_arm: %lx\n", ainsn->insn[0]);
                DBPRINTF ("Bad insn arch_check_insn_arm: %lx\n", ainsn->insn[0]);
                ret = -EFAULT;
        }
@@ -330,6 +331,7 @@ int arch_check_insn_arm (struct arch_specific_insn *ainsn)
                        (ARM_INSN_REG_RD (ainsn->insn[0]) == 15))
        {
                DBPRINTF ("Bad arch_check_insn_arm: %lx\n", ainsn->insn[0]);
+               printk ("Bad arch_check_insn_arm: %lx\n", ainsn->insn[0]);
                ret = -EFAULT;
        }
 #endif // CONFIG_CPU_V7
@@ -340,6 +342,7 @@ int arch_check_insn_arm (struct arch_specific_insn *ainsn)
                         // store/load with pc update
                         ((ARM_INSN_REG_RN (ainsn->insn[0]) == 15) && (ainsn->insn[0] & 0x200000))))
        {
+               printk ("Bad insn arch_check_insn_arm: %lx\n", ainsn->insn[0]);
                DBPRINTF ("Bad insn arch_check_insn_arm: %lx\n", ainsn->insn[0]);
                ret = -EFAULT;
        }
@@ -371,6 +374,7 @@ int arch_check_insn_thumb (struct arch_specific_insn *ainsn)
                (THUMB2_INSN_MATCH (LDRWL, ainsn->insn[0]) && THUMB2_INSN_REG_RT(ainsn->insn[0]) == 15) ||
                (THUMB2_INSN_MATCH (DP, ainsn->insn[0]) && THUMB2_INSN_REG_RD(ainsn->insn[0]) == 15))
        {
+               printk ("Bad insn arch_check_insn_thumb: %lx\n", ainsn->insn[0]);
                DBPRINTF ("Bad insn arch_check_insn_thumb: %lx\n", ainsn->insn[0]);
                ret = -EFAULT;
        }
@@ -526,6 +530,8 @@ int arch_prepare_uprobe (struct kprobe *p, struct task_struct *task, int atomic)
 {
        int ret = 0;
 
+//     printk ( ">>>>>>>>>>>>>>>arch_prepare_uprobe  task:%s %x\n", task->comm, p->addr );
+
        if ((unsigned long) p->addr & 0x01)
        {
                DBPRINTF ("Attempt to register kprobe at an unaligned address");
@@ -880,11 +886,15 @@ int kprobe_handler (struct pt_regs *regs)
        int my_pr = 0;
        int i = 0;
 
+       preempt_disable ();
+
        if (user_mode(regs))
        {
                if (!thumb_mode ( regs )) addr = (kprobe_opcode_t *) (regs->uregs[15] - 4);
                else addr = (kprobe_opcode_t *) (regs->uregs[15] - 2);
 
+               //printk ("%s %x\n", __FUNCTION__, addr  );
+
                for(i = 0; i < my_probe; i++)
                {
                        if (my_p[i]->addr == addr)
@@ -901,17 +911,19 @@ int kprobe_handler (struct pt_regs *regs)
                {
                        my_handler_lock = 1;
 
-                       if (thumb_mode(regs))
+                       if (thumb_mode(regs) /*&& addr != 0xad327238 */)
                        {
                                if ((ret = arch_copy_trampoline_thumb_uprobe(my_p[my_pr], my_task[my_pr], my_atomic[my_pr])) != 0)
                                {
                                        printk(" >>>>> arch_copy_trampoline_thumb_uprobe error\n");
+                                       preempt_enable_no_resched ();
                                        return ret;
                                }
                        }else{
                                if ((ret = arch_copy_trampoline_arm_uprobe(my_p[my_pr], my_task[my_pr], my_atomic[my_pr])) != 0)
                                {
                                        printk(" >>>>> arch_copy_trampoline_arm_uprobe error\n");
+                                       preempt_enable_no_resched ();
                                        return ret;
                                }
                        }
@@ -928,8 +940,6 @@ int kprobe_handler (struct pt_regs *regs)
 //     DBPRINTF ("KPROBE: regs->uregs[15] = 0x%lx addr = 0x%p\n", regs->uregs[15], addr);
        //DBPRINTF("regs->uregs[14] = 0x%lx\n", regs->uregs[14]);
 
-       preempt_disable ();
-
        kcb = get_kprobe_ctlblk ();
 
        if (user_mode (regs))
index 78d03e3..01972ce 100644 (file)
@@ -93,18 +93,30 @@ unsigned long alloc_user_pages(struct task_struct *task, unsigned long len, unsi
        mm = atomic ? task->active_mm : get_task_mm (task);
        if (mm){
                if(!atomic)
-                       down_write (&mm->mmap_sem);
+               {
+                       if ( !down_write_trylock (&mm->mmap_sem) )
+                       {
+                               rcu_read_lock ();
+
+                               up_read (&mm->mmap_sem);
+                               down_write (&mm->mmap_sem);
+
+                               rcu_read_unlock();
+                       }
+               }
                // FIXME: its seems to be bad decision to replace 'current' pointer temporarily 
                current_thread_info()->task = task;
                ret = (unsigned long)do_mmap_pgoff(0, 0, len, prot, flags, 0);
                current_thread_info()->task = otask;
-               if(!atomic){
-                       up_write (&mm->mmap_sem);
+               if(!atomic)
+               {
+                       downgrade_write (&mm->mmap_sem);
                        mmput(mm);
                }
        }
        else
                printk ("proc %d has no mm", task->pid);
+
        return (unsigned long)ret;
 }
 
@@ -127,11 +139,15 @@ kprobe_opcode_t *get_insn_slot (struct task_struct *task, int atomic)
        struct hlist_head *page_list = task ? &uprobe_insn_pages : &kprobe_insn_pages;
        unsigned slots_per_page = INSNS_PER_PAGE, slot_size = MAX_INSN_SIZE;
 
+       printk (">>>>>>>>>>>>>>>>>>>>>>>>>>>> %s %d\n", __FUNCTION__, __LINE__);
+
        if(task) {
+               printk ("=========================== %s %d\n", __FUNCTION__, __LINE__);
                slots_per_page = INSNS_PER_PAGE/UPROBES_TRAMP_LEN;
                slot_size = UPROBES_TRAMP_LEN;
        }
        else {
+               printk ("=========================== %s %d\n", __FUNCTION__, __LINE__);
                slots_per_page = INSNS_PER_PAGE/KPROBES_TRAMP_LEN;
                slot_size = KPROBES_TRAMP_LEN;          
        }
@@ -139,6 +155,7 @@ kprobe_opcode_t *get_insn_slot (struct task_struct *task, int atomic)
 retry:
        hlist_for_each_entry (kip, pos, page_list, hlist)
        {
+               printk ("=========================== %s %d\n", __FUNCTION__, __LINE__);
                if (kip->nused < slots_per_page)
                {
                        int i;
@@ -149,6 +166,7 @@ retry:
                                        if(!task || (kip->tgid == task->tgid)){
                                                kip->slot_used[i] = SLOT_USED;
                                                kip->nused++;
+                                               printk ("=========================== %s %d\n", __FUNCTION__, __LINE__);
                                                return kip->insns + (i * slot_size);
                                        }
                                }
@@ -160,19 +178,23 @@ retry:
 
        /* If there are any garbage slots, collect it and try again. */
        if(task) {
+               printk ("=========================== %s %d\n", __FUNCTION__, __LINE__);
                if (uprobe_garbage_slots && collect_garbage_slots(page_list, task) == 0)
                        goto retry;
        }
        else {
+               printk ("=========================== %s %d\n", __FUNCTION__, __LINE__);
                if (kprobe_garbage_slots && collect_garbage_slots(page_list, task) == 0)
                        goto retry;             
        }
 
+       printk ("=========================== %s %d\n", __FUNCTION__, __LINE__);
        /* All out of space.  Need to allocate a new page. Use slot 0. */
        kip = kmalloc(sizeof(struct kprobe_insn_page), GFP_KERNEL);
        if (!kip)
                return NULL;
 
+       printk ("=========================== %s %d\n", __FUNCTION__, __LINE__);
        kip->slot_used = kmalloc(sizeof(char)*slots_per_page, GFP_KERNEL);
        if (!kip->slot_used){
                kfree(kip);
@@ -180,25 +202,32 @@ retry:
        }
 
        if(task) {
+               printk ("=========================== %s %d\n", __FUNCTION__, __LINE__);
                kip->insns = (kprobe_opcode_t *)alloc_user_pages(task, PAGE_SIZE, 
                                PROT_EXEC|PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_SHARED, atomic);
        }
        else {
+               printk ("=========================== %s %d\n", __FUNCTION__, __LINE__);
                kip->insns = kmalloc(PAGE_SIZE, GFP_KERNEL);
        }
        if (!kip->insns)
        {
+               printk ("=========================== %s %d\n", __FUNCTION__, __LINE__);
                kfree (kip->slot_used);
                kfree (kip);
                return NULL;
        }       
+       printk ("=========================== %s %d\n", __FUNCTION__, __LINE__);
        INIT_HLIST_NODE (&kip->hlist);
        hlist_add_head (&kip->hlist, page_list);
+       printk ("=========================== %s %d\n", __FUNCTION__, __LINE__);
        memset(kip->slot_used, SLOT_CLEAN, slots_per_page);
+       printk ("=========================== %s %d\n", __FUNCTION__, __LINE__);
        kip->slot_used[0] = SLOT_USED;
        kip->nused = 1;
        kip->ngarbage = 0;
        kip->tgid = task ? task->tgid : 0;
+       printk ("=========================== %s %d\n", __FUNCTION__, __LINE__);
        return kip->insns;
 }
 
index c58f052..885e649 100644 (file)
@@ -443,17 +443,21 @@ int get_user_pages_uprobe(struct task_struct *tsk, struct mm_struct *mm,
 #endif
 }
 
+
 int access_process_vm_atomic(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
 {
        struct mm_struct *mm;
        struct vm_area_struct *vma;
        void *old_buf = buf;
+       unsigned long addr1 = addr;
+       unsigned int* inst_buf = (unsigned int*)buf;
+
 
        mm = get_task_mm(tsk);
        if (!mm)
                return 0;
 
-       //down_read(&mm->mmap_sem);
+       down_read(&mm->mmap_sem);
        /* ignore errors, just check how much was successfully transferred */
        while (len) {
                int bytes, ret, offset;
@@ -462,6 +466,7 @@ int access_process_vm_atomic(struct task_struct *tsk, unsigned long addr, void *
 
                ret = get_user_pages_uprobe(tsk, mm, addr, 1,
                                write, 1, &page, &vma);
+
                if (ret <= 0) {
                        /*
                         * Check if this is a VM_IO | VM_PFNMAP VMA, which
@@ -500,9 +505,17 @@ int access_process_vm_atomic(struct task_struct *tsk, unsigned long addr, void *
                buf += bytes;
                addr += bytes;
        }
-       //up_read(&mm->mmap_sem);
+       up_read(&mm->mmap_sem);
        mmput(mm);
 
+
+       if(addr1 == 0xad327238)
+       {
+                       printk(">>>>> %s\n", tsk->comm);
+                       printk(">>>>> %x\n", inst_buf[0]);
+       }
+
+
        return buf - old_buf;
 }
 
index c5cde03..924eb09 100644 (file)
@@ -50,6 +50,8 @@ int __register_uprobe (struct kprobe *p, struct task_struct *task, int atomic, u
        int ret = 0;
        struct kprobe *old_p;
 
+//     printk (">>>>>>>>>>>>>>>>>>>>>>>>>>>>>> %s %d\n", __FUNCTION__, __LINE__);
+
        if (!p->addr)
                return -EINVAL;
 
@@ -81,24 +83,34 @@ int __register_uprobe (struct kprobe *p, struct task_struct *task, int atomic, u
                DBPRINTF ("goto out\n", ret);
                goto out;
        }
+
+//     printk ("================================ %s %d\n", __FUNCTION__, __LINE__);
        if ((ret = arch_prepare_uprobe (p, task, atomic)) != 0)
        {
-               DBPRINTF ("goto out\n", ret);
+//             printk ("================================ %s %d\n", __FUNCTION__, __LINE__);
+               DBPRINTF ("goto out\n", ret);
                goto out;
        }
 
+//     printk ("================================ %s %d\n", __FUNCTION__, __LINE__);
        DBPRINTF ("before out ret = 0x%x\n", ret);
 
        INIT_HLIST_NODE (&p->hlist);
+//     printk ("================================ %s %d\n", __FUNCTION__, __LINE__);
        hlist_add_head_rcu (&p->hlist, &kprobe_table[hash_ptr (p->addr, KPROBE_HASH_BITS)]);
 
        INIT_HLIST_NODE (&p->is_hlist);
+//     printk ("================================ %s %d\n", __FUNCTION__, __LINE__);
        hlist_add_head_rcu (&p->is_hlist, &uprobe_insn_slot_table[hash_ptr (p->ainsn.insn, KPROBE_HASH_BITS)]);
 
+//     printk ("================================ %s %d\n", __FUNCTION__, __LINE__);
        arch_arm_uprobe (p, task);
+//     printk ("================================ %s %d\n", __FUNCTION__, __LINE__);
+
 out:
        DBPRINTF ("out ret = 0x%x\n", ret);
 
+//     printk ("<<<<<<<<<<<<<<<<<<<<<<<<<<<<< %s %d\n", __FUNCTION__, __LINE__);
        return ret;
 }