#include "ip.h"
#include "sspt_page.h"
#include "sspt_file.h"
+#include <writer/swap_writer_module.h>
-#include "us_def_handler.h"
+
+static int entry_handler(struct uretprobe_instance *ri, struct pt_regs *regs)
+{
+ struct us_ip *ip = container_of(ri->rp, struct us_ip, retprobe);
+
+ entry_event(ip->args, regs, PT_US, PST_NONE);
+
+ return 0;
+}
+
+static int ret_handler(struct uretprobe_instance *ri, struct pt_regs *regs)
+{
+ struct us_ip *ip = container_of(ri->rp, struct us_ip, retprobe);
+ unsigned long addr = (unsigned long)ip->retprobe.up.kp.addr;
+
+#if defined(CONFIG_ARM)
+ addr = ip->offset & 0x01 ? addr | 0x01 : addr;
+#endif
+
+ exit_event(regs, addr);
+
+ return 0;
+}
struct us_ip *create_ip(unsigned long offset, const char *args)
{
ip->got_addr = 0;
ip->flag_got = 1;
- /* jprobe */
- ip->jprobe.pre_entry = ujprobe_event_pre_handler;
- ip->jprobe.entry = ujprobe_event_handler;
-
/* TODO: or copy args?! */
- ip->jprobe.args = args;
+ ip->args = args;
/* retprobe */
ip->flag_retprobe = 1;
- ip->retprobe.handler = uretprobe_event_handler;
+ ip->retprobe.handler = ret_handler;
+ ip->retprobe.entry_handler = entry_handler;
return ip;
}
struct list_head list;
struct sspt_page *page;
- struct ujprobe jprobe;
struct uretprobe retprobe;
+ char *args;
unsigned long offset;
unsigned long got_addr;
#include "sspt_debug.h"
#include "us_proc_types.h"
#include <swap_uprobes.h>
-#include "us_def_handler.h"
#include <us_manager.h>
{
int ret = 0;
- /* for juprobe */
- ip->jprobe.priv_arg = ip;
- ip->jprobe.up.task = ip->page->file->proc->task;
- ip->jprobe.up.sm = ip->page->file->proc->sm;
-
/* for retuprobe */
ip->retprobe.up.task = ip->page->file->proc->task;
ip->retprobe.up.sm = ip->page->file->proc->sm;
- ret = dbi_register_ujprobe(&ip->jprobe);
- if (ret) {
- printk("dbi_register_ujprobe() failure %d\n", ret);
- return ret;
- }
-
if (ip->flag_retprobe) {
ret = dbi_register_uretprobe(&ip->retprobe);
if (ret) {
static inline int do_unregister_usprobe(struct us_ip *ip)
{
- dbi_unregister_ujprobe(&ip->jprobe);
-
if (ip->flag_retprobe) {
dbi_unregister_uretprobe(&ip->retprobe);
}
err = do_unregister_usprobe(ip);
break;
case US_DISARM:
- disarm_uprobe(&ip->jprobe.up.kp, task);
+ disarm_uprobe(&ip->retprobe.up.kp, task);
break;
default:
panic("incorrect value flag=%d", flag);
printk("### offset=%lx\n", page->offset);
list_for_each_entry(ip, &page->ip_list, list) {
- printk("### addr[%2d]=%lx, J_addr=%lx, R_addr=%lx\n",
- i, (unsigned long)ip->offset, (unsigned long)ip->jprobe.up.kp.addr,
+ printk("### addr[%2d]=%lx, R_addr=%lx\n",
+ i, (unsigned long)ip->offset,
(unsigned long)ip->retprobe.up.kp.addr);
- print_jprobe(&ip->jprobe);
print_retprobe(&ip->retprobe);
++i;
}
list_for_each_entry(ip, &page->ip_list, list) {
addr = file->vm_start + page->offset + ip->offset;
- ip->retprobe.up.kp.addr = ip->jprobe.up.kp.addr = (kprobe_opcode_t *)addr;
+ ip->retprobe.up.kp.addr = (kprobe_opcode_t *)addr;
}
}
+++ /dev/null
-/*
- * SWAP uprobe manager
- * modules/us_manager/us_def_handler.c
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * Copyright (C) Samsung Electronics, 2013
- *
- * 2013 Vyacheslav Cherkashin: SWAP us_manager implement
- *
- */
-
-#include <linux/module.h>
-#include <asm/percpu.h>
-#include <swap_uprobes.h>
-#include <sspt/ip.h>
-#include <dbi_kprobes_deps.h>
-#include <sspt/sspt.h>
-#include <writer/swap_writer_module.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);
- struct us_ip *regs = __get_cpu_var(gpUserRegs);
- unsigned long addr = (unsigned long)ip->jprobe.up.kp.addr;
-
-#if defined(CONFIG_ARM)
- addr = ip->offset & 0x01 ? addr | 0x01 : addr;
-#endif
-
- entry_event(ip->jprobe.args, regs, PT_US, PST_NONE);
-
- swap_ujprobe_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)
-{
- int retval = regs_return_value(regs);
- struct us_ip *ip = container_of(probe->rp, struct us_ip, retprobe);
- 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
-
- exit_event(regs, addr);
-
- return 0;
-}
-EXPORT_SYMBOL_GPL(uretprobe_event_handler);
+++ /dev/null
-/*
- * SWAP uprobe manager
- * modules/us_manager/us_def_handler.h
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- * Copyright (C) Samsung Electronics, 2013
- *
- * 2013 Vyacheslav Cherkashin: SWAP us_manager implement
- *
- */
-
-#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);
-
-#endif /* _US_DEF_HANDLER_H */