Question about copy_from_user/copy_to_user
Hi all,
I am working on a module driver. A user application alloc a bunch of memory for storing packet. And module driver can read /write data from/into the memory in user space. I use ioctl function to pass the pointer of memory of user space to module driver. What I want to do is to store the pointer in kernel space and when I need to write or read data from memory of user space, I try to use copy_from_user or copy_to_user to get/put data. But I always get wrong data. I don't know the reason. Would you guys give me some help?
Simple description of the code:
device_ioctl() {
// get the pointer of memory of user space, and assign thepointer to kernel variable.
}
device_xmit(){
// when upper layer send a packet to this device.
// I try to use the copy_from_user to get some information from
user space buf
// but I cannot get correct information.
}Thx
Quoted 27 lines · Qiuyu Zhang
Hi all,
I am working on a module driver. A user application alloc a bunch of memory for storing packet. And module driver can read /write data from/into the memory in user space. I use ioctl function to pass the pointer of memory of user space to module driver. What I want to do is to store the pointer in kernel space and when I need to write or read data from memory of user space, I try to use
copy_from_userorcopy_to_userto get/put data. But I always get wrong data. I don't know the reason. Would you guys give me some help?Simple description of the code:
device_ioctl() { // get the pointer of memory of user space, and assign thepointer to kernel variable.
}device_xmit(){ // when upper layer send a packet to this device. // I try to use the copy_from_user to get some information from user space buf // but I cannot get correct information. }
Quoted 2 lines
Thx
-
The kernel executes functions upon behalf of the caller. The caller's pointer is only valid when the caller calls the kernel. At another time, the kernel has its data-segment set to KERNEL_DS and other times set to the virtual address space of other callers.
Anything written like you propose is likely to vomit and take your corner of the galaxy with it. Please get a good book about kernel device drivers first before you start.
Cheers,
Dick Johnson
Penguin : Linux version 2.4.26 on an i686 machine (5570.56 BogoMips).
Note 96.31% of all statistics are fiction.