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/string.h>
#include <linux/thread_info.h>
#include <asm/errno.h>
#include <asm/memory.h>
#include <asm/domain.h>
#include <asm/unified.h>
#include <asm/compiler.h>

Go to the source code of this file.

Data Structures

struct  exception_table_entry
 

Macros

#define VERIFY_READ   0
 
#define VERIFY_WRITE   1
 
#define KERNEL_DS   0x00000000
 
#define get_ds()   (KERNEL_DS)
 
#define USER_DS   KERNEL_DS
 
#define segment_eq(a, b)   (1)
 
#define __addr_ok(addr)   ((void)(addr),1)
 
#define __range_ok(addr, size)   ((void)(addr),0)
 
#define get_fs()   (KERNEL_DS)
 
#define get_user(x, p)   __get_user(x,p)
 
#define put_user(x, p)   __put_user(x,p)
 
#define access_ok(type, addr, size)   (__range_ok(addr,size) == 0)
 
#define user_addr_max()   (segment_eq(get_fs(), USER_DS) ? TASK_SIZE : ~0UL)
 
#define __get_user(x, ptr)
 
#define __get_user_error(x, ptr, err)
 
#define __get_user_err(x, ptr, err)
 
#define __get_user_asm_byte(x, addr, err)
 
#define __get_user_asm_half(x, __gu_addr, err)
 
#define __get_user_asm_word(x, addr, err)
 
#define __put_user(x, ptr)
 
#define __put_user_error(x, ptr, err)
 
#define __put_user_err(x, ptr, err)
 
#define __put_user_asm_byte(x, __pu_addr, err)
 
#define __put_user_asm_half(x, __pu_addr, err)
 
#define __put_user_asm_word(x, __pu_addr, err)
 
#define __reg_oper0   "%R2"
 
#define __reg_oper1   "%Q2"
 
#define __put_user_asm_dword(x, __pu_addr, err)
 
#define __copy_from_user(to, from, n)   (memcpy(to, (void __force *)from, n), 0)
 
#define __copy_to_user(to, from, n)   (memcpy((void __force *)to, from, n), 0)
 
#define __clear_user(addr, n)   (memset((void __force *)addr, 0, n), 0)
 
#define __copy_to_user_inatomic   __copy_to_user
 
#define __copy_from_user_inatomic   __copy_from_user
 

Functions

int fixup_exception (struct pt_regs *regs)
 
int __get_user_bad (void)
 
int __put_user_bad (void)
 
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)    ((void)(addr),1)

Definition at line 203 of file uaccess.h.

#define __clear_user (   addr,
  n 
)    (memset((void __force *)addr, 0, n), 0)

Definition at line 429 of file uaccess.h.

#define __copy_from_user (   to,
  from,
  n 
)    (memcpy(to, (void __force *)from, n), 0)

Definition at line 427 of file uaccess.h.

#define __copy_from_user_inatomic   __copy_from_user

Definition at line 449 of file uaccess.h.

#define __copy_to_user (   to,
  from,
  n 
)    (memcpy((void __force *)to, from, n), 0)

Definition at line 428 of file uaccess.h.

#define __copy_to_user_inatomic   __copy_to_user

Definition at line 448 of file uaccess.h.

#define __get_user (   x,
  ptr 
)
Value:
({ \
long __gu_err = 0; \
__get_user_err((x),(ptr),__gu_err); \
__gu_err; \
})

Definition at line 230 of file uaccess.h.

#define __get_user_asm_byte (   x,
  addr,
  err 
)
Value:
__asm__ __volatile__( \
"1: " TUSER(ldrb) " %1,[%2],#0\n" \
"2:\n" \
" .pushsection .fixup,\"ax\"\n" \
" .align 2\n" \
"3: mov %0, %3\n" \
" mov %1, #0\n" \
" b 2b\n" \
" .popsection\n" \
" .pushsection __ex_table,\"a\"\n" \
" .align 3\n" \
" .long 1b, 3b\n" \
" .popsection" \
: "+r" (err), "=&r" (x) \
: "r" (addr), "i" (-EFAULT) \
: "cc")

Definition at line 258 of file uaccess.h.

#define __get_user_asm_half (   x,
  __gu_addr,
  err 
)
Value:
({ \
unsigned long __b1, __b2; \
__get_user_asm_byte(__b1, __gu_addr, err); \
__get_user_asm_byte(__b2, __gu_addr + 1, err); \
(x) = __b1 | (__b2 << 8); \
})

Definition at line 277 of file uaccess.h.

#define __get_user_asm_word (   x,
  addr,
  err 
)
Value:
__asm__ __volatile__( \
"1: " TUSER(ldr) " %1,[%2],#0\n" \
"2:\n" \
" .pushsection .fixup,\"ax\"\n" \
" .align 2\n" \
"3: mov %0, %3\n" \
" mov %1, #0\n" \
" b 2b\n" \
" .popsection\n" \
" .pushsection __ex_table,\"a\"\n" \
" .align 3\n" \
" .long 1b, 3b\n" \
" .popsection" \
: "+r" (err), "=&r" (x) \
: "r" (addr), "i" (-EFAULT) \
: "cc")

Definition at line 294 of file uaccess.h.

#define __get_user_err (   x,
  ptr,
  err 
)
Value:
do { \
unsigned long __gu_addr = (unsigned long)(ptr); \
unsigned long __gu_val; \
__chk_user_ptr(ptr); \
might_fault(); \
switch (sizeof(*(ptr))) { \
case 1: __get_user_asm_byte(__gu_val,__gu_addr,err); break; \
case 2: __get_user_asm_half(__gu_val,__gu_addr,err); break; \
case 4: __get_user_asm_word(__gu_val,__gu_addr,err); break; \
default: (__gu_val) = __get_user_bad(); \
} \
(x) = (__typeof__(*(ptr)))__gu_val; \
} while (0)

Definition at line 243 of file uaccess.h.

#define __get_user_error (   x,
  ptr,
  err 
)
Value:
({ \
__get_user_err((x),(ptr),err); \
(void) 0; \
})

Definition at line 237 of file uaccess.h.

#define __put_user (   x,
  ptr 
)
Value:
({ \
long __pu_err = 0; \
__put_user_err((x),(ptr),__pu_err); \
__pu_err; \
})

Definition at line 312 of file uaccess.h.

#define __put_user_asm_byte (   x,
  __pu_addr,
  err 
)
Value:
__asm__ __volatile__( \
"1: " TUSER(strb) " %1,[%2],#0\n" \
"2:\n" \
" .pushsection .fixup,\"ax\"\n" \
" .align 2\n" \
"3: mov %0, %3\n" \
" b 2b\n" \
" .popsection\n" \
" .pushsection __ex_table,\"a\"\n" \
" .align 3\n" \
" .long 1b, 3b\n" \
" .popsection" \
: "+r" (err) \
: "r" (x), "r" (__pu_addr), "i" (-EFAULT) \
: "cc")

Definition at line 340 of file uaccess.h.

#define __put_user_asm_dword (   x,
  __pu_addr,
  err 
)
Value:
__asm__ __volatile__( \
ARM( "1: " TUSER(str) " " __reg_oper1 ", [%1], #4\n" ) \
ARM( "2: " TUSER(str) " " __reg_oper0 ", [%1]\n" ) \
THUMB( "1: " TUSER(str) " " __reg_oper1 ", [%1]\n" ) \
THUMB( "2: " TUSER(str) " " __reg_oper0 ", [%1, #4]\n" ) \
"3:\n" \
" .pushsection .fixup,\"ax\"\n" \
" .align 2\n" \
"4: mov %0, %3\n" \
" b 3b\n" \
" .popsection\n" \
" .pushsection __ex_table,\"a\"\n" \
" .align 3\n" \
" .long 1b, 4b\n" \
" .long 2b, 4b\n" \
" .popsection" \
: "+r" (err), "+r" (__pu_addr) \
: "r" (x), "i" (-EFAULT) \
: "cc")

Definition at line 398 of file uaccess.h.

#define __put_user_asm_half (   x,
  __pu_addr,
  err 
)
Value:
({ \
unsigned long __temp = (unsigned long)(x); \
__put_user_asm_byte(__temp, __pu_addr, err); \
__put_user_asm_byte(__temp >> 8, __pu_addr + 1, err); \
})

Definition at line 358 of file uaccess.h.

#define __put_user_asm_word (   x,
  __pu_addr,
  err 
)
Value:
__asm__ __volatile__( \
"1: " TUSER(str) " %1,[%2],#0\n" \
"2:\n" \
" .pushsection .fixup,\"ax\"\n" \
" .align 2\n" \
"3: mov %0, %3\n" \
" b 2b\n" \
" .popsection\n" \
" .pushsection __ex_table,\"a\"\n" \
" .align 3\n" \
" .long 1b, 3b\n" \
" .popsection" \
: "+r" (err) \
: "r" (x), "r" (__pu_addr), "i" (-EFAULT) \
: "cc")

Definition at line 373 of file uaccess.h.

#define __put_user_err (   x,
  ptr,
  err 
)
Value:
do { \
unsigned long __pu_addr = (unsigned long)(ptr); \
__typeof__(*(ptr)) __pu_val = (x); \
might_fault(); \
switch (sizeof(*(ptr))) { \
case 1: __put_user_asm_byte(__pu_val,__pu_addr,err); break; \
case 2: __put_user_asm_half(__pu_val,__pu_addr,err); break; \
case 4: __put_user_asm_word(__pu_val,__pu_addr,err); break; \
case 8: __put_user_asm_dword(__pu_val,__pu_addr,err); break; \
default: __put_user_bad(); \
} \
} while (0)

Definition at line 325 of file uaccess.h.

#define __put_user_error (   x,
  ptr,
  err 
)
Value:
({ \
__put_user_err((x),(ptr),err); \
(void) 0; \
})

Definition at line 319 of file uaccess.h.

#define __range_ok (   addr,
  size 
)    ((void)(addr),0)

Definition at line 204 of file uaccess.h.

#define __reg_oper0   "%R2"

Definition at line 391 of file uaccess.h.

#define __reg_oper1   "%Q2"

Definition at line 392 of file uaccess.h.

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

Definition at line 216 of file uaccess.h.

#define get_ds (   void)    (KERNEL_DS)

Definition at line 56 of file uaccess.h.

#define get_fs (   void)    (KERNEL_DS)

Definition at line 205 of file uaccess.h.

#define get_user (   x,
  p 
)    __get_user(x,p)

Definition at line 211 of file uaccess.h.

#define KERNEL_DS   0x00000000

Definition at line 55 of file uaccess.h.

#define put_user (   x,
  p 
)    __put_user(x,p)

Definition at line 212 of file uaccess.h.

#define segment_eq (   a,
  b 
)    (1)

Definition at line 202 of file uaccess.h.

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

Definition at line 218 of file uaccess.h.

#define USER_DS   KERNEL_DS

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

int __get_user_bad ( void  )
int __put_user_bad ( void  )
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.

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.