fracipo
5th November 2007, 12:16 PM
Hallo!
I have a problem writing into a memory segment from inside the kernel.
I allocated a segment of memory (an array of char) in USER-SPACE
and read it correctly from KERNEL-SPACE with the function copy_from_user().
The problem comes when writing into such segment using the copy_to_user() function!
The segment of memory is an array and should be writable...
I've tried to set the memory flags of the memory segment
(form task_struct->mm_struct->vm_area_struct of the user space program)
by using:
((program->mm)->mmap)->vm_flags = VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC | VM_READ | VM_WRITE;
(where program is the pointer to the task_struct of the program)
but copy_to_user returns and the number of bytes it fails to write is nonzero...
copy to user: http://www.gelato.unsw.edu.au/~dsw/public-files/kernel-docs/kernel-api/r4037.html
copy from user: http://www.gelato.unsw.edu.au/~dsw/public-files/kernel-docs/kernel-api/r4081.html
Can someone please help me solve this issue?
thanks in advance,
Francesco
UPDATE:
doing some debugging and changes I see that only sometimes it writes...
copy to user returns a 0 value only sometimes...
someone can tell me why?
I have a problem writing into a memory segment from inside the kernel.
I allocated a segment of memory (an array of char) in USER-SPACE
and read it correctly from KERNEL-SPACE with the function copy_from_user().
The problem comes when writing into such segment using the copy_to_user() function!
The segment of memory is an array and should be writable...
I've tried to set the memory flags of the memory segment
(form task_struct->mm_struct->vm_area_struct of the user space program)
by using:
((program->mm)->mmap)->vm_flags = VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC | VM_READ | VM_WRITE;
(where program is the pointer to the task_struct of the program)
but copy_to_user returns and the number of bytes it fails to write is nonzero...
copy to user: http://www.gelato.unsw.edu.au/~dsw/public-files/kernel-docs/kernel-api/r4037.html
copy from user: http://www.gelato.unsw.edu.au/~dsw/public-files/kernel-docs/kernel-api/r4081.html
Can someone please help me solve this issue?
thanks in advance,
Francesco
UPDATE:
doing some debugging and changes I see that only sometimes it writes...
copy to user returns a 0 value only sometimes...
someone can tell me why?