3 @@ -2505,3 +2505,56 @@ #endif
6 #endif /* __HAVE_ARCH_GATE_AREA */
9 + * Access another process' address space.
10 + * Source/target buffer must be kernel space,
11 + * Do not walk the page table directly, use get_user_pages
13 +int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
15 + struct mm_struct *mm;
16 + struct vm_area_struct *vma;
18 + void *old_buf = buf;
20 + mm = get_task_mm(tsk);
24 + down_read(&mm->mmap_sem);
25 + /* ignore errors, just check how much was sucessfully transfered */
27 + int bytes, ret, offset;
30 + ret = get_user_pages(tsk, mm, addr, 1,
31 + write, 1, &page, &vma);
36 + offset = addr & (PAGE_SIZE-1);
37 + if (bytes > PAGE_SIZE-offset)
38 + bytes = PAGE_SIZE-offset;
42 + copy_to_user_page(vma, page, addr,
43 + maddr + offset, buf, bytes);
44 + set_page_dirty_lock(page);
46 + copy_from_user_page(vma, page, addr,
47 + buf, maddr + offset, bytes);
50 + page_cache_release(page);
55 + up_read(&mm->mmap_sem);
58 + return buf - old_buf;
62 @@ -1206,3 +1206,51 @@ struct page *filemap_nopage(struct vm_ar
68 + * Access another process' address space.
69 + * - source/target buffer must be kernel space
71 +int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
73 + struct vm_list_struct *vml;
74 + struct vm_area_struct *vma;
75 + struct mm_struct *mm;
76 +printk("!!! OH YEAH\n");
77 + if (addr + len < addr)
80 + mm = get_task_mm(tsk);
84 + down_read(&mm->mmap_sem);
86 + /* the access must start within one of the target process's mappings */
87 + for (vml = mm->context.vmlist; vml; vml = vml->next) {
88 + if (addr >= vml->vma->vm_start && addr < vml->vma->vm_end)
95 + /* don't overrun this mapping */
96 + if (addr + len >= vma->vm_end)
97 + len = vma->vm_end - addr;
99 + /* only read or write mappings where it is permitted */
100 + if (write && vma->vm_flags & VM_WRITE)
101 + len -= copy_to_user((void *) addr, buf, len);
102 + else if (!write && vma->vm_flags & VM_READ)
103 + len -= copy_from_user(buf, (void *) addr, len);
110 + up_read(&mm->mmap_sem);