summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--driver/Kbuild2
-rw-r--r--driver/sspt/sspt.h7
-rw-r--r--driver/us_def_handler.c97
-rw-r--r--driver/us_def_handler.h21
-rw-r--r--driver/us_proc_inst.c111
5 files changed, 123 insertions, 115 deletions
diff --git a/driver/Kbuild b/driver/Kbuild
index ee9ca4b4..33003e87 100644
--- a/driver/Kbuild
+++ b/driver/Kbuild
@@ -4,4 +4,4 @@ obj-m := swap_driver.o
swap_driver-y := error_storage.o device_driver.o ec.o legacy.o module.o probes.o \
probes_manager.o storage.o us_proc_inst.o helper.o us_slot_manager.o \
sspt/ip.o sspt/sspt_page.o sspt/sspt_file.o sspt/sspt_proc.o \
- filters/filters_core.o filters/filter_by_pach.o
+ filters/filters_core.o filters/filter_by_pach.o us_def_handler.o
diff --git a/driver/sspt/sspt.h b/driver/sspt/sspt.h
index 619d0210..982c6a58 100644
--- a/driver/sspt/sspt.h
+++ b/driver/sspt/sspt.h
@@ -32,6 +32,7 @@
#include "sspt_debug.h"
#include "../us_proc_inst.h"
#include <swap_uprobes.h>
+#include "us_def_handler.h"
#include "../storage.h"
@@ -72,9 +73,9 @@ static inline struct sspt_proc *get_file_probes(const inst_us_proc_t *task_inst_
pd.flag_retprobe = 1;
pd.offset = ip->offset;
pd.got_addr = got_addr;
- pd.pre_handler = ip->jprobe.pre_entry;
- pd.jp_handler = (unsigned long) ip->jprobe.entry;
- pd.rp_handler = ip->retprobe.handler;
+ pd.pre_handler = ip->jprobe.pre_entry ? ip->jprobe.pre_entry : ujprobe_event_pre_handler;
+ pd.jp_handler = (unsigned long) (ip->jprobe.entry ? ip->jprobe.entry : ujprobe_event_handler);
+ pd.rp_handler = ip->retprobe.handler ? ip->retprobe.handler : uretprobe_event_handler;
sspt_proc_add_ip_data(proc, dentry, name, &pd);
}
diff --git a/driver/us_def_handler.c b/driver/us_def_handler.c
new file mode 100644
index 00000000..9af5ed0b
--- /dev/null
+++ b/driver/us_def_handler.c
@@ -0,0 +1,97 @@
+#include <linux/module.h>
+#include <asm/percpu.h>
+#include <ec_probe.h>
+#include <picl.h>
+#include <swap_uprobes.h>
+#include <sspt/ip.h>
+#include <dbi_kprobes_deps.h>
+#include "storage.h"
+#include "us_proc_inst.h"
+
+DEFINE_PER_CPU(struct us_ip *, gpCurIp) = NULL;
+EXPORT_PER_CPU_SYMBOL_GPL(gpCurIp);
+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;
+ __get_cpu_var(gpUserRegs) = regs;
+ return 0;
+}
+EXPORT_SYMBOL_GPL(ujprobe_event_pre_handler);
+
+void ujprobe_event_handler(unsigned long arg0, unsigned long arg1,
+ unsigned long arg2, unsigned long arg3,
+ unsigned long arg4, unsigned long arg5)
+{
+ struct us_ip *ip = __get_cpu_var(gpCurIp);
+ unsigned long addr = (unsigned long)ip->jprobe.up.kp.addr;
+
+#if defined(CONFIG_ARM)
+ addr = ip->offset & 0x01 ? addr | 0x01 : addr;
+#endif
+
+ pack_event_info(US_PROBE_ID, RECORD_ENTRY, "ppppppp", addr, arg0, arg1,
+ arg2, arg3, arg4, arg5);
+ dbi_uprobe_return();
+}
+EXPORT_SYMBOL_GPL(ujprobe_event_handler);
+
+static void send_plt(struct us_ip *ip)
+{
+ unsigned long addr = (unsigned long)ip->jprobe.up.kp.addr;
+ struct vm_area_struct *vma = find_vma(current->mm, addr);
+
+ if (vma && check_vma(vma)) {
+ char *name = NULL;
+ unsigned long real_addr;
+ unsigned long real_got = current->mm->exe_file == vma->vm_file ?
+ ip->got_addr :
+ ip->got_addr + vma->vm_start;
+
+ if (!read_proc_vm_atomic(current, real_got, &real_addr, sizeof(real_addr))) {
+ printk("Failed to read got %lx at memory address %lx!\n", ip->got_addr, real_got);
+ return;
+ }
+
+ vma = find_vma(current->mm, real_addr);
+ 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 %lx address\n", real_addr);
+ return;
+ }
+
+ if (name)
+ pack_event_info(PLT_ADDR_PROBE_ID, RECORD_RET, "ppsp",
+ addr, real_addr, name,
+ real_addr - vma->vm_start);
+ else
+ pack_event_info(PLT_ADDR_PROBE_ID, RECORD_RET, "ppp",
+ addr, real_addr,
+ real_addr - vma->vm_start);
+ }
+}
+
+int uretprobe_event_handler(struct uretprobe_instance *probe,
+ struct pt_regs *regs,
+ struct us_ip *ip)
+{
+ int retval = regs_return_value(regs);
+ unsigned long addr = (unsigned long)ip->jprobe.up.kp.addr;
+
+ if (ip->got_addr && ip->flag_got == 0) {
+ send_plt(ip);
+ ip->flag_got = 1;
+ }
+
+#if defined(CONFIG_ARM)
+ addr = ip->offset & 0x01 ? addr | 0x01 : addr;
+#endif
+
+ pack_event_info(US_PROBE_ID, RECORD_RET, "pd", addr, retval);
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(uretprobe_event_handler);
diff --git a/driver/us_def_handler.h b/driver/us_def_handler.h
new file mode 100644
index 00000000..3628ac07
--- /dev/null
+++ b/driver/us_def_handler.h
@@ -0,0 +1,21 @@
+#ifndef _US_DEF_HANDLER_H
+#define _US_DEF_HANDLER_H
+
+#include <asm/percpu.h>
+
+struct us_ip;
+struct pt_regs;
+struct uretprobe_instance;
+
+DECLARE_PER_CPU(struct us_ip *, gpCurIp);
+DECLARE_PER_CPU(struct pt_regs *, gpUserRegs);
+
+unsigned long ujprobe_event_pre_handler(struct us_ip *ip,
+ struct pt_regs *regs);
+void ujprobe_event_handler(unsigned long arg0, unsigned long arg1,
+ unsigned long arg2, unsigned long arg3,
+ unsigned long arg4, unsigned long arg5);
+int uretprobe_event_handler(struct uretprobe_instance *p,
+ struct pt_regs *regs, struct us_ip *ip);
+
+#endif /* _US_DEF_HANDLER_H */
diff --git a/driver/us_proc_inst.c b/driver/us_proc_inst.c
index 6ab82ce0..6a4319f0 100644
--- a/driver/us_proc_inst.c
+++ b/driver/us_proc_inst.c
@@ -29,11 +29,6 @@
static const char *app_filter = "app";
-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 uretprobe_instance *probe, struct pt_regs *regs, struct us_ip *ip);
-
-
#define print_event(fmt, args...) \
{ \
char *buf[1024]; \
@@ -240,110 +235,10 @@ void print_vma(struct mm_struct *mm)
printk("### print_vma: END\n");
}
-static DEFINE_PER_CPU(struct us_ip *, gpCurIp) = NULL;
-EXPORT_PER_CPU_SYMBOL_GPL(gpCurIp);
-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;
- __get_cpu_var (gpUserRegs) = regs;
- return 0;
-}
-
-void ujprobe_event_handler (unsigned long arg1, unsigned long arg2, unsigned long arg3, unsigned long arg4, unsigned long arg5, unsigned long arg6)
-{
- struct us_ip *ip = __get_cpu_var(gpCurIp);
- unsigned long addr = (unsigned long)ip->jprobe.up.kp.addr;
-
-#if defined(CONFIG_ARM)
- if (ip->offset & 0x01)
- {
- pack_event_info (US_PROBE_ID, RECORD_ENTRY, "ppppppp", addr | 0x01, arg1, arg2, arg3, arg4, arg5, arg6);
- }else{
- pack_event_info (US_PROBE_ID, RECORD_ENTRY, "ppppppp", addr, arg1, arg2, arg3, arg4, arg5, arg6);
- }
-#else
- pack_event_info (US_PROBE_ID, RECORD_ENTRY, "ppppppp", addr, arg1, arg2, arg3, arg4, arg5, arg6);
-#endif
- // Mr_Nobody: uncomment for valencia
- //unregister_usprobe(current, ip, 1);
- dbi_uprobe_return ();
-}
-
-static void send_plt(struct us_ip *ip)
-{
- unsigned long addr = (unsigned long)ip->jprobe.up.kp.addr;
- struct vm_area_struct *vma = find_vma(current->mm, addr);
-
- if (vma && check_vma(vma)) {
- char *name = NULL;
- unsigned long real_addr;
- unsigned long real_got = current->mm->exe_file == vma->vm_file ?
- ip->got_addr :
- ip->got_addr + vma->vm_start;
-
- if (!read_proc_vm_atomic(current, real_got, &real_addr, sizeof(real_addr))) {
- printk("Failed to read got %lx at memory address %lx!\n", ip->got_addr, real_got);
- return;
- }
-
- vma = find_vma(current->mm, real_addr);
- 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 %lx address\n", real_addr);
- return;
- }
-
- if (name) {
- pack_event_info(PLT_ADDR_PROBE_ID, RECORD_RET, "ppsp", addr, real_addr, name, real_addr - vma->vm_start);
- } else {
- pack_event_info(PLT_ADDR_PROBE_ID, RECORD_RET, "ppp", addr, real_addr, real_addr - vma->vm_start);
- }
- }
-}
-
-int uretprobe_event_handler(struct uretprobe_instance *probe, struct pt_regs *regs, struct us_ip *ip)
-{
- int retval = regs_return_value(regs);
- unsigned long addr = (unsigned long)ip->jprobe.up.kp.addr;
-
- if (ip->got_addr && ip->flag_got == 0) {
- send_plt(ip);
- ip->flag_got = 1;
- }
-
-#if defined(CONFIG_ARM)
- if (ip->offset & 0x01)
- {
- pack_event_info (US_PROBE_ID, RECORD_RET, "pd", addr | 0x01, retval);
- }else{
- pack_event_info (US_PROBE_ID, RECORD_RET, "pd", addr, retval);
- }
-#else
- pack_event_info (US_PROBE_ID, RECORD_RET, "pd", addr, retval);
-#endif
- // Mr_Nobody: uncomment for valencia
- //unregister_usprobe(current, ip, 1);
- return 0;
-}
-
int register_usprobe(struct us_ip *ip)
{
int ret = 0;
- if (ip->jprobe.entry == NULL) {
- ip->jprobe.entry = (void *)ujprobe_event_handler;
- DPRINTF("Set default event handler for %x\n", ip->offset);
- }
-
- if (ip->jprobe.pre_entry == NULL) {
- ip->jprobe.pre_entry = (uprobe_pre_entry_handler_t)ujprobe_event_pre_handler;
- DPRINTF("Set default pre handler for %x\n", ip->offset);
- }
-
ip->jprobe.priv_arg = ip;
ip->jprobe.up.task = ip->page->file->proc->task;
ip->jprobe.up.sm = ip->page->file->proc->sm;
@@ -365,12 +260,6 @@ int register_usprobe(struct us_ip *ip)
memcpy(&ip->retprobe.up.kp.opcode, &ip->jprobe.up.kp.opcode, sizeof(kprobe_opcode_t));
if (ip->flag_retprobe) {
- // Mr_Nobody: comment for valencia
- if (ip->retprobe.handler == NULL) {
- ip->retprobe.handler = (uretprobe_handler_t)uretprobe_event_handler;
- DPRINTF("Set default ret event handler for %x\n", ip->offset);
- }
-
ip->retprobe.priv_arg = ip;
ip->retprobe.up.task = ip->page->file->proc->task;
ip->retprobe.up.sm = ip->page->file->proc->sm;