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  mm_segment_t
 
struct  exception_table_entry
 

Macros

#define VERIFY_READ   0
 
#define VERIFY_WRITE   1
 
#define MAKE_MM_SEG(s)   ((mm_segment_t) { (s) })
 
#define segment_eq(a, b)   ((a).is_user_space == (b).is_user_space)
 
#define USER_ADDR_LIMIT   0x80000000
 
#define KERNEL_DS   MAKE_MM_SEG(0)
 
#define USER_DS   MAKE_MM_SEG(1)
 
#define get_ds()   (KERNEL_DS)
 
#define __range_ok(addr, size)
 
#define access_ok(type, addr, size)   (likely(__range_ok(addr, size) == 0))
 
#define __copy_to_user_inatomic   __copy_to_user
 
#define __copy_from_user_inatomic   __copy_from_user
 
#define put_user(x, ptr)   __put_user_check((x),(ptr),sizeof(*(ptr)))
 
#define get_user(x, ptr)   __get_user_check((x),(ptr),sizeof(*(ptr)))
 
#define __put_user(x, ptr)   __put_user_nocheck((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_asm(suffix, __gu_val, ptr, __gu_err)
 
#define __put_user_nocheck(x, ptr, size)
 
#define __put_user_check(x, ptr, size)
 
#define __put_user_asm(suffix, ptr, __pu_val, __gu_err)
 
#define strlen_user(s)   strnlen_user(s, ~0UL >> 1)
 

Functions

__kernel_size_t __copy_user (void *to, const void *from, __kernel_size_t n)
 
__kernel_size_t copy_to_user (void __user *to, const void *from, __kernel_size_t n)
 
__kernel_size_t copy_from_user (void *to, const void __user *from, __kernel_size_t n)
 
int __get_user_bad (void)
 
int __put_user_bad (void)
 
__kernel_size_t clear_user (void __user *addr, __kernel_size_t size)
 
__kernel_size_t __clear_user (void __user *addr, __kernel_size_t size)
 
long strncpy_from_user (char *dst, const char __user *src, long count)
 
long __strncpy_from_user (char *dst, const char __user *src, long count)
 
long strnlen_user (const char __user *__s, long __n)
 
long __strnlen_user (const char __user *__s, long __n)
 

Macro Definition Documentation

#define __copy_from_user_inatomic   __copy_from_user

Definition at line 93 of file uaccess.h.

#define __copy_to_user_inatomic   __copy_to_user

Definition at line 92 of file uaccess.h.

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

Definition at line 176 of file uaccess.h.

#define __get_user_asm (   suffix,
  __gu_val,
  ptr,
  __gu_err 
)
Value:
asm volatile( \
"1: ld." suffix " %1, %3 \n" \
"2: \n" \
" .subsection 1 \n" \
"3: mov %0, %4 \n" \
" rjmp 2b \n" \
" .subsection 0 \n" \
" .section __ex_table, \"a\" \n" \
" .long 1b, 3b \n" \
" .previous \n" \
: "=r"(__gu_err), "=r"(__gu_val) \
: "0"(__gu_err), "m"(*(ptr)), "i"(-EFAULT))

Definition at line 229 of file uaccess.h.

#define __get_user_check (   x,
  ptr,
  size 
)
Value:
({ \
unsigned long __gu_val = 0; \
const typeof(*(ptr)) __user * __gu_addr = (ptr); \
int __gu_err = 0; \
\
if (access_ok(VERIFY_READ, __gu_addr, size)) { \
switch (size) { \
case 1: \
__get_user_asm("ub", __gu_val, __gu_addr, \
__gu_err); \
break; \
case 2: \
__get_user_asm("uh", __gu_val, __gu_addr, \
__gu_err); \
break; \
case 4: \
__get_user_asm("w", __gu_val, __gu_addr, \
__gu_err); \
break; \
default: \
__gu_err = __get_user_bad(); \
break; \
} \
} else { \
__gu_err = -EFAULT; \
} \
x = (typeof(*(ptr)))__gu_val; \
__gu_err; \
})

Definition at line 198 of file uaccess.h.

#define __get_user_nocheck (   x,
  ptr,
  size 
)
Value:
({ \
unsigned long __gu_val = 0; \
int __gu_err = 0; \
\
switch (size) { \
case 1: __get_user_asm("ub", __gu_val, ptr, __gu_err); break; \
case 2: __get_user_asm("uh", __gu_val, ptr, __gu_err); break; \
case 4: __get_user_asm("w", __gu_val, ptr, __gu_err); break; \
default: __gu_err = __get_user_bad(); break; \
} \
\
x = (typeof(*(ptr)))__gu_val; \
__gu_err; \
})

Definition at line 182 of file uaccess.h.

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

Definition at line 153 of file uaccess.h.

#define __put_user_asm (   suffix,
  ptr,
  __pu_val,
  __gu_err 
)
Value:
asm volatile( \
"1: st." suffix " %1, %3 \n" \
"2: \n" \
" .subsection 1 \n" \
"3: mov %0, %4 \n" \
" rjmp 2b \n" \
" .subsection 0 \n" \
" .section __ex_table, \"a\" \n" \
" .long 1b, 3b \n" \
" .previous \n" \
: "=r"(__gu_err), "=m"(*(ptr)) \
: "0"(__gu_err), "r"(__pu_val), "i"(-EFAULT))

Definition at line 294 of file uaccess.h.

#define __put_user_check (   x,
  ptr,
  size 
)

Definition at line 259 of file uaccess.h.

#define __put_user_nocheck (   x,
  ptr,
  size 
)
Value:
({ \
typeof(*(ptr)) __pu_val; \
int __pu_err = 0; \
\
__pu_val = (x); \
switch (size) { \
case 1: __put_user_asm("b", ptr, __pu_val, __pu_err); break; \
case 2: __put_user_asm("h", ptr, __pu_val, __pu_err); break; \
case 4: __put_user_asm("w", ptr, __pu_val, __pu_err); break; \
case 8: __put_user_asm("d", ptr, __pu_val, __pu_err); break; \
default: __pu_err = __put_user_bad(); break; \
} \
__pu_err; \
})

Definition at line 243 of file uaccess.h.

#define __range_ok (   addr,
  size 
)
Value:
(test_thread_flag(TIF_USERSPACE) \
&& (((unsigned long)(addr) >= 0x80000000) \
|| ((unsigned long)(size) > 0x80000000) \
|| (((unsigned long)(addr) + (unsigned long)(size)) > 0x80000000)))

Definition at line 63 of file uaccess.h.

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

Definition at line 69 of file uaccess.h.

#define get_ds (   void)    (KERNEL_DS)

Definition at line 36 of file uaccess.h.

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

Definition at line 131 of file uaccess.h.

#define KERNEL_DS   MAKE_MM_SEG(0)

Definition at line 33 of file uaccess.h.

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

Definition at line 28 of file uaccess.h.

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

Definition at line 111 of file uaccess.h.

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

Definition at line 29 of file uaccess.h.

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

Definition at line 317 of file uaccess.h.

#define USER_ADDR_LIMIT   0x80000000

Definition at line 31 of file uaccess.h.

#define USER_DS   MAKE_MM_SEG(1)

Definition at line 34 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

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

__kernel_size_t __copy_user ( void to,
const void from,
__kernel_size_t  n 
)

Definition at line 27 of file nommu.c.

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

Definition at line 113 of file usercopy.c.

long __strnlen_user ( const char __user __s,
long  __n 
)
__kernel_size_t 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.

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

Definition at line 224 of file usercopy.c.

__kernel_size_t copy_from_user ( void to,
const void __user from,
__kernel_size_t  n 
)

Definition at line 12 of file usercopy_64.c.

__kernel_size_t copy_to_user ( void __user to,
const void from,
unsigned long  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 21 of file usercopy_64.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.

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.