#include "dbi_kprobes.h"
#include "../dbi_kprobes.h"
+#include "../../dbi_kprobes.h"
#include "../../dbi_kdebug.h"
#include "../../dbi_insn_slots.h"
#define SUPRESS_BUG_MESSAGES
-extern unsigned long sched_addr;
-extern unsigned long fork_addr;
-
extern struct kprobe * per_cpu__current_kprobe;
-extern spinlock_t kretprobe_lock;
-extern struct kretprobe *sched_rp;
-
-extern struct hlist_head kprobe_insn_pages;
-extern struct hlist_head uprobe_insn_pages;
-
-extern struct kprobe *kprobe_running(void);
-extern void reset_current_kprobe(void);
-extern struct kprobe_ctlblk *get_kprobe_ctlblk(void);
-extern struct kprobe * current_kprobe;
-
extern struct hlist_head kprobe_table[KPROBE_TABLE_SIZE];
#ifdef OVERHEAD_DEBUG
return (kprobe_opcode_t)((long)addr + 8 + branch_displacement(insn));
}
-unsigned int arr_traps_template[] = {
+static unsigned int arr_traps_template[] = {
0xe1a0c00d, // mov ip, sp
0xe92dd800, // stmdb sp!, {fp, ip, lr, pc}
0xe24cb004, // sub fp, ip, #4 ; 0x4
};
-struct kprobe trampoline_p =
+static struct kprobe trampoline_p =
{
.addr = (kprobe_opcode_t *) & kretprobe_trampoline,
.pre_handler = trampoline_probe_handler
};
// is instruction Thumb2 and NOT a branch, etc...
-int isThumb2(kprobe_opcode_t insn)
+static int isThumb2(kprobe_opcode_t insn)
{
if(( (insn & 0xf800) == 0xe800 ||
(insn & 0xf800) == 0xf000 ||
}
-int prep_pc_dep_insn_execbuf (kprobe_opcode_t * insns, kprobe_opcode_t insn, int uregs)
+static int prep_pc_dep_insn_execbuf (kprobe_opcode_t * insns, kprobe_opcode_t insn, int uregs)
{
int i;
-int prep_pc_dep_insn_execbuf_thumb (kprobe_opcode_t * insns, kprobe_opcode_t insn, int uregs)
+static int prep_pc_dep_insn_execbuf_thumb (kprobe_opcode_t * insns, kprobe_opcode_t insn, int uregs)
{
unsigned char mreg = 0;
unsigned char reg = 0;
-int arch_check_insn_arm (struct arch_specific_insn *ainsn)
+static int arch_check_insn_arm (struct arch_specific_insn *ainsn)
{
int ret = 0;
return ret;
}
-int arch_check_insn_thumb (struct arch_specific_insn *ainsn)
+static int arch_check_insn_thumb (struct arch_specific_insn *ainsn)
{
int ret = 0;
return -EFAULT;
}
if ((p->safe_arm == -1) && (p->safe_thumb == -1)) {
- printk("Error in %s at %d: failed arch_copy_trampoline_*_uprobe() (both) [tgid=%u, addr=%x, data=%x]\n",
- __FILE__, __LINE__, task->tgid, p->addr, p->opcode);
+ printk("Error in %s at %d: failed arch_copy_trampoline_*_uprobe() (both) [tgid=%u, addr=%lx, data=%lx]\n",
+ __FILE__, __LINE__, task->tgid, (unsigned long)p->addr, (unsigned long)p->opcode);
if (!write_proc_vm_atomic (task, (unsigned long) p->addr, &p->opcode, sizeof (p->opcode)))
panic ("Failed to write memory %p!\n", p->addr);
free_insn_slot(&uprobe_insn_pages, task, p->ainsn.insn_arm);
struct kprobe *p = NULL, *p_run = NULL;
int ret = 0, retprobe = 0, reenter = 0;
- kprobe_opcode_t *ssaddr = 0;
+ kprobe_opcode_t *ssaddr = NULL;
struct kprobe_ctlblk *kcb;
#ifdef SUPRESS_BUG_MESSAGES
}
-int asm_init_module_dependencies()
+int asm_init_module_dependencies(void)
{
//No module dependencies
return 0;
}
-
-void (* do_kpro)(struct undef_hook *);
-void (* undo_kpro)(struct undef_hook *);
+typedef void (* kpro_type)(struct undef_hook *);
+static kpro_type do_kpro;
+static kpro_type undo_kpro;
// kernel probes hook
-struct undef_hook undef_ho_k = {
+static struct undef_hook undef_ho_k = {
.instr_mask = 0xffffffff,
.instr_val = BREAKPOINT_INSTRUCTION,
.cpsr_mask = MODE_MASK,
};
// userspace probes hook (arm)
-struct undef_hook undef_ho_u = {
+static struct undef_hook undef_ho_u = {
.instr_mask = 0xffffffff,
.instr_val = BREAKPOINT_INSTRUCTION,
.cpsr_mask = MODE_MASK,
};
// userspace probes hook (thumb)
-struct undef_hook undef_ho_u_t = {
+static struct undef_hook undef_ho_u_t = {
.instr_mask = 0xffffffff,
.instr_val = BREAKPOINT_INSTRUCTION & 0x0000ffff,
.cpsr_mask = MODE_MASK,
}
arr_traps_template[NOTIFIER_CALL_CHAIN_INDEX] = arch_construct_brunch ((unsigned int)kprobe_handler, do_bp_handler + NOTIFIER_CALL_CHAIN_INDEX * 4, 1);
// Register hooks (kprobe_handler)
- do_kpro = swap_ksyms("register_undef_hook");
- if (do_kpro == 0) {
+ do_kpro = (kpro_type)swap_ksyms("register_undef_hook");
+ if (do_kpro == NULL) {
printk("no register_undef_hook symbol found!\n");
return -1;
}
// Unregister hooks (kprobe_handler)
- undo_kpro = swap_ksyms("unregister_undef_hook");
- if (undo_kpro == 0) {
+ undo_kpro = (kpro_type)swap_ksyms("unregister_undef_hook");
+ if (undo_kpro == NULL) {
printk("no unregister_undef_hook symbol found!\n");
return -1;
}
unsigned int *arr_traps_original;
-extern unsigned long sched_addr;
-
extern struct kprobe * per_cpu__current_kprobe;
-extern spinlock_t kretprobe_lock;
-extern struct kretprobe *sched_rp;
-
-extern struct hlist_head kprobe_insn_pages;
-extern struct hlist_head uprobe_insn_pages;
-
-extern struct kprobe *kprobe_running (void);
-extern struct kprobe_ctlblk *get_kprobe_ctlblk (void);
-extern void reset_current_kprobe (void);
#ifdef OVERHEAD_DEBUG
unsigned long swap_sum_time = 0;
#define SUPRESS_BUG_MESSAGES
-extern unsigned long sched_addr;
extern unsigned long exit_addr;
-extern unsigned long fork_addr;
extern struct kprobe * per_cpu__current_kprobe;
extern struct kprobe * per_cpu__current_kprobe;
-extern spinlock_t kretprobe_lock;
-extern struct kretprobe *sched_rp;
-extern struct hlist_head kprobe_insn_pages;
-extern struct hlist_head uprobe_insn_pages;
-
-extern spinlock_t kretprobe_lock;
-
-extern struct kprobe *kprobe_running (void);
-extern struct kprobe_ctlblk *get_kprobe_ctlblk (void);
-extern void reset_current_kprobe (void);
extern struct kprobe * current_kprobe;
#ifdef OVERHEAD_DEBUG
#include <ksyms.h>
-extern unsigned long sched_addr;
-extern unsigned long fork_addr;
-
-extern struct hlist_head kprobe_insn_pages;
-extern struct hlist_head uprobe_insn_pages;
-
-
void arch_remove_kprobe (struct kprobe *p, struct task_struct *task)
{
// TODO: check boostable for x86 and MIPS
{
}
-int arch_init_module_dependencies()
+int arch_init_module_dependencies(void)
{
sched_addr = swap_ksyms("__switch_to");
fork_addr = swap_ksyms("do_fork");
unsigned long len, unsigned long prot,
unsigned long flags, unsigned long pgoff);
-extern struct hlist_head uprobe_insn_slot_table[KPROBE_TABLE_SIZE];
struct hlist_head kprobe_insn_pages;
struct hlist_head uprobe_insn_pages;
}
// FIXME: its seems to be bad decision to replace 'current' pointer temporarily
current_thread_info()->task = task;
- ret = do_mmap_pgoff(0, 0, len, prot, flags, 0);
+ ret = do_mmap_pgoff(NULL, 0, len, prot, flags, 0);
current_thread_info()->task = otask;
if (!atomic) {
downgrade_write (&mm->mmap_sem);
kprobe_opcode_t *get_insn_slot(struct task_struct *task, int atomic);
void free_insn_slot(struct hlist_head *page_list, struct task_struct *task, kprobe_opcode_t *slot);
+extern struct hlist_head kprobe_insn_pages;
+extern struct hlist_head uprobe_insn_pages;
#endif /* _SRC_INSNS_SLOTS_H */
#include <linux/pagemap.h>
-
-extern unsigned long sched_addr;
-extern unsigned long fork_addr;
-extern struct hlist_head kprobe_insn_pages;
-
DEFINE_PER_CPU (struct kprobe *, current_kprobe) = NULL;
-DEFINE_PER_CPU (struct kprobe_ctlblk, kprobe_ctlblk);
+static DEFINE_PER_CPU (struct kprobe_ctlblk, kprobe_ctlblk);
DEFINE_SPINLOCK (kretprobe_lock); /* Protects kretprobe_inst_table */
-DEFINE_PER_CPU (struct kprobe *, kprobe_instance) = NULL;
+static DEFINE_PER_CPU (struct kprobe *, kprobe_instance) = NULL;
struct hlist_head kprobe_table[KPROBE_TABLE_SIZE];
-struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE];
+static struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE];
atomic_t kprobe_count;
* Add the new probe to old_p->list. Fail if this is the
* second jprobe at the address - two jprobes can't coexist
*/
-int add_new_kprobe (struct kprobe *old_p, struct kprobe *p)
+static int add_new_kprobe (struct kprobe *old_p, struct kprobe *p)
{
if (p->break_handler)
{
void dbi_unregister_jprobe (struct jprobe *jp)
{
- dbi_unregister_kprobe (&jp->kp, 0);
+ dbi_unregister_kprobe (&jp->kp, NULL);
}
/*
unsigned long flags;
struct kretprobe_instance *ri;
- dbi_unregister_kprobe (&rp->kp, 0);
+ dbi_unregister_kprobe (&rp->kp, NULL);
if ((unsigned long)rp->kp.addr == sched_addr) {
unpatch_suspended_all_task_ret_addr(rp);
rcu_read_unlock();
}
-int __init init_kprobes (void)
+static int __init init_kprobes (void)
{
int i, err = 0;
return err;
}
-void __exit exit_kprobes (void)
+static void __exit exit_kprobes (void)
{
dbi_arch_exit_kprobes ();
}
void set_normalized_timeval (struct timeval *tv, time_t sec, suseconds_t usec);
#endif
+extern DEFINE_PER_CPU (struct kprobe *, current_kprobe);
+extern spinlock_t kretprobe_lock;
+extern struct hlist_head kprobe_table[KPROBE_TABLE_SIZE];
+//extern struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE];
+extern atomic_t kprobe_count;
+extern struct kretprobe *sched_rp;
+
+struct kprobe *kprobe_running (void);
+void reset_current_kprobe (void);
+struct kprobe_ctlblk *get_kprobe_ctlblk (void);
#endif /* _DBI_KPROBES_H */
unsigned long fork_addr;
#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 29)
-struct mm_struct* init_mm_ptr;
+static struct mm_struct* init_mm_ptr;
struct mm_struct init_mm;
#endif
#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38)
-unsigned long zero_pfn __read_mostly;
+static unsigned long zero_pfn __read_mostly;
#ifndef is_zero_pfn
static inline int is_zero_pfn(unsigned long pfn)
stack_guard_page_end(vma, addr+PAGE_SIZE);
}
-int __get_user_pages_uprobe(struct task_struct *tsk, struct mm_struct *mm,
+static int __get_user_pages_uprobe(struct task_struct *tsk, struct mm_struct *mm,
unsigned long start, int nr_pages, unsigned int gup_flags,
struct page **pages, struct vm_area_struct **vmas,
int *nonblocking)
}
#else /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */
-int __get_user_pages_uprobe(struct task_struct *tsk, struct mm_struct *mm,
+static int __get_user_pages_uprobe(struct task_struct *tsk, struct mm_struct *mm,
unsigned long start, int len, int flags,
struct page **pages, struct vm_area_struct **vmas)
{
return __get_user_pages_uprobe(tsk, mm,
start, len, flags,
#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38)
- pages, vmas, 0);
+ pages, vmas, NULL);
#else /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */
pages, vmas);
#endif /* LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 38) */
#define get_user_pages_atomic get_user_pages_uprobe
-
+extern unsigned long sched_addr;
+extern unsigned long fork_addr;
#endif /* _DBI_KPROBES_DEPS_H */
#include <linux/mempolicy.h>
#include <linux/module.h>
-
-extern atomic_t kprobe_count;
-extern struct hlist_head kprobe_table[KPROBE_TABLE_SIZE];
-extern struct hlist_head kretprobe_inst_table[KPROBE_TABLE_SIZE];
-extern spinlock_t kretprobe_lock;
-
-extern struct kretprobe *sched_rp;
-
struct hlist_head uprobe_insn_slot_table[KPROBE_TABLE_SIZE];
head = &kprobe_table[i];
hlist_for_each_entry_safe(p, node, tnode, head, hlist) {
if (p->tgid == task->tgid) {
- printk("dbi_unregister_all_uprobes: delete uprobe at %p[%x] for %s/%d\n",
- p->addr, p->opcode, task->comm, task->pid);
+ printk("dbi_unregister_all_uprobes: delete uprobe at %p[%lx] for %s/%d\n",
+ p->addr, (unsigned long)p->opcode, task->comm, task->pid);
unregister_uprobe(p, task, atomic);
}
}
void dbi_uprobe_return(void);
-
+extern struct hlist_head uprobe_insn_slot_table[KPROBE_TABLE_SIZE];
#endif /* _DBI_UPROBES_H */