0
我正在編寫一個讀取進程虛擬內存部分的內核模塊。我試圖在內核中使用access_process_vm方法,但它總是讀取0個字節。瞭解access_process_vm linux內核?
target = get_pid_task(find_get_pid(target_pid),PIDTYPE_PID);
if (target == NULL) {
printk(KERN_ALERT "no such task %d\n",target_pid);
return -1;
}
printk(KERN_INFO "opened task with pid %d\n",target->pid);
len = vm_end-vm_start;
buf = kmalloc(len ,GFP_KERNEL);
if (!buf) {
printk(KERN_ALERT "unable to allocate memory\n");
return -1;
}
printk(KERN_INFO "allocated memory\n");
bytes = access_process_vm(target,addr,buf,len,FOLL_FORCE);
if (bytes != len) {
printk(KERN_ALERT "could only read %d of %ld bytes\n",bytes,len);
kfree(buf);
return -1;
}
printk(KERN_INFO "read %d bytes successfully\n",bytes);
我在做什麼錯?