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/sched.h>

Go to the source code of this file.

Data Structures

struct  __large_struct
 
struct  exception_table_entry
 
union  exception_table_entry::exception_fixup
 

Macros

#define KERNEL_DS   ((mm_segment_t) { 0UL })
 
#define USER_DS   ((mm_segment_t) { -0x40000000000UL })
 
#define VERIFY_READ   0
 
#define VERIFY_WRITE   1
 
#define get_fs()   (current_thread_info()->addr_limit)
 
#define get_ds()   (KERNEL_DS)
 
#define set_fs(x)   (current_thread_info()->addr_limit = (x))
 
#define segment_eq(a, b)   ((a).seg == (b).seg)
 
#define __access_ok(addr, size, segment)   (((segment).seg & (addr | size | (addr+size))) == 0)
 
#define access_ok(type, addr, size)
 
#define put_user(x, ptr)   __put_user_check((__typeof__(*(ptr)))(x),(ptr),sizeof(*(ptr)),get_fs())
 
#define get_user(x, ptr)   __get_user_check((x),(ptr),sizeof(*(ptr)),get_fs())
 
#define __put_user(x, ptr)   __put_user_nocheck((__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, segment)
 
#define __m(x)   (*(struct __large_struct __user *)(x))
 
#define __get_user_64(addr)
 
#define __get_user_32(addr)
 
#define __get_user_16(addr)
 
#define __get_user_8(addr)
 
#define __put_user_nocheck(x, ptr, size)
 
#define __put_user_check(x, ptr, size, segment)
 
#define __put_user_64(x, addr)
 
#define __put_user_32(x, addr)
 
#define __put_user_16(x, addr)
 
#define __put_user_8(x, addr)
 
#define __module_address(sym)
 
#define __module_call(ra, arg, sym)   "bsr $" #ra "," #sym " !samegp"
 
#define __copy_to_user(to, from, n)
 
#define __copy_from_user(to, from, n)
 
#define __copy_to_user_inatomic   __copy_to_user
 
#define __copy_from_user_inatomic   __copy_from_user
 
#define user_addr_max()   (segment_eq(get_fs(), USER_DS) ? TASK_SIZE : ~0UL)
 
#define fixup_exception(map_reg, _fixup, pc)
 
#define ARCH_HAS_SORT_EXTABLE
 
#define ARCH_HAS_SEARCH_EXTABLE
 

Functions

void __get_user_unknown (void)
 
void __put_user_unknown (void)
 
void __copy_user (void)
 
long __copy_tofrom_user_nocheck (void *to, const void *from, long len)
 
long __copy_tofrom_user (void *to, const void *from, long len, const void __user *validate)
 
long copy_to_user (void __user *to, const void *from, long n)
 
long copy_from_user (void *to, const void __user *from, long n)
 
void __do_clear_user (void)
 
long __clear_user (void __user *to, long len)
 
long clear_user (void __user *to, long len)
 
long strncpy_from_user (char *dest, 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)
 

Macro Definition Documentation

#define __access_ok (   addr,
  size,
  segment 
)    (((segment).seg & (addr | size | (addr+size))) == 0)

Definition at line 42 of file uaccess.h.

#define __copy_from_user (   to,
  from,
  n 
)
Value:
({ \
__chk_user_ptr(from); \
__copy_tofrom_user_nocheck((to),(__force void *)(from),(n)); \
})

Definition at line 387 of file uaccess.h.

#define __copy_from_user_inatomic   __copy_from_user

Definition at line 394 of file uaccess.h.

#define __copy_to_user (   to,
  from,
  n 
)
Value:
({ \
__chk_user_ptr(to); \
__copy_tofrom_user_nocheck((__force void *)(to),(from),(n)); \
})

Definition at line 382 of file uaccess.h.

#define __copy_to_user_inatomic   __copy_to_user

Definition at line 393 of file uaccess.h.

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

Definition at line 75 of file uaccess.h.

#define __get_user_16 (   addr)
Value:
{ \
long __gu_tmp; \
__asm__("1: ldq_u %0,0(%3)\n" \
"2: ldq_u %1,1(%3)\n" \
" extwl %0,%3,%0\n" \
" extwh %1,%3,%1\n" \
" or %0,%1,%0\n" \
"3:\n" \
".section __ex_table,\"a\"\n" \
" .long 1b - .\n" \
" lda %0, 3b-1b(%2)\n" \
" .long 2b - .\n" \
" lda %0, 3b-2b(%2)\n" \
".previous" \
: "=&r"(__gu_val), "=&r"(__gu_tmp), "=r"(__gu_err) \
: "r"(addr), "2"(__gu_err)); \
}

Definition at line 171 of file uaccess.h.

#define __get_user_32 (   addr)
Value:
__asm__("1: ldl %0,%2\n" \
"2:\n" \
".section __ex_table,\"a\"\n" \
" .long 1b - .\n" \
" lda %0, 2b-1b(%1)\n" \
".previous" \
: "=r"(__gu_val), "=r"(__gu_err) \
: "m"(__m(addr)), "1"(__gu_err))

Definition at line 135 of file uaccess.h.

#define __get_user_64 (   addr)
Value:
__asm__("1: ldq %0,%2\n" \
"2:\n" \
".section __ex_table,\"a\"\n" \
" .long 1b - .\n" \
" lda %0, 2b-1b(%1)\n" \
".previous" \
: "=r"(__gu_val), "=r"(__gu_err) \
: "m"(__m(addr)), "1"(__gu_err))

Definition at line 125 of file uaccess.h.

#define __get_user_8 (   addr)
Value:
__asm__("1: ldq_u %0,0(%2)\n" \
" extbl %0,%2,%0\n" \
"2:\n" \
".section __ex_table,\"a\"\n" \
" .long 1b - .\n" \
" lda %0, 2b-1b(%1)\n" \
".previous" \
: "=&r"(__gu_val), "=r"(__gu_err) \
: "r"(addr), "1"(__gu_err))

Definition at line 190 of file uaccess.h.

#define __get_user_check (   x,
  ptr,
  size,
  segment 
)
Value:
({ \
long __gu_err = -EFAULT; \
unsigned long __gu_val = 0; \
const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \
if (__access_ok((unsigned long)__gu_addr,size,segment)) { \
__gu_err = 0; \
switch (size) { \
case 1: __get_user_8(__gu_addr); break; \
case 2: __get_user_16(__gu_addr); break; \
case 4: __get_user_32(__gu_addr); break; \
case 8: __get_user_64(__gu_addr); break; \
default: __get_user_unknown(); break; \
} \
} \
(x) = (__typeof__(*(ptr))) __gu_val; \
__gu_err; \
})

Definition at line 103 of file uaccess.h.

#define __get_user_nocheck (   x,
  ptr,
  size 
)
Value:
({ \
long __gu_err = 0; \
unsigned long __gu_val; \
__chk_user_ptr(ptr); \
switch (size) { \
case 1: __get_user_8(ptr); break; \
case 2: __get_user_16(ptr); break; \
case 4: __get_user_32(ptr); break; \
case 8: __get_user_64(ptr); break; \
default: __get_user_unknown(); break; \
} \
(x) = (__typeof__(*(ptr))) __gu_val; \
__gu_err; \
})

Definition at line 87 of file uaccess.h.

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

Definition at line 123 of file uaccess.h.

#define __module_address (   sym)

Definition at line 351 of file uaccess.h.

#define __module_call (   ra,
  arg,
  sym 
)    "bsr $" #ra "," #sym " !samegp"

Definition at line 352 of file uaccess.h.

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

Definition at line 73 of file uaccess.h.

#define __put_user_16 (   x,
  addr 
)
Value:
{ \
long __pu_tmp1, __pu_tmp2, __pu_tmp3, __pu_tmp4; \
__asm__ __volatile__( \
"1: ldq_u %2,1(%5)\n" \
"2: ldq_u %1,0(%5)\n" \
" inswh %6,%5,%4\n" \
" inswl %6,%5,%3\n" \
" mskwh %2,%5,%2\n" \
" mskwl %1,%5,%1\n" \
" or %2,%4,%2\n" \
" or %1,%3,%1\n" \
"3: stq_u %2,1(%5)\n" \
"4: stq_u %1,0(%5)\n" \
"5:\n" \
".section __ex_table,\"a\"\n" \
" .long 1b - .\n" \
" lda $31, 5b-1b(%0)\n" \
" .long 2b - .\n" \
" lda $31, 5b-2b(%0)\n" \
" .long 3b - .\n" \
" lda $31, 5b-3b(%0)\n" \
" .long 4b - .\n" \
" lda $31, 5b-4b(%0)\n" \
".previous" \
: "=r"(__pu_err), "=&r"(__pu_tmp1), \
"=&r"(__pu_tmp2), "=&r"(__pu_tmp3), \
"=&r"(__pu_tmp4) \
: "r"(addr), "r"((unsigned long)(x)), "0"(__pu_err)); \
}

Definition at line 286 of file uaccess.h.

#define __put_user_32 (   x,
  addr 
)
Value:
__asm__ __volatile__("1: stl %r2,%1\n" \
"2:\n" \
".section __ex_table,\"a\"\n" \
" .long 1b - .\n" \
" lda $31,2b-1b(%0)\n" \
".previous" \
: "=r"(__pu_err) \
: "m"(__m(addr)), "rJ"(x), "0"(__pu_err))

Definition at line 250 of file uaccess.h.

#define __put_user_64 (   x,
  addr 
)
Value:
__asm__ __volatile__("1: stq %r2,%1\n" \
"2:\n" \
".section __ex_table,\"a\"\n" \
" .long 1b - .\n" \
" lda $31,2b-1b(%0)\n" \
".previous" \
: "=r"(__pu_err) \
: "m" (__m(addr)), "rJ" (x), "0"(__pu_err))

Definition at line 240 of file uaccess.h.

#define __put_user_8 (   x,
  addr 
)
Value:
{ \
long __pu_tmp1, __pu_tmp2; \
__asm__ __volatile__( \
"1: ldq_u %1,0(%4)\n" \
" insbl %3,%4,%2\n" \
" mskbl %1,%4,%1\n" \
" or %1,%2,%1\n" \
"2: stq_u %1,0(%4)\n" \
"3:\n" \
".section __ex_table,\"a\"\n" \
" .long 1b - .\n" \
" lda $31, 3b-1b(%0)\n" \
" .long 2b - .\n" \
" lda $31, 3b-2b(%0)\n" \
".previous" \
: "=r"(__pu_err), \
"=&r"(__pu_tmp1), "=&r"(__pu_tmp2) \
: "r"((unsigned long)(x)), "r"(addr), "0"(__pu_err)); \
}

Definition at line 317 of file uaccess.h.

#define __put_user_check (   x,
  ptr,
  size,
  segment 
)
Value:
({ \
long __pu_err = -EFAULT; \
__typeof__(*(ptr)) __user *__pu_addr = (ptr); \
if (__access_ok((unsigned long)__pu_addr,size,segment)) { \
__pu_err = 0; \
switch (size) { \
case 1: __put_user_8(x,__pu_addr); break; \
case 2: __put_user_16(x,__pu_addr); break; \
case 4: __put_user_32(x,__pu_addr); break; \
case 8: __put_user_64(x,__pu_addr); break; \
default: __put_user_unknown(); break; \
} \
} \
__pu_err; \
})

Definition at line 218 of file uaccess.h.

#define __put_user_nocheck (   x,
  ptr,
  size 
)
Value:
({ \
long __pu_err = 0; \
__chk_user_ptr(ptr); \
switch (size) { \
case 1: __put_user_8(x,ptr); break; \
case 2: __put_user_16(x,ptr); break; \
case 4: __put_user_32(x,ptr); break; \
case 8: __put_user_64(x,ptr); break; \
default: __put_user_unknown(); break; \
} \
__pu_err; \
})

Definition at line 204 of file uaccess.h.

#define access_ok (   type,
  addr,
  size 
)
Value:
({ \
__chk_user_ptr(addr); \
__access_ok(((unsigned long)(addr)),(size),get_fs()); \
})

Definition at line 45 of file uaccess.h.

#define ARCH_HAS_SEARCH_EXTABLE

Definition at line 487 of file uaccess.h.

#define ARCH_HAS_SORT_EXTABLE

Definition at line 486 of file uaccess.h.

#define fixup_exception (   map_reg,
  _fixup,
  pc 
)
Value:
({ \
if ((_fixup)->fixup.bits.valreg != 31) \
map_reg((_fixup)->fixup.bits.valreg) = 0; \
if ((_fixup)->fixup.bits.errreg != 31) \
map_reg((_fixup)->fixup.bits.errreg) = -EFAULT; \
(pc) + (_fixup)->fixup.bits.nextinsn; \
})

Definition at line 477 of file uaccess.h.

#define get_ds (   void)    (KERNEL_DS)

Definition at line 27 of file uaccess.h.

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

Definition at line 26 of file uaccess.h.

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

Definition at line 65 of file uaccess.h.

#define KERNEL_DS   ((mm_segment_t) { 0UL })

Definition at line 20 of file uaccess.h.

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

Definition at line 63 of file uaccess.h.

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

Definition at line 30 of file uaccess.h.

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

Definition at line 28 of file uaccess.h.

#define user_addr_max ( )    (segment_eq(get_fs(), USER_DS) ? TASK_SIZE : ~0UL)

Definition at line 436 of file uaccess.h.

#define USER_DS   ((mm_segment_t) { -0x40000000000UL })

Definition at line 21 of file uaccess.h.

#define VERIFY_READ   0

Definition at line 23 of file uaccess.h.

#define VERIFY_WRITE   1

Definition at line 24 of file uaccess.h.

Function Documentation

long __clear_user ( void __user to,
long  len 
)
inline

Definition at line 412 of file uaccess.h.

long __copy_tofrom_user ( void to,
const void from,
long  len,
const void __user validate 
)
inline

Definition at line 375 of file uaccess.h.

long __copy_tofrom_user_nocheck ( void to,
const void from,
long  len 
)
inline

Definition at line 358 of file uaccess.h.

void __copy_user ( void  )
void __do_clear_user ( void  )
void __get_user_unknown ( void  )
void __put_user_unknown ( void  )
long clear_user ( void __user to,
long  len 
)
inline

Definition at line 426 of file uaccess.h.

long copy_from_user ( void to,
const void __user from,
long  n 
)
inline

Definition at line 404 of file uaccess.h.

long copy_to_user ( void __user to,
const void from,
long  n 
)
inline

Definition at line 398 of file uaccess.h.

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

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.