1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| #include <linux/init.h> #include <linux/module.h> #include <linux/platform_device.h> #include <linux/mm.h> #include <linux/rwsem.h> #include <linux/rmap.h> #include "klookup_symbol.h" #include <linux/slab.h>
static int g_enter_num;
struct vma_info { struct list_head list; struct vm_area_struct *vma; unsigned long address; };
static bool collect_vmas(struct page *page, struct vm_area_struct *vma, unsigned long address, void *arg) { struct list_head *vma_list = arg; struct vma_info *info = kmalloc(sizeof(*info), GFP_KERNEL); info->vma = vma; info->address = address; list_add(&info->list, vma_list);
g_enter_num++; pr_info("debug collect_vmas count=%d\n", g_enter_num); return true; }
void find_processes(phys_addr_t paddr) { /* pfn: physical frame number */ unsigned long pfn = paddr >> PAGE_SHIFT; struct page *page = pfn_to_page(pfn); LIST_HEAD(vma_list); struct rmap_walk_control rwc = { .rmap_one = collect_vmas, .arg = &vma_list, };
printk("paddr=0x%lx\n", paddr);
g_rmap_walk(page, &rwc); // 遍历 vma_list 输出进程和虚拟地址 struct vma_info *info; list_for_each_entry(info, &vma_list, list) { struct task_struct *task = info->vma->vm_mm->owner; printk("Process: %s, PID: %d, Virtual Address: 0x%lx\n", task->comm, task->pid, info->address); }
// pr_info("current pid=%d finished\n", current->pid); }
/* echo 0x10742b000 > /sys/module/vma/parameters/paddr
*/
unsigned long paddr = 0x104cb7000; module_param(paddr, ulong, 0644);
static int hello_init(void) { init_symbol(); find_processes(paddr);
return 0; }
static void hello_exit(void) { printk(KERN_ALERT "Goodbye,world\n"); }
module_init(hello_init); module_exit(hello_exit); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("hello driver");
|