Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions
uaccess.h File Reference
#include <linux/errno.h>
#include <linux/thread_info.h>
#include <asm/page.h>
#include <asm/setup.h>

Go to the source code of this file.

Data Structures

struct  exception_table_entry
 
struct  __large_struct
 

Macros

#define VERIFY_READ   0
 
#define VERIFY_WRITE   1
 
#define MAKE_MM_SEG(s)   ((mm_segment_t) { (s) })
 
#define KERNEL_DS   MAKE_MM_SEG(0xFFFFFFFF)
 
#define USER_DS   MAKE_MM_SEG(0xFFFFFFFF)
 
#define get_ds()   (KERNEL_DS)
 
#define segment_eq(a, b)   ((a).seg == (b).seg)
 
#define __addr_ok(addr)   ((unsigned long)(addr) < (current_thread_info()->addr_limit.seg))
 
#define __range_ok(addr, size)
 
#define get_user(x, ptr)   __get_user_check((x),(ptr),sizeof(*(ptr)))
 
#define put_user(x, ptr)   __put_user_check((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)))
 
#define __get_user(x, ptr)   __get_user_nocheck((x),(ptr),sizeof(*(ptr)))
 
#define __get_user_nocheck(x, ptr, size)
 
#define __get_user_check(x, ptr, size)
 
#define __get_user_size(x, ptr, size, retval)
 
#define __get_user_asm(x, addr, err, itype)
 
#define __put_user(x, ptr)   __put_user_nocheck((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)))
 
#define __put_user_nocheck(x, ptr, size)
 
#define __put_user_check(x, ptr, size)
 
#define __put_user_size(x, ptr, size, retval)
 
#define __m(x)   (*(struct __large_struct *)(x))
 
#define __put_user_asm(x, addr, err, itype)
 
#define __copy_user(to, from, size)
 
#define __copy_user_zeroing(to, from, size)
 
#define __copy_to_user(to, from, n)   __generic_copy_to_user_nocheck((to),(from),(n))
 
#define __copy_to_user_inatomic   __copy_to_user
 
#define __copy_from_user_inatomic   __copy_from_user
 
#define copy_to_user(to, from, n)
 
#define __copy_from_user(to, from, n)   __generic_copy_from_user_nocheck((to),(from),(n))
 
#define copy_from_user(to, from, n)
 
#define strlen_user(str)   strnlen_user(str, ~0UL >> 1)
 

Functions

int fixup_exception (struct pt_regs *regs)
 
long __get_user_bad (void)
 
void __put_user_bad (void)
 
unsigned long __generic_copy_to_user (void __user *, const void *, unsigned long)
 
unsigned long __generic_copy_from_user (void *, const void __user *, unsigned long)
 
long __must_check strncpy_from_user (char *dst, const char __user *src, long count)
 
long __must_check __strncpy_from_user (char *dst, const char __user *src, long count)
 
unsigned long __clear_user (void __user *mem, unsigned long len)
 
unsigned long clear_user (void __user *mem, unsigned long len)
 
long strnlen_user (const char __user *str, long n)
 

Macro Definition Documentation

#define __addr_ok (   addr)    ((unsigned long)(addr) < (current_thread_info()->addr_limit.seg))

Definition at line 59 of file uaccess.h.

#define __copy_from_user (   to,
  from,
  n 
)    __generic_copy_from_user_nocheck((to),(from),(n))

__copy_from_user: - Copy a block of data from user space, with less checking. * : Destination address, in kernel space. : Source address, in user space.
: Number of bytes to copy.

Context: User context only. This function may sleep.

Copy data from user space to kernel space. Caller must check the specified block with access_ok() before calling this function.

Returns number of bytes that could not be copied. On success, this will be zero.

If some data could not be copied, this function will pad the copied data to the requested size using zero bytes.

Definition at line 620 of file uaccess.h.

#define __copy_from_user_inatomic   __copy_from_user

Definition at line 583 of file uaccess.h.

#define __copy_to_user (   to,
  from,
  n 
)    __generic_copy_to_user_nocheck((to),(from),(n))

__copy_to_user: - Copy a block of data into user space, with less checking. : Destination address, in user space. : Source address, in kernel space.
: Number of bytes to copy.

Context: User context only. This function may sleep.

Copy data from kernel space to user space. Caller must check the specified block with access_ok() before calling this function.

Returns number of bytes that could not be copied. On success, this will be zero.

Definition at line 579 of file uaccess.h.

#define __copy_to_user_inatomic   __copy_to_user

Definition at line 582 of file uaccess.h.

#define __copy_user (   to,
  from,
  size 
)

Definition at line 424 of file uaccess.h.

#define __copy_user_zeroing (   to,
  from,
  size 
)

Definition at line 481 of file uaccess.h.

#define __get_user (   x,
  ptr 
)    __get_user_nocheck((x),(ptr),sizeof(*(ptr)))

__get_user: - Get a simple variable from user space, with less checking. : Variable to store result. : Source address, in user space.

Context: User context only. This function may sleep.

This macro copies a single simple variable from user space to kernel space. It supports simple types like char and int, but not larger data types like structures or arrays.

must have pointer-to-simple-variable type, and the result of dereferencing must be assignable to without a cast.

Caller must check the pointer with access_ok() before calling this function.

Returns zero on success, or -EFAULT on error. On error, the variable is set to zero.

Definition at line 212 of file uaccess.h.

#define __get_user_asm (   x,
  addr,
  err,
  itype 
)
Value:
__asm__ __volatile__( \
" .fillinsn\n" \
"1: ld"itype" %1,@%2\n" \
" .fillinsn\n" \
"2:\n" \
".section .fixup,\"ax\"\n" \
" .balign 4\n" \
"3: ldi %0,%3\n" \
" seth r14,#high(2b)\n" \
" or3 r14,r14,#low(2b)\n" \
" jmp r14\n" \
".previous\n" \
".section __ex_table,\"a\"\n" \
" .balign 4\n" \
" .long 1b,3b\n" \
".previous" \
: "=&r" (err), "=&r" (x) \
: "r" (addr), "i" (-EFAULT), "0" (err) \
: "r14", "memory")

Definition at line 251 of file uaccess.h.

#define __get_user_check (   x,
  ptr,
  size 
)
Value:
({ \
long __gu_err = -EFAULT; \
unsigned long __gu_val = 0; \
const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \
if (access_ok(VERIFY_READ,__gu_addr,size)) \
__get_user_size(__gu_val,__gu_addr,(size),__gu_err); \
(x) = (__typeof__(*(ptr)))__gu_val; \
__gu_err; \
})

Definition at line 225 of file uaccess.h.

#define __get_user_nocheck (   x,
  ptr,
  size 
)
Value:
({ \
long __gu_err = 0; \
unsigned long __gu_val; \
might_sleep(); \
__get_user_size(__gu_val,(ptr),(size),__gu_err); \
(x) = (__typeof__(*(ptr)))__gu_val; \
__gu_err; \
})

Definition at line 215 of file uaccess.h.

#define __get_user_size (   x,
  ptr,
  size,
  retval 
)
Value:
do { \
retval = 0; \
__chk_user_ptr(ptr); \
switch (size) { \
case 1: __get_user_asm(x,ptr,retval,"ub"); break; \
case 2: __get_user_asm(x,ptr,retval,"uh"); break; \
case 4: __get_user_asm(x,ptr,retval,""); break; \
default: (x) = __get_user_bad(); \
} \
} while (0)

Definition at line 239 of file uaccess.h.

#define __m (   x)    (*(struct __large_struct *)(x))

Definition at line 383 of file uaccess.h.

#define __put_user (   x,
  ptr 
)    __put_user_nocheck((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)))

__put_user: - Write a simple value into user space, with less checking. : Value to copy to user space. : Destination address, in user space.

Context: User context only. This function may sleep.

This macro copies a single simple value from kernel space to user space. It supports simple types like char and int, but not larger data types like structures or arrays.

must have pointer-to-simple-variable type, and must be assignable to the result of dereferencing .

Caller must check the pointer with access_ok() before calling this function.

Returns zero on success, or -EFAULT on error.

Definition at line 291 of file uaccess.h.

#define __put_user_asm (   x,
  addr,
  err,
  itype 
)
Value:
__asm__ __volatile__( \
" .fillinsn\n" \
"1: st"itype" %1,@%2\n" \
" .fillinsn\n" \
"2:\n" \
".section .fixup,\"ax\"\n" \
" .balign 4\n" \
"3: ldi %0,%3\n" \
" seth r14,#high(2b)\n" \
" or3 r14,r14,#low(2b)\n" \
" jmp r14\n" \
".previous\n" \
".section __ex_table,\"a\"\n" \
" .balign 4\n" \
" .long 1b,3b\n" \
".previous" \
: "=&r" (err) \
: "r" (x), "r" (addr), "i" (-EFAULT), "0" (err) \
: "r14", "memory")

Definition at line 390 of file uaccess.h.

#define __put_user_check (   x,
  ptr,
  size 
)
Value:
({ \
long __pu_err = -EFAULT; \
__typeof__(*(ptr)) __user *__pu_addr = (ptr); \
if (access_ok(VERIFY_WRITE,__pu_addr,size)) \
__put_user_size((x),__pu_addr,(size),__pu_err); \
__pu_err; \
})

Definition at line 304 of file uaccess.h.

#define __put_user_nocheck (   x,
  ptr,
  size 
)
Value:
({ \
long __pu_err; \
might_sleep(); \
__put_user_size((x),(ptr),(size),__pu_err); \
__pu_err; \
})

Definition at line 295 of file uaccess.h.

#define __put_user_size (   x,
  ptr,
  size,
  retval 
)
Value:
do { \
retval = 0; \
__chk_user_ptr(ptr); \
switch (size) { \
case 1: __put_user_asm(x,ptr,retval,"b"); break; \
case 2: __put_user_asm(x,ptr,retval,"h"); break; \
case 4: __put_user_asm(x,ptr,retval,""); break; \
case 8: __put_user_u64((__typeof__(*ptr))(x),ptr,retval); break;\
default: __put_user_bad(); \
} \
} while (0)

Definition at line 369 of file uaccess.h.

#define __range_ok (   addr,
  size 
)
Value:
({ \
unsigned long flag, roksum; \
__chk_user_ptr(addr); \
asm ( \
" cmpu %1, %1 ; clear cbit\n" \
" addx %1, %3 ; set cbit if overflow\n" \
" subx %0, %0\n" \
" cmpu %4, %1\n" \
" subx %0, %5\n" \
: "=&r" (flag), "=r" (roksum) \
: "1" (addr), "r" ((int)(size)), \
"r" (current_thread_info()->addr_limit.seg), "r" (0) \
: "cbit" ); \
flag; })

Definition at line 71 of file uaccess.h.

#define copy_from_user (   to,
  from,
  n 
)
Value:
({ \
might_sleep(); \
__generic_copy_from_user((to),(from),(n)); \
})

copy_from_user: - Copy a block of data from user space. : Destination address, in kernel space. : Source address, in user space.
: Number of bytes to copy.

Context: User context only. This function may sleep.

Copy data from user space to kernel space.

Returns number of bytes that could not be copied. On success, this will be zero.

If some data could not be copied, this function will pad the copied data to the requested size using zero bytes.

Definition at line 639 of file uaccess.h.

#define copy_to_user (   to,
  from,
  n 
)
Value:
({ \
might_sleep(); \
__generic_copy_to_user((to),(from),(n)); \
})

copy_to_user: - Copy a block of data into user space. : Destination address, in user space. : Source address, in kernel space.
: Number of bytes to copy.

Context: User context only. This function may sleep.

Copy data from kernel space to user space.

Returns number of bytes that could not be copied. On success, this will be zero.

Definition at line 598 of file uaccess.h.

#define get_ds (   void)    (KERNEL_DS)

Definition at line 44 of file uaccess.h.

#define get_user (   x,
  ptr 
)    __get_user_check((x),(ptr),sizeof(*(ptr)))

get_user: - Get a simple variable from user space. : Variable to store result. : Source address, in user space.

Context: User context only. This function may sleep.

This macro copies a single simple variable from user space to kernel space. It supports simple types like char and int, but not larger data types like structures or arrays.

must have pointer-to-simple-variable type, and the result of dereferencing must be assignable to without a cast.

Returns zero on success, or -EFAULT on error. On error, the variable is set to zero.

Definition at line 170 of file uaccess.h.

#define KERNEL_DS   MAKE_MM_SEG(0xFFFFFFFF)

Definition at line 42 of file uaccess.h.

#define MAKE_MM_SEG (   s)    ((mm_segment_t) { (s) })

Definition at line 30 of file uaccess.h.

#define put_user (   x,
  ptr 
)    __put_user_check((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)))

put_user: - Write a simple value into user space. : Value to copy to user space. : Destination address, in user space.

Context: User context only. This function may sleep.

This macro copies a single simple value from kernel space to user space. It supports simple types like char and int, but not larger data types like structures or arrays.

must have pointer-to-simple-variable type, and must be assignable to the result of dereferencing .

Returns zero on success, or -EFAULT on error.

Definition at line 189 of file uaccess.h.

#define segment_eq (   a,
  b 
)    ((a).seg == (b).seg)

Definition at line 57 of file uaccess.h.

#define strlen_user (   str)    strnlen_user(str, ~0UL >> 1)

strlen_user: - Get the size of a string in user space. : The string to measure.

Context: User context only. This function may sleep.

Get the size of a NUL-terminated string in user space.

Returns the size of the string INCLUDING the terminating NUL. On exception, returns 0.

If there is a limit on the length of a valid string, you may wish to consider using strnlen_user() instead.

Definition at line 690 of file uaccess.h.

#define USER_DS   MAKE_MM_SEG(0xFFFFFFFF)

Definition at line 43 of file uaccess.h.

#define VERIFY_READ   0

Definition at line 19 of file uaccess.h.

#define VERIFY_WRITE   1

Definition at line 20 of file uaccess.h.

Function Documentation

unsigned long __clear_user ( void __user addr,
unsigned long  size 
)

__clear_user: - Zero a block of memory in user space, with less checking. : Destination address, in user space.
: Number of bytes to zero.

Zero a block of memory in user space. Caller must check the specified block with access_ok() before calling this function.

Returns number of bytes that could not be cleared. On success, this will be zero.

Definition at line 158 of file uaccess_with_memcpy.c.

unsigned long __generic_copy_from_user ( void ,
const void __user ,
unsigned  long 
)

Definition at line 24 of file usercopy.c.

unsigned long __generic_copy_to_user ( void __user ,
const void ,
unsigned  long 
)

Definition at line 15 of file usercopy.c.

long __get_user_bad ( void  )
void __put_user_bad ( void  )
long __must_check __strncpy_from_user ( char dst,
const char __user src,
long  count 
)

Definition at line 113 of file usercopy.c.

unsigned long clear_user ( void __user to,
unsigned long  n 
)

clear_user: - Zero a block of memory in user space. : Destination address, in user space.
: Number of bytes to zero.

Zero a block of memory in user space. Caller must check the specified block with access_ok() before calling this function.

Returns number of bytes that could not be cleared. On success, this will be zero.

clear_user: - Zero a block of memory in user space. : Destination address, in user space.
: Number of bytes to zero.

Zero a block of memory in user space.

Returns number of bytes that could not be cleared. On success, this will be zero.

Definition at line 224 of file usercopy.c.

int fixup_exception ( struct pt_regs regs)

Definition at line 7 of file extable.c.

long __must_check strncpy_from_user ( char dst,
const char __user src,
long  count 
)

strncpy_from_user: - Copy a NUL terminated string from userspace. : Destination address, in kernel space. This buffer must be at least bytes long. : Source address, in user space. : Maximum number of bytes to copy, including the trailing NUL.

Copies a NUL-terminated string from userspace to kernel space.

On success, returns the length of the string (not including the trailing NUL).

If access to userspace fails, returns -EFAULT (some data may have been copied).

If is smaller than the length of the string, copies bytes and returns .

Definition at line 20 of file uaccess.c.

long strnlen_user ( const char __user str,
long  count 
)

strnlen_user: - Get the size of a user string INCLUDING final NUL. : The string to measure. : Maximum count (including NUL character)

Context: User context only. This function may sleep.

Get the size of a NUL-terminated string in user space.

Returns the size of the string INCLUDING the terminating NUL. If the string is too long, returns 'count+1'. On exception (or invalid count), returns 0.

Definition at line 72 of file uaccess.c.