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 <linux/prefetch.h>
#include <linux/string.h>
#include <asm/page.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 KERNEL_DS   (~0UL)
 
#define get_ds()   (KERNEL_DS)
 
#define USER_DS   (TASK_SIZE)
 
#define get_fs()   (current_thread_info()->addr_limit)
 
#define set_fs(x)   (current_thread_info()->addr_limit = (x))
 
#define segment_eq(a, b)   ((a) == (b))
 
#define __range_ok(addr, size)   (size <= get_fs() && addr <= (get_fs()-size))
 
#define __addr_ok(addr)   ((unsigned long) addr < get_fs())
 
#define access_ok(type, addr, size)   __range_ok((unsigned long)addr, (unsigned long)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 __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, op)
 
#define __put_user_asm2(x, addr, err)
 
#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, op)
 
#define __get_user_asm2(x, addr, err)
 
#define __copy_from_user(to, from, size)   __copy_tofrom_user(to, from, size)
 
#define __copy_to_user(to, from, size)   __copy_tofrom_user(to, from, size)
 
#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)
 

Functions

unsigned long search_exception_table (unsigned long)
 
void sort_exception_table (void)
 
long __put_user_bad (void)
 
long __get_user_bad (void)
 
unsigned long __must_check __copy_tofrom_user (void *to, const void *from, unsigned long size)
 
unsigned long __clear_user (void *addr, unsigned long size)
 
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 __addr_ok (   addr)    ((unsigned long) addr < get_fs())

Definition at line 63 of file uaccess.h.

#define __copy_from_user (   to,
  from,
  size 
)    __copy_tofrom_user(to, from, size)

Definition at line 265 of file uaccess.h.

#define __copy_from_user_inatomic   __copy_from_user

Definition at line 271 of file uaccess.h.

#define __copy_to_user (   to,
  from,
  size 
)    __copy_tofrom_user(to, from, size)

Definition at line 267 of file uaccess.h.

#define __copy_to_user_inatomic   __copy_to_user

Definition at line 270 of file uaccess.h.

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

Definition at line 112 of file uaccess.h.

#define __get_user_asm (   x,
  addr,
  err,
  op 
)
Value:
__asm__ __volatile__( \
"1: "op" %1,0(%2)\n" \
"2:\n" \
".section .fixup,\"ax\"\n" \
"3: l.addi %0,r0,%3\n" \
" l.addi %1,r0,0\n" \
" l.j 2b\n" \
" l.nop\n" \
".previous\n" \
".section __ex_table,\"a\"\n" \
" .align 2\n" \
" .long 1b,3b\n" \
".previous" \
: "=r"(err), "=r"(x) \
: "r"(addr), "i"(-EFAULT), "0"(err))

Definition at line 223 of file uaccess.h.

#define __get_user_asm2 (   x,
  addr,
  err 
)
Value:
__asm__ __volatile__( \
"1: l.lwz %1,0(%2)\n" \
"2: l.lwz %H1,4(%2)\n" \
"3:\n" \
".section .fixup,\"ax\"\n" \
"4: l.addi %0,r0,%3\n" \
" l.addi %1,r0,0\n" \
" l.addi %H1,r0,0\n" \
" l.j 3b\n" \
" l.nop\n" \
".previous\n" \
".section __ex_table,\"a\"\n" \
" .align 2\n" \
" .long 1b,4b\n" \
" .long 2b,4b\n" \
".previous" \
: "=r"(err), "=&r"(x) \
: "r"(addr), "i"(-EFAULT), "0"(err))

Definition at line 240 of file uaccess.h.

#define __get_user_check (   x,
  ptr,
  size 
)
Value:
({ \
long __gu_err = -EFAULT, __gu_val = 0; \
const __typeof__(*(ptr)) * __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 199 of file uaccess.h.

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

Definition at line 191 of file uaccess.h.

#define __get_user_size (   x,
  ptr,
  size,
  retval 
)
Value:
do { \
retval = 0; \
switch (size) { \
case 1: __get_user_asm(x, ptr, retval, "l.lbz"); break; \
case 2: __get_user_asm(x, ptr, retval, "l.lhz"); break; \
case 4: __get_user_asm(x, ptr, retval, "l.lwz"); break; \
case 8: __get_user_asm2(x, ptr, retval); \
default: (x) = __get_user_bad(); \
} \
} while (0)

Definition at line 211 of file uaccess.h.

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

Definition at line 150 of file uaccess.h.

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

Definition at line 114 of file uaccess.h.

#define __put_user_asm (   x,
  addr,
  err,
  op 
)
Value:
__asm__ __volatile__( \
"1: "op" 0(%2),%1\n" \
"2:\n" \
".section .fixup,\"ax\"\n" \
"3: l.addi %0,r0,%3\n" \
" l.j 2b\n" \
" l.nop\n" \
".previous\n" \
".section __ex_table,\"a\"\n" \
" .align 2\n" \
" .long 1b,3b\n" \
".previous" \
: "=r"(err) \
: "r"(x), "r"(addr), "i"(-EFAULT), "0"(err))

Definition at line 157 of file uaccess.h.

#define __put_user_asm2 (   x,
  addr,
  err 
)
Value:
__asm__ __volatile__( \
"1: l.sw 0(%2),%1\n" \
"2: l.sw 4(%2),%H1\n" \
"3:\n" \
".section .fixup,\"ax\"\n" \
"4: l.addi %0,r0,%3\n" \
" l.j 3b\n" \
" l.nop\n" \
".previous\n" \
".section __ex_table,\"a\"\n" \
" .align 2\n" \
" .long 1b,4b\n" \
" .long 2b,4b\n" \
".previous" \
: "=r"(err) \
: "r"(x), "r"(addr), "i"(-EFAULT), "0"(err))

Definition at line 173 of file uaccess.h.

#define __put_user_check (   x,
  ptr,
  size 
)
Value:
({ \
long __pu_err = -EFAULT; \
__typeof__(*(ptr)) *__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 126 of file uaccess.h.

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

Definition at line 119 of file uaccess.h.

#define __put_user_size (   x,
  ptr,
  size,
  retval 
)
Value:
do { \
retval = 0; \
switch (size) { \
case 1: __put_user_asm(x, ptr, retval, "l.sb"); break; \
case 2: __put_user_asm(x, ptr, retval, "l.sh"); break; \
case 4: __put_user_asm(x, ptr, retval, "l.sw"); break; \
case 8: __put_user_asm2(x, ptr, retval); break; \
default: __put_user_bad(); \
} \
} while (0)

Definition at line 135 of file uaccess.h.

#define __range_ok (   addr,
  size 
)    (size <= get_fs() && addr <= (get_fs()-size))

Definition at line 60 of file uaccess.h.

#define access_ok (   type,
  addr,
  size 
)    __range_ok((unsigned long)addr, (unsigned long)size)

Definition at line 65 of file uaccess.h.

#define get_ds (   void)    (KERNEL_DS)

Definition at line 49 of file uaccess.h.

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

Definition at line 52 of file uaccess.h.

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

Definition at line 107 of file uaccess.h.

#define KERNEL_DS   (~0UL)

Definition at line 48 of file uaccess.h.

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

Definition at line 109 of file uaccess.h.

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

Definition at line 55 of file uaccess.h.

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

Definition at line 53 of file uaccess.h.

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

Definition at line 316 of file uaccess.h.

#define USER_DS   (TASK_SIZE)

Definition at line 51 of file uaccess.h.

#define VERIFY_READ   0

Definition at line 31 of file uaccess.h.

#define VERIFY_WRITE   1

Definition at line 32 of file uaccess.h.

Function Documentation

unsigned long __clear_user ( void addr,
unsigned long  size 
)

Definition at line 116 of file usercopy.c.

unsigned long __must_check __copy_tofrom_user ( void to,
const void from,
unsigned long  size 
)
long __get_user_bad ( void  )
long __put_user_bad ( void  )
unsigned long search_exception_table ( unsigned  long)

Definition at line 43 of file extable.c.

void sort_exception_table ( void  )
__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.