doubts for copy_from_user

Dave Hylands dhylands at gmail.com
Sun Jul 3 13:15:10 EDT 2011


Hi Vishal,

On Sun, Jul 3, 2011 at 5:09 AM, Vishal Thanki <vishalthanki at gmail.com> 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. But, the implementation
> of these functions actually access the user-space data right? Can
> someone explain me how this actually happens?

How it actually happens is architecture dependent. Whether kernel
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



More information about the Kernelnewbies mailing list