%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% $Id: user.tex,v 1.1 2002/07/12 15:37:26 nayaniabhishek Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Userspace access}
\section{copy\_[to/from]\_user}

Macros copy\_to\_user and copy\_from\_user are used to copy arbitrary
amount of data between kernel space and user space. They return the number
of uncopied bytes (0 is a successful return). Since they may sleep implicitly,
they should never be called outside user context, with interrupts
disabled or with spinlock held.

\macro{copy\_to\_user}{copy_to_user}{include/asm-i386/uaccess.h}
\begin{verbatim}
#define copy_to_user(to,from,n)                         \
        (__builtin_constant_p(n) ?                      \
         __constant_copy_to_user((to),(from),(n)) :     \
         __generic_copy_to_user((to),(from),(n)))
\end{verbatim}

copy\_to\_user copies \textbf{n} bytes  from  address \textbf{from}
in kernel space to address \textbf{to} in user space. Code using this
function should look like:
	\begin{verbatim}
		if (copy_from_user(to,uptr,size)) {
		        return -EFAULT;
		}
	\end{verbatim}


\macro{copy\_from\_user}{copy_from_user}{include/asm-i386/uaccess.h}
\begin{verbatim}
#define copy_from_user(to,from,n)                       \
        (__builtin_constant_p(n) ?                      \
         __constant_copy_from_user((to),(from),(n)) :   \
         __generic_copy_from_user((to),(from),(n)))
\end{verbatim}
[TODO] describe ..does the oposite of copy\_to\_user.


\macro{\_\_copy\_to\_user}{__copy_to_user}{include/asm-i386/uaccess.h}
\begin{verbatim}
#define __copy_to_user(to,from,n)                       \
        (__builtin_constant_p(n) ?                      \
         __constant_copy_to_user_nocheck((to),(from),(n)) :     \
         __generic_copy_to_user_nocheck((to),(from),(n)))
\end{verbatim}
[TODO] describe


\macro{\_\_copy\_from\_user}{__copy_from_user}{include/asm-i386/uaccess.h}
\begin{verbatim}
#define __copy_from_user(to,from,n)                     \
        (__builtin_constant_p(n) ?                      \
         __constant_copy_from_user_nocheck((to),(from),(n)) :   \
         __generic_copy_from_user_nocheck((to),(from),(n)))
\end{verbatim}
[TODO] describe


