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/compiler.h>
#include <linux/thread_info.h>
#include <linux/string.h>
#include <asm/asm.h>
#include <asm/page.h>
#include <asm/smap.h>
#include <asm/uaccess_64.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(-1UL)
 
#define USER_DS   MAKE_MM_SEG(TASK_SIZE_MAX)
 
#define get_ds()   (KERNEL_DS)
 
#define get_fs()   (current_thread_info()->addr_limit)
 
#define set_fs(x)   (current_thread_info()->addr_limit = (x))
 
#define segment_eq(a, b)   ((a).seg == (b).seg)
 
#define user_addr_max()   (current_thread_info()->addr_limit.seg)
 
#define __addr_ok(addr)   ((unsigned long __force)(addr) < user_addr_max())
 
#define __range_not_ok(addr, size, limit)
 
#define access_ok(type, addr, size)   (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
 
#define ARCH_HAS_SORT_EXTABLE
 
#define ARCH_HAS_SEARCH_EXTABLE
 
#define __get_user_x(size, ret, x, ptr)
 
#define __get_user_8(__ret_gu, __val_gu, ptr)   __get_user_x(8, __ret_gu, __val_gu, ptr)
 
#define get_user(x, ptr)
 
#define __put_user_x(size, x, ptr, __ret_pu)
 
#define __put_user_asm_u64(x, ptr, retval, errret)   __put_user_asm(x, ptr, retval, "q", "", "er", errret)
 
#define __put_user_asm_ex_u64(x, addr)   __put_user_asm_ex(x, addr, "q", "", "er")
 
#define __put_user_x8(x, ptr, __ret_pu)   __put_user_x(8, x, ptr, __ret_pu)
 
#define __put_user_size(x, ptr, size, retval, errret)
 
#define put_user(x, ptr)
 
#define __get_user_asm_u64(x, ptr, retval, errret)   __get_user_asm(x, ptr, retval, "q", "", "=r", errret)
 
#define __get_user_asm_ex_u64(x, ptr)   __get_user_asm_ex(x, ptr, "q", "", "=r")
 
#define __get_user_size(x, ptr, size, retval, errret)
 
#define __get_user_asm(x, addr, err, itype, rtype, ltype, errret)
 
#define __get_user_size_ex(x, ptr, size)
 
#define __get_user_asm_ex(x, addr, itype, rtype, ltype)
 
#define __put_user_nocheck(x, ptr, size)
 
#define __get_user_nocheck(x, ptr, size)
 
#define __m(x)   (*(struct __large_struct __user *)(x))
 
#define __put_user_asm(x, addr, err, itype, rtype, ltype, errret)
 
#define __put_user_asm_ex(x, addr, itype, rtype, ltype)
 
#define uaccess_try
 
#define uaccess_catch(err)
 
#define __get_user(x, ptr)   __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
 
#define __put_user(x, ptr)   __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
 
#define __get_user_unaligned   __get_user
 
#define __put_user_unaligned   __put_user
 
#define get_user_try   uaccess_try
 
#define get_user_catch(err)   uaccess_catch(err)
 
#define get_user_ex(x, ptr)
 
#define put_user_try
 
#define put_user_catch(err)
 
#define put_user_ex(x, ptr)
 
#define ARCH_HAS_NOCACHE_UACCESS   1
 

Functions

int fixup_exception (struct pt_regs *regs)
 
int early_fixup_exception (unsigned long *ip)
 
int __get_user_1 (void)
 
int __get_user_2 (void)
 
int __get_user_4 (void)
 
int __get_user_8 (void)
 
int __get_user_bad (void)
 
void __put_user_bad (void)
 
void __put_user_1 (void)
 
void __put_user_2 (void)
 
void __put_user_4 (void)
 
void __put_user_8 (void)
 
unsigned long copy_from_user_nmi (void *to, const void __user *from, unsigned long n)
 
__must_check long strncpy_from_user (char *dst, const char __user *src, long count)
 
__must_check long strlen_user (const char __user *str)
 
__must_check long strnlen_user (const char __user *str, long n)
 
unsigned long __must_check clear_user (void __user *mem, unsigned long len)
 
unsigned long __must_check __clear_user (void __user *mem, unsigned long len)
 

Macro Definition Documentation

#define __addr_ok (   addr)    ((unsigned long __force)(addr) < user_addr_max())

Definition at line 37 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 501 of file uaccess.h.

#define __get_user_8 (   __ret_gu,
  __val_gu,
  ptr 
)    __get_user_x(8, __ret_gu, __val_gu, 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 157 of file uaccess.h.

#define __get_user_asm (   x,
  addr,
  err,
  itype,
  rtype,
  ltype,
  errret 
)
Value:
asm volatile(ASM_STAC "\n" \
"1: mov"itype" %2,%"rtype"1\n" \
"2: " ASM_CLAC "\n" \
".section .fixup,\"ax\"\n" \
"3: mov %3,%0\n" \
" xor"itype" %"rtype"1,%"rtype"1\n" \
" jmp 2b\n" \
".previous\n" \
_ASM_EXTABLE(1b, 3b) \
: "=r" (err), ltype(x) \
: "m" (__m(addr)), "i" (errret), "0" (err))

Definition at line 384 of file uaccess.h.

#define __get_user_asm_ex (   x,
  addr,
  itype,
  rtype,
  ltype 
)
Value:
asm volatile("1: mov"itype" %1,%"rtype"0\n" \
"2:\n" \
_ASM_EXTABLE_EX(1b, 2b) \
: ltype(x) : "m" (__m(addr)))

Definition at line 418 of file uaccess.h.

#define __get_user_asm_ex_u64 (   x,
  ptr 
)    __get_user_asm_ex(x, ptr, "q", "", "=r")

Definition at line 358 of file uaccess.h.

#define __get_user_asm_u64 (   x,
  ptr,
  retval,
  errret 
)    __get_user_asm(x, ptr, retval, "q", "", "=r", errret)

Definition at line 356 of file uaccess.h.

#define __get_user_nocheck (   x,
  ptr,
  size 
)
Value:
({ \
int __gu_err; \
unsigned long __gu_val; \
__get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
(x) = (__force __typeof__(*(ptr)))__gu_val; \
__gu_err; \
})

Definition at line 431 of file uaccess.h.

#define __get_user_size (   x,
  ptr,
  size,
  retval,
  errret 
)
Value:
do { \
retval = 0; \
__chk_user_ptr(ptr); \
switch (size) { \
case 1: \
__get_user_asm(x, ptr, retval, "b", "b", "=q", errret); \
break; \
case 2: \
__get_user_asm(x, ptr, retval, "w", "w", "=r", errret); \
break; \
case 4: \
__get_user_asm(x, ptr, retval, "l", "k", "=r", errret); \
break; \
case 8: \
__get_user_asm_u64(x, ptr, retval, errret); \
break; \
default: \
(x) = __get_user_bad(); \
} \
} while (0)

Definition at line 362 of file uaccess.h.

#define __get_user_size_ex (   x,
  ptr,
  size 
)
Value:
do { \
__chk_user_ptr(ptr); \
switch (size) { \
case 1: \
__get_user_asm_ex(x, ptr, "b", "b", "=q"); \
break; \
case 2: \
__get_user_asm_ex(x, ptr, "w", "w", "=r"); \
break; \
case 4: \
__get_user_asm_ex(x, ptr, "l", "k", "=r"); \
break; \
case 8: \
__get_user_asm_ex_u64(x, ptr); \
break; \
default: \
(x) = __get_user_bad(); \
} \
} while (0)

Definition at line 397 of file uaccess.h.

#define __get_user_unaligned   __get_user

Definition at line 527 of file uaccess.h.

#define __get_user_x (   size,
  ret,
  x,
  ptr 
)
Value:
asm volatile("call __get_user_" #size \
: "=a" (ret), "=d" (x) \
: "0" (ptr)) \

Definition at line 128 of file uaccess.h.

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

Definition at line 442 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 524 of file uaccess.h.

#define __put_user_asm (   x,
  addr,
  err,
  itype,
  rtype,
  ltype,
  errret 
)
Value:
asm volatile(ASM_STAC "\n" \
"1: mov"itype" %"rtype"1,%2\n" \
"2: " ASM_CLAC "\n" \
".section .fixup,\"ax\"\n" \
"3: mov %3,%0\n" \
" jmp 2b\n" \
".previous\n" \
_ASM_EXTABLE(1b, 3b) \
: "=r"(err) \
: ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))

Definition at line 449 of file uaccess.h.

#define __put_user_asm_ex (   x,
  addr,
  itype,
  rtype,
  ltype 
)
Value:
asm volatile("1: mov"itype" %"rtype"0,%1\n" \
"2:\n" \
_ASM_EXTABLE_EX(1b, 2b) \
: : ltype(x), "m" (__m(addr)))

Definition at line 461 of file uaccess.h.

#define __put_user_asm_ex_u64 (   x,
  addr 
)    __put_user_asm_ex(x, addr, "q", "", "er")

Definition at line 224 of file uaccess.h.

#define __put_user_asm_u64 (   x,
  ptr,
  retval,
  errret 
)    __put_user_asm(x, ptr, retval, "q", "", "er", errret)

Definition at line 222 of file uaccess.h.

#define __put_user_nocheck (   x,
  ptr,
  size 
)
Value:
({ \
int __pu_err; \
__put_user_size((x), (ptr), (size), __pu_err, -EFAULT); \
__pu_err; \
})

Definition at line 424 of file uaccess.h.

#define __put_user_size (   x,
  ptr,
  size,
  retval,
  errret 
)
Value:
do { \
__typeof__(*(ptr))__pus_tmp = x; \
retval = 0; \
\
if (unlikely(__copy_to_user_ll(ptr, &__pus_tmp, size) != 0)) \
retval = errret; \
} while (0)

Definition at line 331 of file uaccess.h.

#define __put_user_unaligned   __put_user

Definition at line 528 of file uaccess.h.

#define __put_user_x (   size,
  x,
  ptr,
  __ret_pu 
)
Value:
asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
: "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")

Definition at line 188 of file uaccess.h.

#define __put_user_x8 (   x,
  ptr,
  __ret_pu 
)    __put_user_x(8, x, ptr, __ret_pu)

Definition at line 226 of file uaccess.h.

#define __range_not_ok (   addr,
  size,
  limit 
)
Value:
({ \
unsigned long flag, roksum; \
__chk_user_ptr(addr); \
asm("add %3,%1 ; sbb %0,%0 ; cmp %1,%4 ; sbb $0,%0" \
: "=&r" (flag), "=r" (roksum) \
: "1" (addr), "g" ((long)(size)), \
"rm" (limit)); \
})

Definition at line 50 of file uaccess.h.

#define access_ok (   type,
  addr,
  size 
)    (likely(__range_not_ok(addr, size, user_addr_max()) == 0))

access_ok: - Checks if a user space pointer is valid : Type of access: VERIFY_READ or VERIFY_WRITE. Note that VERIFY_WRITE is a superset of VERIFY_READ - if it is safe to write to a block, it is always safe to read from it. : User space pointer to start of block to check : Size of block to check

Context: User context only. This function may sleep.

Checks if a pointer to a block of memory in user space is valid.

Returns true (nonzero) if the memory block may be valid, false (zero) if it is definitely invalid.

Note that, depending on architecture, this function probably just checks that the pointer is in the user space range - after calling this function, memory access functions may still return -EFAULT.

Definition at line 80 of file uaccess.h.

#define ARCH_HAS_NOCACHE_UACCESS   1

Definition at line 589 of file uaccess.h.

#define ARCH_HAS_SEARCH_EXTABLE

Definition at line 102 of file uaccess.h.

#define ARCH_HAS_SORT_EXTABLE

Definition at line 101 of file uaccess.h.

#define get_ds (   void)    (KERNEL_DS)

Definition at line 30 of file uaccess.h.

#define get_fs (   void)    (current_thread_info()->addr_limit)

Definition at line 31 of file uaccess.h.

#define get_user (   x,
  ptr 
)
Value:
({ \
int __ret_gu; \
unsigned long __val_gu; \
__chk_user_ptr(ptr); \
might_fault(); \
switch (sizeof(*(ptr))) { \
case 1: \
__get_user_x(1, __ret_gu, __val_gu, ptr); \
break; \
case 2: \
__get_user_x(2, __ret_gu, __val_gu, ptr); \
break; \
case 4: \
__get_user_x(4, __ret_gu, __val_gu, ptr); \
break; \
case 8: \
__get_user_8(__ret_gu, __val_gu, ptr); \
break; \
default: \
__get_user_x(X, __ret_gu, __val_gu, ptr); \
break; \
} \
(x) = (__typeof__(*(ptr)))__val_gu; \
__ret_gu; \
})

Definition at line 161 of file uaccess.h.

#define get_user_catch (   err)    uaccess_catch(err)

Definition at line 538 of file uaccess.h.

#define get_user_ex (   x,
  ptr 
)
Value:
do { \
unsigned long __gue_val; \
__get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
(x) = (__force __typeof__(*(ptr)))__gue_val; \
} while (0)

Definition at line 540 of file uaccess.h.

#define get_user_try   uaccess_try

Definition at line 537 of file uaccess.h.

#define KERNEL_DS   MAKE_MM_SEG(-1UL)

Definition at line 27 of file uaccess.h.

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

Definition at line 25 of file uaccess.h.

#define put_user (   x,
  ptr 
)
Value:
({ \
int __ret_pu; \
__typeof__(*(ptr))__pus_tmp = x; \
__ret_pu = 0; \
if (unlikely(__copy_to_user_ll(ptr, &__pus_tmp, \
sizeof(*(ptr))) != 0)) \
__ret_pu = -EFAULT; \
__ret_pu; \
})

Definition at line 340 of file uaccess.h.

#define put_user_catch (   err)
Value:
(err) |= __uaccess_err; \
} while (0)

Definition at line 559 of file uaccess.h.

#define put_user_ex (   x,
  ptr 
)
Value:
do { \
__uaccess_err |= __put_user(x, ptr); \
} while (0)

Definition at line 563 of file uaccess.h.

#define put_user_try
Value:
do { \
int __uaccess_err = 0;

Definition at line 556 of file uaccess.h.

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

Definition at line 34 of file uaccess.h.

#define set_fs (   x)    (current_thread_info()->addr_limit = (x))

Definition at line 32 of file uaccess.h.

#define uaccess_catch (   err)
Value:
clac(); \
(err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
} while (0)

Definition at line 475 of file uaccess.h.

#define uaccess_try
Value:
do { \
current_thread_info()->uaccess_err = 0; \
stac(); \
barrier();

Definition at line 470 of file uaccess.h.

#define user_addr_max ( )    (current_thread_info()->addr_limit.seg)

Definition at line 36 of file uaccess.h.

#define USER_DS   MAKE_MM_SEG(TASK_SIZE_MAX)

Definition at line 28 of file uaccess.h.

#define VERIFY_READ   0

Definition at line 14 of file uaccess.h.

#define VERIFY_WRITE   1

Definition at line 15 of file uaccess.h.

Function Documentation

unsigned long __must_check __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.

int __get_user_1 ( void  )
int __get_user_2 ( void  )
int __get_user_4 ( void  )
int __get_user_8 ( void  )
int __get_user_bad ( void  )
void __put_user_1 ( void  )
void __put_user_2 ( void  )
void __put_user_4 ( void  )
void __put_user_8 ( void  )
void __put_user_bad ( void  )
unsigned long __must_check 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.

unsigned long copy_from_user_nmi ( void to,
const void __user from,
unsigned long  n 
)

Definition at line 17 of file usercopy.c.

int early_fixup_exception ( unsigned long ip)

Definition at line 53 of file extable.c.

int fixup_exception ( struct pt_regs regs)

Definition at line 7 of file extable.c.

__must_check long strlen_user ( const char __user str)

strlen_user: - Get the size of a user string INCLUDING final NUL. : 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 126 of file strnlen_user.c.

__must_check long 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.

__must_check 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.