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/thread_info.h>
#include <linux/kernel.h>
#include <asm/page.h>
#include <asm/errno.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_XDS   MAKE_MM_SEG(0xBFFFFFFF)
 
#define KERNEL_DS   MAKE_MM_SEG(0x9FFFFFFF)
 
#define USER_DS   MAKE_MM_SEG(TASK_SIZE)
 
#define get_ds()   (KERNEL_DS)
 
#define get_fs()   (current_thread_info()->addr_limit)
 
#define set_fs(x)   (current_thread_info()->addr_limit = (x))
 
#define __kernel_ds_p()   (current_thread_info()->addr_limit.seg == 0x9FFFFFFF)
 
#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)   ___range_ok((unsigned long)(addr), (u32)(size))
 
#define access_ok(type, addr, size)   (__range_ok((addr), (size)) == 0)
 
#define __access_ok(addr, size)   (__range_ok((addr), (size)) == 0)
 
#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 put_user_ret(x, ptr, ret)   ({ if (put_user((x), (ptr))) return (ret); })
 
#define get_user_ret(x, ptr, ret)   ({ if (get_user((x), (ptr))) return (ret); })
 
#define __put_user_ret(x, ptr, ret)   ({ if (__put_user((x), (ptr))) return (ret); })
 
#define __get_user_ret(x, ptr, ret)   ({ if (__get_user((x), (ptr))) return (ret); })
 
#define __m(x)   (*(struct __large_struct *)(x))
 
#define __get_user_nocheck(x, ptr, size)
 
#define __get_user_check(x, ptr, size)
 
#define __get_user_asm(INSN)
 
#define __put_user_nocheck(x, ptr, size)
 
#define __put_user_check(x, ptr, size)
 
#define __put_user_asm(INSN)
 
#define __put_user_asm8()
 
#define __copy_user(to, from, size)
 
#define __copy_user_zeroing(to, from, size)
 
#define __copy_to_user_inatomic(to, from, n)   __generic_copy_to_user_nocheck((to), (from), (n))
 
#define __copy_from_user_inatomic(to, from, n)   __generic_copy_from_user_nocheck((to), (from), (n))
 
#define __copy_to_user(to, from, n)
 
#define __copy_from_user(to, from, n)
 
#define copy_to_user(to, from, n)   __generic_copy_to_user((to), (from), (n))
 
#define copy_from_user(to, from, n)   __generic_copy_from_user((to), (from), (n))
 
#define strlen_user(str)   strnlen_user(str, ~0UL >> 1)
 

Functions

int fixup_exception (struct pt_regs *regs)
 
int __get_user_unknown (void)
 
int __put_user_unknown (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 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 *str, long n)
 
unsigned long clear_user (void __user *mem, unsigned long len)
 
unsigned long __clear_user (void __user *mem, unsigned long len)
 

Macro Definition Documentation

#define __access_ok (   addr,
  size 
)    (__range_ok((addr), (size)) == 0)

Definition at line 73 of file uaccess.h.

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

Definition at line 45 of file uaccess.h.

#define __copy_from_user (   to,
  from,
  n 
)
Value:
({ \
might_sleep(); \
__copy_from_user_inatomic((to), (from), (n)); \
})

Definition at line 478 of file uaccess.h.

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

Definition at line 469 of file uaccess.h.

#define __copy_to_user (   to,
  from,
  n 
)
Value:
({ \
might_sleep(); \
__copy_to_user_inatomic((to), (from), (n)); \
})

Definition at line 472 of file uaccess.h.

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

Definition at line 467 of file uaccess.h.

#define __copy_user (   to,
  from,
  size 
)
Value:
do { \
if (size) { \
void *__to = to; \
const void *__from = from; \
int w; \
asm volatile( \
"0: movbu (%0),%3;\n" \
"1: movbu %3,(%1);\n" \
" inc %0;\n" \
" inc %1;\n" \
" add -1,%2;\n" \
" bne 0b;\n" \
"2:\n" \
" .section .fixup,\"ax\"\n" \
"3: jmp 2b\n" \
" .previous\n" \
" .section __ex_table,\"a\"\n" \
" .balign 4\n" \
" .long 0b,3b\n" \
" .long 1b,3b\n" \
" .previous\n" \
: "=a"(__from), "=a"(__to), "=r"(size), "=&r"(w)\
: "0"(__from), "1"(__to), "2"(size) \
: "cc", "memory"); \
} \
} while (0)

Definition at line 295 of file uaccess.h.

#define __copy_user_zeroing (   to,
  from,
  size 
)

Definition at line 323 of file uaccess.h.

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

Definition at line 111 of file uaccess.h.

#define __get_user_asm (   INSN)
Value:
({ \
asm volatile( \
"1:\n" \
" mov"INSN" %2,%1\n" \
" mov 0,%0\n" \
"2:\n" \
" .section .fixup,\"ax\"\n" \
"3:\n\t" \
" mov %3,%0\n" \
" jmp 2b\n" \
" .previous\n" \
" .section __ex_table,\"a\"\n" \
" .balign 4\n" \
" .long 1b, 3b\n" \
" .previous" \
: "=&r" (__gu_err), "=&r" (__gu_val) \
: "m" (__m(__gu_addr)), "i" (-EFAULT)); \
})

Definition at line 175 of file uaccess.h.

#define __get_user_check (   x,
  ptr,
  size 
)
Value:
({ \
const __typeof__(ptr) __guc_ptr = (ptr); \
int _e; \
if (likely(__access_ok((unsigned long) __guc_ptr, (size)))) \
_e = __get_user_nocheck((x), __guc_ptr, (size)); \
else { \
_e = -EFAULT; \
(x) = (__typeof__(x))0; \
} \
_e; \
})

Definition at line 162 of file uaccess.h.

#define __get_user_nocheck (   x,
  ptr,
  size 
)
Value:
({ \
unsigned long __gu_addr; \
int __gu_err; \
__gu_addr = (unsigned long) (ptr); \
switch (size) { \
case 1: { \
unsigned char __gu_val; \
__get_user_asm("bu"); \
(x) = *(__force __typeof__(*(ptr))*) &__gu_val; \
break; \
} \
case 2: { \
unsigned short __gu_val; \
__get_user_asm("hu"); \
(x) = *(__force __typeof__(*(ptr))*) &__gu_val; \
break; \
} \
case 4: { \
unsigned int __gu_val; \
__get_user_asm(""); \
(x) = *(__force __typeof__(*(ptr))*) &__gu_val; \
break; \
} \
default: \
__get_user_unknown(); \
break; \
} \
__gu_err; \
})

Definition at line 131 of file uaccess.h.

#define __get_user_ret (   x,
  ptr,
  ret 
)    ({ if (__get_user((x), (ptr))) return (ret); })

Definition at line 125 of file uaccess.h.

#define __kernel_ds_p ( )    (current_thread_info()->addr_limit.seg == 0x9FFFFFFF)

Definition at line 41 of file uaccess.h.

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

Definition at line 129 of file uaccess.h.

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

Definition at line 110 of file uaccess.h.

#define __put_user_asm (   INSN)
Value:
({ \
asm volatile( \
"1:\n" \
" mov"INSN" %1,%2\n" \
" mov 0,%0\n" \
"2:\n" \
" .section .fixup,\"ax\"\n" \
"3:\n" \
" mov %3,%0\n" \
" jmp 2b\n" \
" .previous\n" \
" .section __ex_table,\"a\"\n" \
" .balign 4\n" \
" .long 1b, 3b\n" \
" .previous" \
: "=&r" (__pu_err) \
: "r" (__pu_val.val), "m" (__m(__pu_addr)), \
"i" (-EFAULT) \
); \
})

Definition at line 242 of file uaccess.h.

#define __put_user_asm8 ( )
Value:
({ \
asm volatile( \
"1: mov %1,%3 \n" \
"2: mov %2,%4 \n" \
" mov 0,%0 \n" \
"3: \n" \
" .section .fixup,\"ax\" \n" \
"4: \n" \
" mov %5,%0 \n" \
" jmp 3b \n" \
" .previous \n" \
" .section __ex_table,\"a\"\n" \
" .balign 4 \n" \
" .long 1b, 4b \n" \
" .long 2b, 4b \n" \
" .previous \n" \
: "=&r" (__pu_err) \
: "r" (__pu_val.bits[0]), "r" (__pu_val.bits[1]), \
"m" (__m(__pu_addr)), "m" (__m(__pu_addr+4)), \
"i" (-EFAULT) \
); \
})

Definition at line 264 of file uaccess.h.

#define __put_user_check (   x,
  ptr,
  size 
)
Value:
({ \
union { \
__typeof__(*(ptr)) val; \
u32 bits[2]; \
} __pu_val; \
unsigned long __pu_addr; \
int __pu_err; \
__pu_val.val = (x); \
__pu_addr = (unsigned long) (ptr); \
if (likely(__access_ok(__pu_addr, size))) { \
switch (size) { \
case 1: __put_user_asm("bu"); break; \
case 2: __put_user_asm("hu"); break; \
case 4: __put_user_asm("" ); break; \
case 8: __put_user_asm8(); break; \
default: __pu_err = __put_user_unknown(); break; \
} \
} \
else { \
__pu_err = -EFAULT; \
} \
__pu_err; \
})

Definition at line 217 of file uaccess.h.

#define __put_user_nocheck (   x,
  ptr,
  size 
)
Value:
({ \
union { \
__typeof__(*(ptr)) val; \
u32 bits[2]; \
} __pu_val; \
unsigned long __pu_addr; \
int __pu_err; \
__pu_val.val = (x); \
__pu_addr = (unsigned long) (ptr); \
switch (size) { \
case 1: __put_user_asm("bu"); break; \
case 2: __put_user_asm("hu"); break; \
case 4: __put_user_asm("" ); break; \
case 8: __put_user_asm8(); break; \
default: __pu_err = __put_user_unknown(); break; \
} \
__pu_err; \
})

Definition at line 197 of file uaccess.h.

#define __put_user_ret (   x,
  ptr,
  ret 
)    ({ if (__put_user((x), (ptr))) return (ret); })

Definition at line 123 of file uaccess.h.

#define __range_ok (   addr,
  size 
)    ___range_ok((unsigned long)(addr), (u32)(size))

Definition at line 70 of file uaccess.h.

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

Definition at line 72 of file uaccess.h.

#define copy_from_user (   to,
  from,
  n 
)    __generic_copy_from_user((to), (from), (n))

Definition at line 486 of file uaccess.h.

#define copy_to_user (   to,
  from,
  n 
)    __generic_copy_to_user((to), (from), (n))

Definition at line 485 of file uaccess.h.

#define get_ds (   void)    (KERNEL_DS)

Definition at line 38 of file uaccess.h.

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

Definition at line 39 of file uaccess.h.

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

Definition at line 103 of file uaccess.h.

#define get_user_ret (   x,
  ptr,
  ret 
)    ({ if (get_user((x), (ptr))) return (ret); })

Definition at line 121 of file uaccess.h.

#define KERNEL_DS   MAKE_MM_SEG(0x9FFFFFFF)

Definition at line 35 of file uaccess.h.

#define KERNEL_XDS   MAKE_MM_SEG(0xBFFFFFFF)

Definition at line 34 of file uaccess.h.

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

Definition at line 32 of file uaccess.h.

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

Definition at line 102 of file uaccess.h.

#define put_user_ret (   x,
  ptr,
  ret 
)    ({ if (put_user((x), (ptr))) return (ret); })

Definition at line 119 of file uaccess.h.

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

Definition at line 43 of file uaccess.h.

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

Definition at line 40 of file uaccess.h.

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

Definition at line 491 of file uaccess.h.

#define USER_DS   MAKE_MM_SEG(TASK_SIZE)

Definition at line 36 of file uaccess.h.

#define VERIFY_READ   0

Definition at line 22 of file uaccess.h.

#define VERIFY_WRITE   1

Definition at line 23 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.

int __get_user_unknown ( void  )
int __put_user_unknown ( void  )
long __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 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.