On Sun, Jul 3, 2011 at 10:45 PM, Dave Hylands <dhylands@xxxxxxxxx> wrote:
Hi Vishal,
On Sun, Jul 3, 2011 at 5:09 AM, Vishal Thanki <vishalthanki@xxxxxxxxx> wrote:
> Hi,
>
> We use copy_from_user/copy_to_user functions to copy data transfer
> user data between user space and kernel space. As per my
> understanding, these functions are required because we cannot access
> userspace data directly within kernel space.
Basically if you want to aceess some data from userspace and if that data is not present in memory...or if your user pointer is invalid then it can create lots of problem in your kernel module and kernel may crash.
So, its better to acess something safely, thats why copy to usr/ copy from user is. it does all the validation on user space pointers. Try with memcpy also in your code in place of copy to usr. It will also work if your user space pointer is valid enough. if the user space address is swapped out, this will not work. See what happens then...
But, the implementationHow it actually happens is architecture dependent. Whether kernel
> of these functions actually access the user-space data right? Can
> someone explain me how this actually happens?
space can access user space while in the context of the user-process
is also architecture dependent. I know with ARM, for example, it's
possible to do memcpy instead of copy_to_user, but using memcpy isn't
guaranteed to work on all architectures.
The other difference between memcpy and copy_to/from_user is that
memcpy will typically cause a segmentation fault if passed a bad
pointer, where copy_to/from_user won't.
--
Dave Hylands
Shuswap, BC, Canada
http://www.davehylands.com
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@xxxxxxxxxxxxxxxxx
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@xxxxxxxxxxxxxxxxx http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies