diff options
author | Vitaliy Cherepanov <v.cherepanov@samsung.com> | 2013-02-12 08:34:50 +0400 |
---|---|---|
committer | Vitaliy Cherepanov <v.cherepanov@samsung.com> | 2013-02-12 08:34:50 +0400 |
commit | 52f31e2eae448473fefff282278ca6308d7a7662 (patch) | |
tree | e468c4c65c779c467d0eb5a020f467a7aae7aa79 /driver | |
parent | 4378ba3fb0e76304d0472ad7541b1a5924ace39f (diff) | |
parent | 98bff078071c54eaef85e9b0b3ebef6060dcad64 (diff) | |
download | swap-modules-52f31e2eae448473fefff282278ca6308d7a7662.tar.gz swap-modules-52f31e2eae448473fefff282278ca6308d7a7662.tar.bz2 swap-modules-52f31e2eae448473fefff282278ca6308d7a7662.zip |
Merge branch 'dev' of 106.109.8.71:/srv/git/dbi into dev
Diffstat (limited to 'driver')
-rw-r--r-- | driver/device_driver.c | 26 | ||||
-rw-r--r-- | driver/events.h | 2 | ||||
-rw-r--r-- | driver/module.c | 6 | ||||
-rw-r--r-- | driver/module.h | 2 | ||||
-rw-r--r-- | driver/probes.c | 14 | ||||
-rw-r--r-- | driver/probes_manager.c | 9 | ||||
-rw-r--r-- | driver/sspt/ip.c | 4 | ||||
-rw-r--r-- | driver/sspt/sspt.h | 16 | ||||
-rw-r--r-- | driver/sspt/sspt_debug.h | 41 | ||||
-rw-r--r-- | driver/sspt/sspt_file.c | 9 | ||||
-rw-r--r-- | driver/sspt/sspt_file.h | 2 | ||||
-rw-r--r-- | driver/sspt/sspt_page.c | 2 | ||||
-rw-r--r-- | driver/sspt/sspt_page.h | 2 | ||||
-rw-r--r-- | driver/sspt/sspt_procs.c | 4 | ||||
-rw-r--r-- | driver/sspt/sspt_procs.h | 4 | ||||
-rw-r--r-- | driver/storage.c | 145 | ||||
-rw-r--r-- | driver/us_proc_inst.c | 329 | ||||
-rw-r--r-- | driver/us_proc_inst.h | 14 |
18 files changed, 137 insertions, 494 deletions
diff --git a/driver/device_driver.c b/driver/device_driver.c index 1c3cf50f..9259124a 100644 --- a/driver/device_driver.c +++ b/driver/device_driver.c @@ -648,34 +648,8 @@ sad_cleanup: break; } - case EC_IOCTL_SET_PREDEF_UPROBES: - { - ioctl_predef_uprobes_info_t data; - - result = -1; - break; - - result = copy_from_user (&data, arg_pointer, sizeof (data)); - if (result) - { - result = -EFAULT; - break; - } - - result = set_predef_uprobes (&data); - if (result) - { - break; - } - DPRINTF("Set Predefined User Space Probes"); - break; - } - case EC_IOCTL_GET_PREDEF_UPROBES: { -// result = 0; -// break; - result = get_predef_uprobes((ioctl_predef_uprobes_info_t *)arg); if (result) { diff --git a/driver/events.h b/driver/events.h index 0f34ec59..8be66b5d 100644 --- a/driver/events.h +++ b/driver/events.h @@ -152,7 +152,7 @@ static char *PackArguments (char *pBuffer, unsigned long nLen, const char *szFor } #ifdef __KERNEL__ if((void *)s < (void *)TASK_SIZE) { - const char __user *S = (const char __user *) va_arg (args, const char *); + const char __user *S = (const char __user *) s; nLengthOfString = strlen_user (S); if(nFree < nLengthOfString) return NULL; // no space for arg diff --git a/driver/module.c b/driver/module.c index a01c3e47..c74dc82a 100644 --- a/driver/module.c +++ b/driver/module.c @@ -17,7 +17,7 @@ #include "module.h" -char gl_szDefaultDeviceName[128] = DEFAULT_DEVICE_NAME; +static char gl_szDefaultDeviceName[128] = DEFAULT_DEVICE_NAME; char* device_name = NULL; module_param (device_name, charp, 0); MODULE_PARM_DESC (device_name, "device name for '/proc/devices'"); @@ -27,7 +27,7 @@ module_param (device_major, uint, 0); MODULE_PARM_DESC (device_major, "default device major number"); #if (LINUX_VERSION_CODE != KERNEL_VERSION(2, 6, 16)) -void (*__real_put_task_struct) (struct task_struct * tsk); +static void (*__real_put_task_struct) (struct task_struct * tsk); #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 11)) #define SWAPDRV_PUT_TASK_STRUCT "put_task_struct" void @@ -62,8 +62,6 @@ void __put_task_struct(struct task_struct *tsk) void (*flush_cache_page) (struct vm_area_struct * vma, unsigned long page); #endif -#include "../../tools/gpmu/probes/entry_data.h" - storage_arg_t sa_dpf; static int __init InitializeModule(void) diff --git a/driver/module.h b/driver/module.h index fe774720..22fc12e6 100644 --- a/driver/module.h +++ b/driver/module.h @@ -71,9 +71,11 @@ #include "device_driver.h" #include "probes_manager.h" #include "probes.h" +#include "../../tools/gpmu/probes/entry_data.h" extern char *device_name; extern unsigned int device_major; +extern storage_arg_t sa_dpf; struct handler_map { unsigned long func_addr; diff --git a/driver/probes.c b/driver/probes.c index 4d98b951..9bc8a2fd 100644 --- a/driver/probes.c +++ b/driver/probes.c @@ -56,17 +56,3 @@ const char *ec_probe_name[] = { "rq_profile", "pid_rq_profile" }; - -//TODO: the same function should be used from utils.cpp -int name2index (unsigned *p_index, unsigned count, const char **names, const char *name) -{ - unsigned index; - for (index = 0; index < count; ++index) { - if (!strcmp (names[index], name)) { - *p_index = index; - return 0; - } - } - return -EINVAL; -} - diff --git a/driver/probes_manager.c b/driver/probes_manager.c index a60fd945..647be79a 100644 --- a/driver/probes_manager.c +++ b/driver/probes_manager.c @@ -288,7 +288,7 @@ add_probe (unsigned long addr) return result; } -int reset_probes() +int reset_probes(void) { struct hlist_node *node, *tnode; kernel_probe_t *p; @@ -394,8 +394,7 @@ remove_probe (unsigned long addr) return result; } -DEFINE_PER_CPU (kernel_probe_t *, gpKernProbe) = NULL; -EXPORT_PER_CPU_SYMBOL_GPL(gpKernProbe); +static DEFINE_PER_CPU(kernel_probe_t *, gpKernProbe) = NULL; unsigned long def_jprobe_event_pre_handler (kernel_probe_t * probe, struct pt_regs *regs) @@ -415,7 +414,7 @@ def_jprobe_event_handler (unsigned long arg1, unsigned long arg2, unsigned long if (pf_probe == probe) { if (us_proc_probes & US_PROC_PF_INSTLD) - do_page_fault_j_pre_code(arg1, arg2, arg3); + do_page_fault_j_pre_code(arg1, arg2, (struct pt_regs *) arg3); #ifdef CONFIG_X86 /* FIXME on x86 targets do_page_fault instrumentation may lead to * abnormal termination of some applications (in most cases GUI apps). @@ -531,7 +530,7 @@ void dbi_install_user_handlers(void) if(find_pre_handler) { pre_handler_addr = find_pre_handler(probe->addr); - if (find_pre_handler != 0) { + if (find_pre_handler != NULL) { DPRINTF("Added user pre handler for 0x%lx: 0x%lx", probe->addr, find_pre_handler); probe->jprobe.pre_entry = (kprobe_pre_entry_handler_t)pre_handler_addr; diff --git a/driver/sspt/ip.c b/driver/sspt/ip.c index dd2b8bce..c6e59ceb 100644 --- a/driver/sspt/ip.c +++ b/driver/sspt/ip.c @@ -82,7 +82,7 @@ struct us_ip *copy_ip(const struct us_ip *ip) struct us_ip *create_ip_by_ip_data(struct ip_data *ip_d) { struct us_ip *ip = create_ip(ip_d->offset); - set_ip_jp_handler(ip, ip_d->pre_handler, ip_d->jp_handler); + set_ip_jp_handler(ip, ip_d->pre_handler, (void *)ip_d->jp_handler); if (ip_d->flag_retprobe) { set_ip_rp_handler(ip, ip_d->rp_handler); @@ -96,5 +96,5 @@ struct us_ip *create_ip_by_ip_data(struct ip_data *ip_d) void sspt_set_ip_addr(struct us_ip *ip, const struct sspt_page *page, const struct sspt_file *file) { unsigned long addr = file->vm_start + page->offset + ip->offset; - ip->retprobe.kp.addr = ip->jprobe.kp.addr = addr; + ip->retprobe.kp.addr = ip->jprobe.kp.addr = (kprobe_opcode_t *)addr; } diff --git a/driver/sspt/sspt.h b/driver/sspt/sspt.h index 0cfe5307..e11be73a 100644 --- a/driver/sspt/sspt.h +++ b/driver/sspt/sspt.h @@ -30,6 +30,7 @@ #include "sspt_file.h" #include "sspt_procs.h" #include "sspt_debug.h" +#include "../us_proc_inst.h" #include "../storage.h" @@ -37,7 +38,7 @@ static void print_proc_probes(const struct sspt_procs *procs); -struct sspt_procs *get_file_probes(const inst_us_proc_t *task_inst_info) +static inline struct sspt_procs *get_file_probes(const inst_us_proc_t *task_inst_info) { struct sspt_procs *procs = sspt_procs_create(task_inst_info->m_f_dentry, 0); @@ -52,9 +53,9 @@ struct sspt_procs *get_file_probes(const inst_us_proc_t *task_inst_info) int k, j; us_proc_lib_t *p_libs = &task_inst_info->p_libs[i]; struct dentry *dentry = p_libs->m_f_dentry; - const char *path = p_libs->path; + char *path = p_libs->path; char *name = strrchr(path, '/'); - name = name ? ++name : path; + name = name ? name + 1 : path; for (k = 0; k < p_libs->ips_count; ++k) { struct ip_data pd; @@ -72,7 +73,7 @@ struct sspt_procs *get_file_probes(const inst_us_proc_t *task_inst_info) pd.offset = ip->offset; pd.got_addr = got_addr; pd.pre_handler = ip->jprobe.pre_entry; - pd.jp_handler = ip->jprobe.entry; + pd.jp_handler = (unsigned long) ip->jprobe.entry; pd.rp_handler = ip->retprobe.handler; sspt_procs_add_ip_data(procs, dentry, name, &pd); @@ -96,15 +97,12 @@ enum US_FLAGS { US_DISARM }; -static int register_usprobe(struct task_struct *task, struct us_ip *ip, int atomic); -static int unregister_usprobe(struct task_struct *task, struct us_ip *ip, int atomic, int no_rp2); - -static int register_usprobe_my(struct task_struct *task, struct us_ip *ip) +static inline int register_usprobe_my(struct task_struct *task, struct us_ip *ip) { return register_usprobe(task, ip, 1); } -static int unregister_usprobe_my(struct task_struct *task, struct us_ip *ip, enum US_FLAGS flag) +static inline int unregister_usprobe_my(struct task_struct *task, struct us_ip *ip, enum US_FLAGS flag) { int err = 0; diff --git a/driver/sspt/sspt_debug.h b/driver/sspt/sspt_debug.h index c192785a..1857568c 100644 --- a/driver/sspt/sspt_debug.h +++ b/driver/sspt/sspt_debug.h @@ -25,41 +25,44 @@ * */ -static void print_jprobe(struct jprobe *jp) +static inline void print_jprobe(struct jprobe *jp) { - printk("### JP: entry=%x, pre_entry=%x\n", - jp->entry, jp->pre_entry); + printk("### JP: entry=%lx, pre_entry=%lx\n", + (unsigned long)jp->entry, (unsigned long)jp->pre_entry); } -static void print_retprobe(struct kretprobe *rp) +static inline void print_retprobe(struct kretprobe *rp) { - printk("### RP: handler=%x\n", - rp->handler); + printk("### RP: handler=%lx\n", + (unsigned long)rp->handler); } -static void print_page_probes(const struct sspt_page *page) +static inline void print_page_probes(const struct sspt_page *page) { int i = 0; struct us_ip *ip; - printk("### offset=%x\n", page->offset); + printk("### offset=%lx\n", page->offset); list_for_each_entry(ip, &page->ip_list, list) { - printk("### addr[%2d]=%x, J_addr=%x, R_addr=%x\n", - i, ip->offset, ip->jprobe.kp.addr, ip->retprobe.kp.addr); + printk("### addr[%2d]=%lx, J_addr=%lx, R_addr=%lx\n", + i, (unsigned long)ip->offset, (unsigned long)ip->jprobe.kp.addr, + (unsigned long)ip->retprobe.kp.addr); print_jprobe(&ip->jprobe); print_retprobe(&ip->retprobe); ++i; } } -static void print_file_probes(const struct sspt_file *file) +static inline void print_file_probes(const struct sspt_file *file) { - int i, table_size; + int i; + unsigned long table_size; struct sspt_page *page = NULL; struct hlist_node *node = NULL; struct hlist_head *head = NULL; - static const char *NA = "N/A"; + static unsigned char *NA = "N/A"; + unsigned char *name; if (file == NULL) { printk("### file_p == NULL\n"); @@ -67,9 +70,9 @@ static void print_file_probes(const struct sspt_file *file) } table_size = (1 << file->page_probes_hash_bits); - const char *name = (file->dentry) ? file->dentry->d_iname : NA; + name = (file->dentry) ? file->dentry->d_iname : NA; - printk("### print_file_probes: path=%s, d_iname=%s, table_size=%d, vm_start=%x\n", + printk("### print_file_probes: path=%s, d_iname=%s, table_size=%lu, vm_start=%lx\n", file->name, name, table_size, file->vm_start); for (i = 0; i < table_size; ++i) { @@ -80,7 +83,7 @@ static void print_file_probes(const struct sspt_file *file) } } -static void print_proc_probes(const struct sspt_procs *procs) +static inline void print_proc_probes(const struct sspt_procs *procs) { struct sspt_file *file; @@ -91,7 +94,7 @@ static void print_proc_probes(const struct sspt_procs *procs) printk("### print_proc_probes\n"); } -void print_inst_us_proc(const inst_us_proc_t *task_inst_info) +static inline void print_inst_us_proc(const inst_us_proc_t *task_inst_info) { int i; int cnt = task_inst_info->libs_count; @@ -108,9 +111,9 @@ void print_inst_us_proc(const inst_us_proc_t *task_inst_info) printk("### path=%s, cnt_j=%d\n", path, cnt_j); for (j = 0; j < cnt_j; ++j) { - struct us_ip *ips = &lib->p_ips[j]; + us_proc_ip_t *ips = &lib->p_ips[j]; unsigned long offset = ips->offset; - printk("### offset=%x\n", offset); + printk("### offset=%lx\n", offset); } } printk("### BUNDLE PRINT END ###\n"); diff --git a/driver/sspt/sspt_file.c b/driver/sspt/sspt_file.c index 4fee7e6c..08697d57 100644 --- a/driver/sspt/sspt_file.c +++ b/driver/sspt/sspt_file.c @@ -36,7 +36,7 @@ static int calculation_hash_bits(int cnt) return bits; } -struct sspt_file *sspt_file_create(const char *name, struct dentry *dentry, int page_cnt) +struct sspt_file *sspt_file_create(char *name, struct dentry *dentry, int page_cnt) { struct sspt_file *obj = kmalloc(sizeof(*obj), GFP_ATOMIC); @@ -82,7 +82,8 @@ void sspt_file_free(struct sspt_file *file) static void sspt_add_page(struct sspt_file *file, struct sspt_page *page) { - hlist_add_head(&page->hlist, &file->page_probes_table[hash_ptr(page->offset, file->page_probes_hash_bits)]); + hlist_add_head(&page->hlist, &file->page_probes_table[hash_ptr((void *)page->offset, + file->page_probes_hash_bits)]); } struct sspt_file *sspt_file_copy(const struct sspt_file *file) @@ -135,7 +136,7 @@ static struct sspt_page *sspt_find_page(struct sspt_file *file, unsigned long of struct hlist_head *head; struct sspt_page *page; - head = &file->page_probes_table[hash_ptr(offset, file->page_probes_hash_bits)]; + head = &file->page_probes_table[hash_ptr((void *)offset, file->page_probes_hash_bits)]; hlist_for_each_entry(page, node, head, hlist) { if (page->offset == offset) { return page; @@ -163,7 +164,7 @@ struct sspt_page *sspt_find_page_mapped(struct sspt_file *file, unsigned long pa if (file->vm_start > page || file->vm_end < page) { // TODO: or panic?! - printk("ERROR: file_p[vm_start..vm_end] <> page: file_p[vm_start=%x, vm_end=%x, path=%s, d_iname=%s] page=%x\n", + printk("ERROR: file_p[vm_start..vm_end] <> page: file_p[vm_start=%lx, vm_end=%lx, path=%s, d_iname=%s] page=%lx\n", file->vm_start, file->vm_end, file->name, file->dentry->d_iname, page); return NULL; } diff --git a/driver/sspt/sspt_file.h b/driver/sspt/sspt_file.h index bb1fca67..3d4d2e49 100644 --- a/driver/sspt/sspt_file.h +++ b/driver/sspt/sspt_file.h @@ -42,7 +42,7 @@ struct sspt_file { }; -struct sspt_file *sspt_file_create(const char *name, struct dentry *dentry, int page_cnt); +struct sspt_file *sspt_file_create(char *name, struct dentry *dentry, int page_cnt); struct sspt_file *sspt_file_copy(const struct sspt_file *file); void sspt_file_free(struct sspt_file *file); diff --git a/driver/sspt/sspt_page.c b/driver/sspt/sspt_page.c index 62acabfe..388b03de 100644 --- a/driver/sspt/sspt_page.c +++ b/driver/sspt/sspt_page.c @@ -107,6 +107,6 @@ void sspt_set_all_ip_addr(struct sspt_page *page, const struct sspt_file *file) list_for_each_entry(ip, &page->ip_list, list) { addr = file->vm_start + page->offset + ip->offset; - ip->retprobe.kp.addr = ip->jprobe.kp.addr = addr; + ip->retprobe.kp.addr = ip->jprobe.kp.addr = (kprobe_opcode_t *)addr; } } diff --git a/driver/sspt/sspt_page.h b/driver/sspt/sspt_page.h index 5d74e5fe..26dabc54 100644 --- a/driver/sspt/sspt_page.h +++ b/driver/sspt/sspt_page.h @@ -50,7 +50,7 @@ struct us_ip *sspt_find_ip(struct sspt_page *page, unsigned long offset); static inline void sspt_page_assert_install(const struct sspt_page *page) { if (page->install != 0) { - panic("already installed page %x\n", page->offset); + panic("already installed page %lx\n", page->offset); } } diff --git a/driver/sspt/sspt_procs.c b/driver/sspt/sspt_procs.c index fb585f96..1b8e304c 100644 --- a/driver/sspt/sspt_procs.c +++ b/driver/sspt/sspt_procs.c @@ -84,7 +84,7 @@ static void sspt_procs_add_file(struct sspt_procs *procs, struct sspt_file *file } struct sspt_file *sspt_procs_find_file_or_new(struct sspt_procs *procs, - struct dentry *dentry, const char *name) + struct dentry *dentry, char *name) { struct sspt_file *file; @@ -101,7 +101,7 @@ struct sspt_file *sspt_procs_find_file_or_new(struct sspt_procs *procs, } void sspt_procs_add_ip_data(struct sspt_procs *procs, struct dentry* dentry, - const char *name, struct ip_data *ip_d) + char *name, struct ip_data *ip_d) { struct sspt_file *file = sspt_procs_find_file_or_new(procs, dentry, name); sspt_file_add_ip(file, ip_d); diff --git a/driver/sspt/sspt_procs.h b/driver/sspt/sspt_procs.h index aec87d1e..5cd1015a 100644 --- a/driver/sspt/sspt_procs.h +++ b/driver/sspt/sspt_procs.h @@ -42,9 +42,9 @@ void sspt_procs_free(struct sspt_procs *procs); void sspt_procs_free_all(void); void sspt_procs_add_ip_data(struct sspt_procs *procs, struct dentry* dentry, - const char *name, struct ip_data *ip_d); + char *name, struct ip_data *ip_d); struct sspt_file *sspt_procs_find_file(struct sspt_procs *procs, struct dentry *dentry); struct sspt_file *sspt_procs_find_file_or_new(struct sspt_procs *procs, - struct dentry *dentry, const char *name); + struct dentry *dentry, char *name); #endif /* __SSPT_PROC__ */ diff --git a/driver/storage.c b/driver/storage.c index 43fdd89c..5f770efb 100644 --- a/driver/storage.c +++ b/driver/storage.c @@ -26,6 +26,8 @@ #include "storage.h" #include "handlers_core.h" #include "CProfile.h" +#include "sspt/sspt.h" +#include "sspt/sspt_debug.h" #define after_buffer ec_info.buffer_size @@ -42,7 +44,7 @@ struct cond cond_list; int paused = 0; /* a state after a stop condition (events are not collected) */ struct timeval last_attach_time = {0, 0}; -struct dbi_modules_handlers dbi_mh; +static struct dbi_modules_handlers dbi_mh; struct dbi_modules_handlers *get_dbi_modules_handlers(void) { @@ -81,7 +83,7 @@ inline unsigned long find_dbi_rp_handler(unsigned long p_addr, struct dbi_module /** * Search of handler in global list of modules for defined probe */ -void dbi_find_and_set_handler_for_probe(kernel_probe_t *p) +static void dbi_find_and_set_handler_for_probe(kernel_probe_t *p) { unsigned long jp_handler_addr, rp_handler_addr; struct dbi_modules_handlers_info *local_mhi; @@ -94,7 +96,7 @@ void dbi_find_and_set_handler_for_probe(kernel_probe_t *p) (local_mhi->dbi_module)->name, p->addr); // XXX: absent code for pre_handlers because we suppose that they are not used if ((jp_handler_addr = find_dbi_jp_handler(p->addr, local_mhi)) != 0) { - if (p->jprobe.entry != 0) { + if (p->jprobe.entry != NULL) { printk("Skipping jp_handler for %s module (address %0lX)\n", (local_mhi->dbi_module)->name, p->addr); } @@ -114,7 +116,7 @@ void dbi_find_and_set_handler_for_probe(kernel_probe_t *p) } } if ((rp_handler_addr = find_dbi_rp_handler(p->addr, local_mhi)) != 0) { - if (p->retprobe.handler != 0) { + if (p->retprobe.handler != NULL) { printk("Skipping kretprobe_handler for %s module (address %0lX)\n", (local_mhi->dbi_module)->name, p->addr); } @@ -135,17 +137,17 @@ void dbi_find_and_set_handler_for_probe(kernel_probe_t *p) } } // not found pre_handler - set default (always true for now since pre_handlers not used) - if (p->jprobe.pre_entry == 0) { + if (p->jprobe.pre_entry == NULL) { p->jprobe.pre_entry = (kprobe_pre_entry_handler_t) def_jprobe_event_pre_handler; printk("Set default pre_handler (address %0lX)\n", p->addr); } // not found jp_handler - set default - if (p->jprobe.entry == 0) { + if (p->jprobe.entry == NULL) { p->jprobe.entry = (kprobe_opcode_t *) def_jprobe_event_handler; printk("Set default jp_handler (address %0lX)\n", p->addr); } // not found kretprobe_handler - set default - if (p->retprobe.handler == 0) { + if (p->retprobe.handler == NULL) { p->retprobe.handler = (kretprobe_handler_t) def_retprobe_event_handler; printk("Set default rp_handler (address %0lX)\n", p->addr); } @@ -163,7 +165,7 @@ int dbi_register_handlers_module(struct dbi_modules_handlers_info *dbi_mhi) for (i = 0; i < nr_handlers; ++i) { dbi_mhi->dbi_handlers[i].func_addr = swap_ksyms(dbi_mhi->dbi_handlers[i].func_name); - printk("[0x%08x]-%s\n", dbi_mhi->dbi_handlers[i].func_addr, dbi_mhi->dbi_handlers[i].func_name); + printk("[0x%08lx]-%s\n", dbi_mhi->dbi_handlers[i].func_addr, dbi_mhi->dbi_handlers[i].func_name); } spin_lock_irqsave(&dbi_mh.lock, dbi_flags); @@ -240,9 +242,12 @@ static inst_us_proc_t *get_uprobes(void) EXPORT_SYMBOL_GPL(us_proc_info); EXPORT_SYMBOL_GPL(dex_proc_info); typedef void *(*get_my_uprobes_info_t)(void); -int (*mec_post_event)(char *data, unsigned long len) = NULL; +#ifdef MEMORY_CHECKER +typedef int (*mec_post_event_pointer)(char *data, unsigned long len); +static mec_post_event_pointer mec_post_event = NULL; +#endif -unsigned copy_into_cyclic_buffer (char *buffer, unsigned dst_offset, char *src, unsigned size) +static unsigned copy_into_cyclic_buffer (char *buffer, unsigned dst_offset, char *src, unsigned size) { unsigned nOffset = dst_offset; char* pSource = src; @@ -251,16 +256,7 @@ unsigned copy_into_cyclic_buffer (char *buffer, unsigned dst_offset, char *src, return nOffset; } -unsigned copy_from_cyclic_buffer (char *dst, char *buffer, unsigned src_offset, unsigned size) -{ - unsigned nOffset = src_offset; - char* pDestination = dst; - while (size--) - *pDestination++ = buffer[nOffset++]; - return nOffset; -} - -int CheckBufferSize (unsigned int nSize) +static int CheckBufferSize (unsigned int nSize) { if (nSize < EC_BUFFER_SIZE_MIN) { EPRINTF("Too small buffer size! [Size=%u KB]", nSize / 1024); @@ -273,13 +269,13 @@ int CheckBufferSize (unsigned int nSize) return 0; } -int AllocateSingleBuffer(unsigned int nSize) +static int AllocateSingleBuffer(unsigned int nSize) { unsigned long spinlock_flags = 0L; p_buffer = vmalloc_user(nSize); if(!p_buffer) { - EPRINTF("Memory allocation error! [Size=%lu KB]", nSize / 1024); + EPRINTF("Memory allocation error! [Size=%u KB]", nSize / 1024); return -1; } @@ -290,7 +286,7 @@ int AllocateSingleBuffer(unsigned int nSize) return 0; } -void FreeSingleBuffer (void) +static void FreeSingleBuffer (void) { VFREE_USER(p_buffer, ec_info.buffer_size); CleanECInfo(); @@ -298,7 +294,8 @@ void FreeSingleBuffer (void) ////////////////////////////////////////////////////////////////////////////////////////////////// -int EnableContinuousRetrieval() { +int EnableContinuousRetrieval(void) +{ unsigned long spinlock_flags = 0L; spin_lock_irqsave (&ec_spinlock, spinlock_flags); @@ -308,7 +305,8 @@ int EnableContinuousRetrieval() { return 0; } -int DisableContinuousRetrieval() { +int DisableContinuousRetrieval(void) +{ unsigned long spinlock_flags = 0L; spin_lock_irqsave (&ec_spinlock, spinlock_flags); @@ -320,11 +318,11 @@ int DisableContinuousRetrieval() { ////////////////////////////////////////////////////////////////////////////////////////////////// -int InitializeBuffer(unsigned int nSize) { +static int InitializeBuffer(unsigned int nSize) { return AllocateSingleBuffer(nSize); } -int UninitializeBuffer(void) { +static int UninitializeBuffer(void) { FreeSingleBuffer(); return 0; } @@ -365,7 +363,7 @@ int SetPid(unsigned int pid) return 0; } -void ResetSingleBuffer(void) { +static void ResetSingleBuffer(void) { } int ResetBuffer(void) { @@ -389,7 +387,7 @@ int ResetBuffer(void) { return 0; } -int WriteEventIntoSingleBuffer(char* pEvent, unsigned long nEventSize) { +static int WriteEventIntoSingleBuffer(char* pEvent, unsigned long nEventSize) { unsigned int unused_space; if(!p_buffer) { @@ -443,7 +441,7 @@ int WriteEventIntoSingleBuffer(char* pEvent, unsigned long nEventSize) { return 0; } -int WriteEventIntoBuffer(char* pEvent, unsigned long nEventSize) { +static int WriteEventIntoBuffer(char* pEvent, unsigned long nEventSize) { /*unsigned long i; for(i = 0; i < nEventSize; i++) @@ -522,7 +520,7 @@ static int addr_cmp (const void *a, const void *b) return *(unsigned long *) a > *(unsigned long *) b ? -1 : 1; } -char *find_lib_path(const char *lib_name) +static char *find_lib_path(const char *lib_name) { char *p = deps + sizeof(size_t); char *match; @@ -557,7 +555,7 @@ void unlink_bundle(void) struct list_head *pos; //, *tmp; path = us_proc_info.path; - us_proc_info.path = 0; + us_proc_info.path = NULL; // first make sure "d_lib" is not used any more and only // then release storage @@ -602,7 +600,7 @@ void unlink_bundle(void) us_proc_info.is_plt = 0; } kfree ((void *) us_proc_info.p_libs); - us_proc_info.p_libs = 0; + us_proc_info.p_libs = NULL; } /* if (path) */ /* { */ @@ -613,12 +611,9 @@ void unlink_bundle(void) us_proc_info.tgid = 0; } -struct sspt_procs *get_file_probes(const inst_us_proc_t *task_inst_info); -void print_inst_us_proc(const inst_us_proc_t *task_inst_info); - extern struct dentry *dentry_by_path(const char *path); -int link_bundle() +int link_bundle(void) { inst_us_proc_t *my_uprobes_info = get_uprobes(); char *p = bundle; /* read pointer for bundle */ @@ -626,7 +621,6 @@ int link_bundle() int i, j, l, k; int len; us_proc_lib_t *d_lib, *pd_lib; - dex_proc_ip_t *dex_proc; ioctl_usr_space_lib_t s_lib; ioctl_usr_space_vtp_t *s_vtp; us_proc_vtp_t *mvtp; @@ -1100,7 +1094,7 @@ void storage_down (void) EPRINTF ("ec_info.lost_events_count=%d", ec_info.lost_events_count); } -u_int32_t get_probe_func_addr(const char *fmt, va_list args) +static u_int32_t get_probe_func_addr(const char *fmt, va_list args) { if (fmt[0] != 'p') return 0; @@ -1361,7 +1355,7 @@ int put_us_event (char *data, unsigned long len) else { // FIXME: 'mec_post_event' - not found - mec_post_event = swap_ksyms("mec_post_event"); + mec_post_event = (mec_post_event_pointer) swap_ksyms("mec_post_event"); if(mec_post_event == NULL) { EPRINTF ("Failed to find function 'mec_post_event' from mec_handlers.ko. Memory Error Checker will work incorrectly."); @@ -1448,64 +1442,6 @@ int put_us_event (char *data, unsigned long len) return 0; } -int set_predef_uprobes (ioctl_predef_uprobes_info_t *data) -{ - int i, k, size = 0, probe_size, result, j; - char *buf, *sep1, *sep2; - inst_us_proc_t *my_uprobes_info = get_uprobes(); - - for(j = 0; j < data->probes_count; j++) - { - probe_size = strlen_user(data->p_probes+size); - buf = kmalloc(probe_size, GFP_KERNEL); - - if(!buf) - { - EPRINTF("failed to alloc mem!"); - return -EFAULT; - } - - result = strncpy_from_user(buf, data->p_probes+size, probe_size); - if (result != (probe_size-1)) - { - EPRINTF("failed to copy from user!"); - kfree(buf); - return -EFAULT; - } - //DPRINTF("%s", buf); - sep1 = strchr(buf, ':'); - if(!sep1) - { - EPRINTF("skipping invalid predefined uprobe string '%s'!", buf); - kfree(buf); - size += probe_size; - continue; - } - sep2 = strchr(sep1+1, ':'); - if(!sep2 || (sep2 == sep1) || (sep2+2 == buf+probe_size)) - { - EPRINTF("skipping invalid predefined uprobe string '%s'!", buf); - kfree(buf); - size += probe_size; - continue; - } - for(i = 0; i < my_uprobes_info->libs_count; i++) - { - if(strncmp(buf, my_uprobes_info->p_libs[i].path, sep1-buf) != 0) - continue; - for(k = 0; k < my_uprobes_info->p_libs[i].ips_count; k++) - { - if(strncmp(sep1+1, my_uprobes_info->p_libs[i].p_ips[k].name, sep2-sep1-1) != 0) - continue; - my_uprobes_info->p_libs[i].p_ips[k].offset = simple_strtoul(sep2+1, NULL, 16); - } - } - - kfree(buf); - size += probe_size; - } - return 0; -} int get_predef_uprobes_size(int *size) { @@ -1535,7 +1471,7 @@ int get_predef_uprobes(ioctl_predef_uprobes_info_t *udata) inst_us_proc_t *my_uprobes_info = get_uprobes(); // get addr of array - if (copy_from_user ((void *)&data, udata, sizeof (data))) + if (copy_from_user ((void *)&data, (void __user *) udata, sizeof (data))) { EPRINTF("failed to copy from user!"); return -EFAULT; @@ -1548,7 +1484,8 @@ int get_predef_uprobes(ioctl_predef_uprobes_info_t *udata) for(k = 0; k < my_uprobes_info->p_libs[i].ips_count; k++) { // libname - result = copy_to_user ((void *)(data.p_probes+size), my_uprobes_info->p_libs[i].path, lib_size); + result = copy_to_user ((void __user *)(data.p_probes+size), + (void *) my_uprobes_info->p_libs[i].path, lib_size); if (result) { EPRINTF("failed to copy to user!"); @@ -1556,7 +1493,7 @@ int get_predef_uprobes(ioctl_predef_uprobes_info_t *udata) } size += lib_size; // ":" - result = copy_to_user ((void *)(data.p_probes+size), sep, 1); + result = copy_to_user ((void __user *)(data.p_probes+size), sep, 1); if (result) { EPRINTF("failed to copy to user!"); @@ -1566,7 +1503,7 @@ int get_predef_uprobes(ioctl_predef_uprobes_info_t *udata) // probename //DPRINTF("'%s'", my_uprobes_info->p_libs[i].p_ips[k].name); func_size = strlen(my_uprobes_info->p_libs[i].p_ips[k].name); - result = copy_to_user ((void *)(data.p_probes+size), my_uprobes_info->p_libs[i].p_ips[k].name, func_size); + result = copy_to_user ((void __user *)(data.p_probes+size), my_uprobes_info->p_libs[i].p_ips[k].name, func_size); if (result) { EPRINTF("failed to copy to user!"); @@ -1574,7 +1511,7 @@ int get_predef_uprobes(ioctl_predef_uprobes_info_t *udata) } size += func_size; // ":\0" - result = copy_to_user ((void *)(data.p_probes+size), sep, 2); + result = copy_to_user ((void __user *)(data.p_probes+size), sep, 2); if (result) { EPRINTF("failed to copy to user!"); @@ -1586,7 +1523,7 @@ int get_predef_uprobes(ioctl_predef_uprobes_info_t *udata) } // set probes_count - result = copy_to_user ((void *)&(udata->probes_count), &count, sizeof(count)); + result = copy_to_user ((void __user *)&(udata->probes_count), &count, sizeof(count)); if (result) { EPRINTF("failed to copy to user!"); diff --git a/driver/us_proc_inst.c b/driver/us_proc_inst.c index 7d70ba1a..b0ae91e7 100644 --- a/driver/us_proc_inst.c +++ b/driver/us_proc_inst.c @@ -47,9 +47,6 @@ mmput(mm); \ } -DEFINE_PER_CPU (us_proc_vtp_t *, gpVtp) = NULL; -DEFINE_PER_CPU (struct pt_regs *, gpCurVtpRegs) = NULL; - #if defined(CONFIG_MIPS) # define ARCH_REG_VAL(regs, idx) regs->regs[idx] #elif defined(CONFIG_ARM) @@ -63,17 +60,11 @@ unsigned long ujprobe_event_pre_handler (struct us_ip *ip, struct pt_regs *regs) void ujprobe_event_handler (unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5, unsigned long arg6); int uretprobe_event_handler (struct kretprobe_instance *probe, struct pt_regs *regs, struct us_ip *ip); -static int register_usprobe(struct task_struct *task, struct us_ip *ip, int atomic); -static int unregister_usprobe(struct task_struct *task, struct us_ip *ip, int atomic, int no_rp2); int us_proc_probes; LIST_HEAD(proc_probes_list); -#ifdef SLP_APP -struct dentry *launchpad_daemon_dentry = NULL; -EXPORT_SYMBOL_GPL(launchpad_daemon_dentry); -#endif /* SLP_APP */ #ifdef ANDROID_APP unsigned long android_app_vma_start = 0; @@ -81,6 +72,10 @@ unsigned long android_app_vma_end = 0; struct dentry *app_process_dentry = NULL; #endif /* ANDROID_APP */ +#ifdef SLP_APP +static struct dentry *launchpad_daemon_dentry = NULL; +EXPORT_SYMBOL_GPL(launchpad_daemon_dentry); +#endif /* SLP_APP */ #define print_event(fmt, args...) \ { \ @@ -100,7 +95,7 @@ static inline int is_us_instrumentation(void) return !!us_proc_info.path; } -struct sspt_procs *get_proc_probes_by_task(struct task_struct *task) +static struct sspt_procs *get_proc_probes_by_task(struct task_struct *task) { struct sspt_procs *procs, *tmp; @@ -122,12 +117,12 @@ struct sspt_procs *get_proc_probes_by_task(struct task_struct *task) return NULL; } -void add_proc_probes(struct task_struct *task, struct sspt_procs *procs) +static void add_proc_probes(struct task_struct *task, struct sspt_procs *procs) { list_add_tail(&procs->list, &proc_probes_list); } -struct sspt_procs *get_proc_probes_by_task_or_new(struct task_struct *task) +static struct sspt_procs *get_proc_probes_by_task_or_new(struct task_struct *task) { struct sspt_procs *procs = get_proc_probes_by_task(task); if (procs == NULL) { @@ -231,7 +226,7 @@ static int find_task_by_path (const char *path, struct task_struct **p_task, str struct mm_struct *mm; struct dentry *dentry = dentry_by_path(path); - *p_task = 0; + *p_task = NULL; /* find corresponding dir entry, this is also check for valid path */ // TODO: test - try to instrument process with non-existing path @@ -296,218 +291,6 @@ static int find_task_by_path (const char *path, struct task_struct **p_task, str return 0; } - -static void us_vtp_event_pre_handler (us_proc_vtp_t * vtp, struct pt_regs *regs) -{ - __get_cpu_var(gpVtp) = vtp; - __get_cpu_var(gpCurVtpRegs) = regs; -} - -static void us_vtp_event_handler (unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5, unsigned long arg6) -{ - us_proc_vtp_t *vtp = __get_cpu_var(gpVtp); -#if !defined(CONFIG_X86) - struct pt_regs *regs = __get_cpu_var(gpCurVtpRegs); -#endif - char fmt[4]; - unsigned long vaddr; - long ival; - char cval, *sval; - us_proc_vtp_data_t *vtp_data; -unsigned long ll; - fmt[0] = 'p'; - fmt[3] = 0; - fmt[2] = 's'; - - list_for_each_entry_rcu (vtp_data, &vtp->list, list) { - // DPRINTF ("[%d]proc %s(%d): %lx", nCount++, current->comm, current->pid, vtp->addr); - fmt[1] = vtp_data->type; - if (vtp_data->reg == -1) - vaddr = vtp_data->off; - else - vaddr = ARCH_REG_VAL (regs, vtp_data->reg) + vtp_data->off; - // DPRINTF ("VTP type '%c'", vtp_data->type); - switch (vtp_data->type) - { - case 'd': - case 'x': - case 'p': - if (read_proc_vm_atomic (current, vaddr, &ival, sizeof (ival)) < sizeof (ival)) - EPRINTF ("failed to read vm of proc %s/%u addr %lu!", current->comm, current->pid, vaddr); - else - pack_event_info (VTP_PROBE_ID, RECORD_ENTRY, fmt, vtp->jprobe.kp.addr, ival, vtp_data->name); - break; - case 'f': - if (read_proc_vm_atomic (current, vaddr, &ival, sizeof (ival)) < sizeof (ival)) - EPRINTF ("failed to read vm of proc %s/%u addr %lu!", current->comm, current->pid, vaddr); - else - pack_event_info (VTP_PROBE_ID, RECORD_ENTRY, fmt, vtp->jprobe.kp.addr, ival, vtp_data->name); - break; - case 'c': - if (read_proc_vm_atomic (current, vaddr, &cval, sizeof (cval)) < sizeof (cval)) - EPRINTF ("failed to read vm of proc %s/%u addr %lu!", current->comm, current->pid, vaddr); - else - pack_event_info (VTP_PROBE_ID, RECORD_ENTRY, fmt, vtp->jprobe.kp.addr, cval, vtp_data->name); - break; - case 's': - if (current->active_mm) { - struct page *page; - struct vm_area_struct *vma; - void *maddr; - int len; - if (get_user_pages_atomic (current, current->active_mm, vaddr, 1, 0, 1, &page, &vma) <= 0) { - EPRINTF ("get_user_pages_atomic failed for proc %s/%u addr %lu!", current->comm, current->pid, vaddr); - break; - } - maddr = kmap_atomic (page, KM_USER0); - len = strlen (maddr + (vaddr & ~PAGE_MASK)); - sval = kmalloc (len + 1, GFP_KERNEL); - if (!sval) - EPRINTF ("failed to alloc memory for string in proc %s/%u addr %lu!", current->comm, current->pid, vaddr); - else { - copy_from_user_page (vma, page, vaddr, sval, maddr + (vaddr & ~PAGE_MASK), len + 1); - pack_event_info (VTP_PROBE_ID, RECORD_ENTRY, fmt, vtp->jprobe.kp.addr, sval, vtp_data->name); - kfree (sval); - } - kunmap_atomic (maddr, KM_USER0); - page_cache_release (page); - } - else - EPRINTF ("task %s/%u has no mm!", current->comm, current->pid); - break; - default: - EPRINTF ("unknown variable type '%c'", vtp_data->type); - } - } - dbi_uprobe_return (); -} - -static int install_mapped_ips (struct task_struct *task, inst_us_proc_t* task_inst_info, int atomic) -{ - struct vm_area_struct *vma; - int i, k, err; - unsigned long addr; - unsigned int old_ips_count, old_vtps_count; - struct task_struct *t; - struct mm_struct *mm; - - mm = atomic ? task->active_mm : get_task_mm (task); - if (!mm) { - return task_inst_info->unres_ips_count + task_inst_info->unres_vtps_count; - } - 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); - vma = mm->mmap; - while (vma) { - // skip non-text section -#ifndef __ANDROID - if (vma->vm_pgoff != 0 || !(vma->vm_flags & VM_EXEC) || !vma->vm_file || (vma->vm_flags & VM_ACCOUNT) || - !(vma->vm_flags & (VM_WRITE | VM_MAYWRITE)) || - !(vma->vm_flags & (VM_READ | VM_MAYREAD))) { -#else // __ANDROID - if (vma->vm_pgoff != 0 || !(vma->vm_flags & VM_EXEC) || !vma->vm_file) { -#endif // __ANDROID - vma = vma->vm_next; - continue; - } - /** - * After process was forked, some time it inherits parent process environment. - * We need to renew instrumentation when we detect that process gets own environment. - */ - 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) { -// 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 (!task_inst_info->p_libs[i].loaded) { -// DPRINTF("!VM_EXECUTABLE && !loaded"); - char *p; - int app_flag = (vma->vm_file->f_dentry == task_inst_info->m_f_dentry); - 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 - p = strrchr(task_inst_info->p_libs[i].path, '/'); - if(!p) - p = task_inst_info->p_libs[i].path; - else - p++; - task_inst_info->p_libs[i].loaded = 1; - task_inst_info->p_libs[i].vma_start = vma->vm_start; - task_inst_info->p_libs[i].vma_end = vma->vm_end; - task_inst_info->p_libs[i].vma_flag = vma->vm_flags; - pack_event_info (DYN_LIB_PROBE_ID, RECORD_ENTRY, "dspdd", - task->tgid, p, vma->vm_start, vma->vm_end-vma->vm_start, app_flag); - } - 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; - addr += vma->vm_start; - 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; - task_inst_info->unres_ips_count--; - err = register_usprobe(task, &task_inst_info->p_libs[i].p_ips[k], atomic); - 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++) { - 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)) { - 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; - task_inst_info->p_libs[i].p_vtps[k].jprobe.pre_entry = (kprobe_pre_entry_handler_t) us_vtp_event_pre_handler; - task_inst_info->p_libs[i].p_vtps[k].jprobe.priv_arg = &task_inst_info->p_libs[i].p_vtps[k]; - task_inst_info->p_libs[i].p_vtps[k].installed = 1; - task_inst_info->unres_vtps_count--; - err = dbi_register_ujprobe(task, &task_inst_info->p_libs[i].p_vtps[k].jprobe, atomic); - 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); - } - } - } - } - } - } - - vma = vma->vm_next; - } - - if (!atomic) { - up_read (&mm->mmap_sem); - mmput (mm); - } - return task_inst_info->unres_ips_count + task_inst_info->unres_vtps_count; -} - static void set_mapping_file(struct sspt_file *file, const struct sspt_procs *procs, const struct task_struct *task, @@ -575,45 +358,6 @@ int install_otg_ip(unsigned long addr, } EXPORT_SYMBOL_GPL(install_otg_ip); - -static int uninstall_mapped_ips (struct task_struct *task, inst_us_proc_t* task_inst_info, int atomic) -{ - int i, k, err; - - for (i = 0; i < task_inst_info->libs_count; i++) - { - DPRINTF ("clear lib %s.", task_inst_info->p_libs[i].path); - for (k = 0; k < task_inst_info->p_libs[i].ips_count; k++) - { - if (task_inst_info->p_libs[i].p_ips[k].installed) - { - DPRINTF ("remove IP at %p.", task_inst_info->p_libs[i].p_ips[k].jprobe.kp.addr); - err = unregister_usprobe (task, &task_inst_info->p_libs[i].p_ips[k], atomic, 0); - if (err != 0) - { - EPRINTF ("failed to uninstall IP at %p. Error %d!", task_inst_info->p_libs[i].p_ips[k].jprobe.kp.addr, err); - continue; - } - task_inst_info->unres_ips_count++; - } - } - for (k = 0; k < task_inst_info->p_libs[i].vtps_count; k++) - { - if (task_inst_info->p_libs[i].p_vtps[k].installed) - { - dbi_unregister_ujprobe (task, &task_inst_info->p_libs[i].p_vtps[k].jprobe, atomic); - task_inst_info->unres_vtps_count++; - task_inst_info->p_libs[i].p_vtps[k].installed = 0; - } - } - task_inst_info->p_libs[i].loaded = 0; - } - - DPRINTF ("Ures IPs %d.", task_inst_info->unres_ips_count); - DPRINTF ("Ures VTPs %d.", task_inst_info->unres_vtps_count); - return 0; -} - static int uninstall_kernel_probe (unsigned long addr, int uflag, int kflag, kernel_probe_t ** pprobe) { kernel_probe_t *probe = NULL; @@ -650,8 +394,7 @@ static int uninstall_us_proc_probes(struct task_struct *task, struct sspt_procs int deinst_usr_space_proc (void) { int iRet = 0, found = 0; - struct task_struct *task = 0; - inst_us_proc_t *task_inst_info = NULL; + struct task_struct *task = NULL; if (!is_us_instrumentation()) { return 0; @@ -772,7 +515,7 @@ static void install_proc_probes(struct task_struct *task, struct sspt_procs *pro int inst_usr_space_proc (void) { int ret, i; - struct task_struct *task = 0; + struct task_struct *task = NULL; if (!is_us_instrumentation()) { return 0; @@ -881,8 +624,6 @@ int inst_usr_space_proc (void) #include "../../tools/gpmu/probes/entry_data.h" -extern storage_arg_t sa_dpf; - void do_page_fault_j_pre_code(unsigned long addr, unsigned int fsr, struct pt_regs *regs) { struct task_struct *task = current->group_leader; @@ -901,8 +642,6 @@ EXPORT_SYMBOL_GPL(do_page_fault_j_pre_code); unsigned long imi_sum_time = 0; unsigned long imi_sum_hit = 0; -EXPORT_SYMBOL_GPL (imi_sum_time); -EXPORT_SYMBOL_GPL (imi_sum_hit); static void set_mapping_file(struct sspt_file *file, const struct sspt_procs *procs, @@ -923,7 +662,7 @@ void print_vma(struct mm_struct *mm); static int register_us_page_probe(struct sspt_page *page, const struct sspt_file *file, - const struct task_struct *task) + struct task_struct *task) { int err = 0; struct us_ip *ip; @@ -931,10 +670,10 @@ static int register_us_page_probe(struct sspt_page *page, spin_lock(&page->lock); if (sspt_page_is_install(page)) { - printk("page %x in %s task[tgid=%u, pid=%u] already installed\n", + printk("page %lx in %s task[tgid=%u, pid=%u] already installed\n", page->offset, file->dentry->d_iname, task->tgid, task->pid); print_vma(task->mm); - return 0; + goto unlock; } sspt_page_assert_install(page); @@ -944,18 +683,19 @@ static int register_us_page_probe(struct sspt_page *page, err = register_usprobe_my(task, ip); if (err != 0) { //TODO: ERROR - return err; + goto unlock; } } sspt_page_installed(page); +unlock: spin_unlock(&page->lock); - return 0; + return err; } -static int unregister_us_page_probe(const struct task_struct *task, +static int unregister_us_page_probe(struct task_struct *task, struct sspt_page *page, enum US_FLAGS flag) { int err = 0; @@ -996,7 +736,7 @@ static void install_page_probes(unsigned long page_addr, struct task_struct *tas struct dentry *dentry = vma->vm_file->f_dentry; struct sspt_file *file = sspt_procs_find_file(procs, dentry); if (file) { - struct page_probes *page; + struct sspt_page *page; if (!file->loaded) { set_mapping_file(file, procs, task, vma); file->loaded = 1; @@ -1103,7 +843,7 @@ static int unregister_us_file_probes(struct task_struct *task, struct sspt_file static int uninstall_us_proc_probes(struct task_struct *task, struct sspt_procs *procs, enum US_FLAGS flag) { - int err; + int err = 0; struct sspt_file *file; list_for_each_entry_rcu(file, &procs->file_list, list) { @@ -1117,7 +857,7 @@ static int uninstall_us_proc_probes(struct task_struct *task, struct sspt_procs return err; } -static pid_t find_proc_by_task(const struct task_struct *task, const struct dentry *dentry) +static pid_t find_proc_by_task(const struct task_struct *task, struct dentry *dentry) { struct vm_area_struct *vma; struct mm_struct *mm = task->active_mm; @@ -1150,7 +890,6 @@ void do_page_fault_ret_pre_code (void) { struct task_struct *task = current->group_leader; struct mm_struct *mm = task->mm; - struct vm_area_struct *vma = 0; struct sspt_procs *procs = NULL; /* * Because process threads have same address space @@ -1229,11 +968,6 @@ void do_exit_probe_pre_code (void) } EXPORT_SYMBOL_GPL(do_exit_probe_pre_code); -int check_vma_area(struct vm_area_struct *vma, unsigned long start, unsigned long end) -{ - return (vma->vm_start >= start && vma->vm_end <= end); -} - void print_vma(struct mm_struct *mm) { struct vm_area_struct *vma; @@ -1244,9 +978,9 @@ void print_vma(struct mm_struct *mm) char *x = vma->vm_flags & VM_EXEC ? "x" : "-"; char *r = vma->vm_flags & VM_READ ? "r" : "-"; char *w = vma->vm_flags & VM_WRITE ? "w" : "-"; - char *name = vma->vm_file ? vma->vm_file->f_dentry->d_iname : "N/A"; + char *name = vma->vm_file ? (char *)vma->vm_file->f_dentry->d_iname : "N/A"; - printk("### [%8x..%8x] %s%s%s pgoff=\'%8u\' %s\n", + printk("### [%8lx..%8lx] %s%s%s pgoff=\'%8lu\' %s\n", vma->vm_start, vma->vm_end, x, r, w, vma->vm_pgoff, name); } printk("### print_vma: END\n"); @@ -1256,7 +990,6 @@ static int remove_unmap_probes(struct task_struct *task, struct sspt_procs *proc { struct mm_struct *mm = task->mm; struct vm_area_struct *vma; - unsigned long end, pointer, step; if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE - start) { return -EINVAL; @@ -1318,7 +1051,7 @@ void do_munmap_probe_pre_code(struct mm_struct *mm, unsigned long start, size_t if (procs) { if (remove_unmap_probes(task, procs, start, len)) { - printk("ERROR do_munmap: start=%x, len=%x\n", start, len); + printk("ERROR do_munmap: start=%lx, len=%x\n", start, len); } } } @@ -1382,13 +1115,11 @@ void copy_process_ret_pre_code(struct task_struct *p) rm_uprobes_child(p); } - -DEFINE_PER_CPU(struct us_ip *, gpCurIp) = NULL; +static DEFINE_PER_CPU(struct us_ip *, gpCurIp) = NULL; EXPORT_PER_CPU_SYMBOL_GPL(gpCurIp); -DEFINE_PER_CPU(struct pt_regs *, gpUserRegs) = NULL; +static DEFINE_PER_CPU(struct pt_regs *, gpUserRegs) = NULL; EXPORT_PER_CPU_SYMBOL_GPL(gpUserRegs); - unsigned long ujprobe_event_pre_handler(struct us_ip *ip, struct pt_regs *regs) { __get_cpu_var (gpCurIp) = ip; @@ -1424,7 +1155,7 @@ void ujprobe_event_handler (unsigned long arg1, unsigned long arg2, unsigned lon dbi_uprobe_return (); } -void send_plt(struct us_ip *ip) +static void send_plt(struct us_ip *ip) { unsigned long addr = (unsigned long)ip->jprobe.kp.addr; struct vm_area_struct *vma = find_vma(current->mm, addr); @@ -1437,7 +1168,7 @@ void send_plt(struct us_ip *ip) ip->got_addr + vma->vm_start; if (!read_proc_vm_atomic(current, real_got, &real_addr, sizeof(real_addr))) { - printk("Failed to read got %p at memory address %p!\n", ip->got_addr, real_got); + printk("Failed to read got %lx at memory address %lx!\n", ip->got_addr, real_got); return; } @@ -1445,7 +1176,7 @@ void send_plt(struct us_ip *ip) if (vma && (vma->vm_start <= real_addr) && (vma->vm_end > real_addr)) { name = vma->vm_file ? vma->vm_file->f_dentry->d_iname : NULL; } else { - printk("Failed to get vma, includes %x address\n", real_addr); + printk("Failed to get vma, includes %lx address\n", real_addr); return; } @@ -1482,7 +1213,7 @@ int uretprobe_event_handler(struct kretprobe_instance *probe, struct pt_regs *re return 0; } -static int register_usprobe(struct task_struct *task, struct us_ip *ip, int atomic) +int register_usprobe(struct task_struct *task, struct us_ip *ip, int atomic) { int ret = 0; ip->jprobe.kp.tgid = task->tgid; @@ -1523,7 +1254,7 @@ static int register_usprobe(struct task_struct *task, struct us_ip *ip, int atom return 0; } -static int unregister_usprobe(struct task_struct *task, struct us_ip *ip, int atomic, int not_rp2) +int unregister_usprobe(struct task_struct *task, struct us_ip *ip, int atomic, int not_rp2) { dbi_unregister_ujprobe(task, &ip->jprobe, atomic); diff --git a/driver/us_proc_inst.h b/driver/us_proc_inst.h index 66ed2524..059ee99c 100644 --- a/driver/us_proc_inst.h +++ b/driver/us_proc_inst.h @@ -80,6 +80,14 @@ extern int dump_backtrace(probe_id_t probe_id, struct task_struct *task, /* Gets current function return address */ extern unsigned long get_ret_addr(struct task_struct *task, struct us_ip *ip); +extern unsigned long imi_sum_time; +extern unsigned long imi_sum_hit; + +extern struct list_head proc_probes_list; + +int register_usprobe(struct task_struct *task, struct us_ip *ip, int atomic); +int unregister_usprobe(struct task_struct *task, struct us_ip *ip, int atomic, int no_rp2); + #define user_backtrace(size) \ do { \ us_proc_ip_t *ip = __get_cpu_var(gpCurIp); \ @@ -87,4 +95,10 @@ extern unsigned long get_ret_addr(struct task_struct *task, struct us_ip *ip); dump_backtrace(US_PROBE_ID, current, ip->jprobe.kp.addr, regs, size); \ } while (0) +struct dentry *dentry_by_path(const char *path); +int install_otg_ip(unsigned long addr, + kprobe_pre_entry_handler_t pre_handler, + unsigned long jp_handler, + kretprobe_handler_t rp_handler); + #endif /* !defined(__US_PROC_INST_H__) */ |