From 7abdfe546471945b393fc4ff4a955b8e7b2a0ac2 Mon Sep 17 00:00:00 2001 From: kenistoj Date: Sat, 19 Jan 2008 00:24:07 +0000 Subject: * runtime/uprobes/uprobes.c: Added static copy of access_process_vm(), for kernels that don't export it. --- runtime/uprobes/uprobes.c | 62 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'runtime/uprobes/uprobes.c') diff --git a/runtime/uprobes/uprobes.c b/runtime/uprobes/uprobes.c index 50930709..005ca919 100644 --- a/runtime/uprobes/uprobes.c +++ b/runtime/uprobes/uprobes.c @@ -42,8 +42,14 @@ #define MAX_SSOL_SLOTS 1024 +#ifdef NO_ACCESS_PROCESS_VM_EXPORT +static int __access_process_vm(struct task_struct *tsk, unsigned long addr, + void *buf, int len, int write); +#define access_process_vm __access_process_vm +#else extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write); +#endif static int utask_fake_quiesce(struct uprobe_task *utask); static void uprobe_release_ssol_vma(struct uprobe_process *uproc); @@ -2267,5 +2273,61 @@ static void zap_uretprobe_instances(struct uprobe *u, } #endif /* CONFIG_URETPROBES */ +#ifdef NO_ACCESS_PROCESS_VM_EXPORT +/* + * Some kernel versions export everything that uprobes.ko needs except + * access_process_vm, so we copied and pasted it here. Fortunately, + * everything it calls is exported. + */ +#include +#include +static int __access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write) +{ + struct mm_struct *mm; + struct vm_area_struct *vma; + struct page *page; + void *old_buf = buf; + + mm = get_task_mm(tsk); + if (!mm) + return 0; + + down_read(&mm->mmap_sem); + /* ignore errors, just check how much was sucessfully transfered */ + while (len) { + int bytes, ret, offset; + void *maddr; + + ret = get_user_pages(tsk, mm, addr, 1, + write, 1, &page, &vma); + if (ret <= 0) + break; + + bytes = len; + offset = addr & (PAGE_SIZE-1); + if (bytes > PAGE_SIZE-offset) + bytes = PAGE_SIZE-offset; + + maddr = kmap(page); + if (write) { + copy_to_user_page(vma, page, addr, + maddr + offset, buf, bytes); + set_page_dirty_lock(page); + } else { + copy_from_user_page(vma, page, addr, + buf, maddr + offset, bytes); + } + kunmap(page); + page_cache_release(page); + len -= bytes; + buf += bytes; + addr += bytes; + } + up_read(&mm->mmap_sem); + mmput(mm); + + return buf - old_buf; +} +#endif #include "uprobes_arch.c" MODULE_LICENSE("GPL"); -- cgit