#include
#include
#include
#include
#include
static int hello_init(void) {
struct task_struct *p;
struct vm_area_struct *vma;
printk(KERN_ALERT "init fishing\n");
for_each_process(p) {
if (strcmp(p->comm,"a.out") == 0) {
printk(KERN_ALERT "%s-->%p\n",p->comm, p->mm);
for(vma = p->mm->mmap;vma!=NULL;vma = vma->vm_next) {
printk(KERN_ALERT "%lx - %lx\n",vma->vm_start, vma->vm_end);
}
}
}
return 0;
}
static void hello_exit(void) {
printk(KERN_ALERT "exit fishing\n");
}
subsys_initcall(hello_init);
module_exit(hello_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("shakespeare");
ifneq ($(KERNELRELEASE),)
$(info "2nd")
obj-m := fishing.o
else
#kdir := /lib/modules/$(shell uname -r)/build
kdir := /usr/src/linux-headers-$(shell uname -r)
pwd := $(shell pwd)
all:
$(info "1st")
make -C $(kdir) M=$(pwd) modules
clean:
rm *.ko *.o *.order *.mod.c *.symvers *.mod
endif
使用dmesg打印日志
通过对比可知,打印的线性地址与系统提供的procfs中的maps一致。