Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions | Variables
uaccess.h File Reference
#include <linux/sched.h>
#include <linux/mm.h>
#include <asm-generic/uaccess-unaligned.h>
#include <asm/processor.h>
#include <asm/page.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 MAKE_MM_SEG(a)   ((mm_segment_t) { (a) })
 
#define KERNEL_DS   MAKE_MM_SEG(-1UL)
 
#define USER_DS   MAKE_MM_SEG(PAGE_OFFSET)
 
#define get_ds()   (KERNEL_DS)
 
#define get_fs()   (current_thread_info()->addr_limit)
 
#define set_fs(x)   (current_thread_info()->addr_limit = (x))
 
#define segment_eq(a, b)   ((a).seg == (b).seg)
 
#define is_arch_mappable_range   is_arch_mappable_range
 
#define access_ok(type, addr, size)
 
#define _ASM_PTR   ".long"
 
#define __get_user_asm(OP, x, ptr, ret)
 
#define __get_user_1(x, ptr, ret)   __get_user_asm(lb_u, x, ptr, ret)
 
#define __get_user_2(x, ptr, ret)   __get_user_asm(lh_u, x, ptr, ret)
 
#define __get_user_4(x, ptr, ret)   __get_user_asm(lw, x, ptr, ret)
 
#define __lo32(a, b)   b
 
#define __hi32(a, b)   a
 
#define __get_user_8(x, ptr, ret)
 
#define __get_user(x, ptr)
 
#define __put_user_asm(OP, x, ptr, ret)
 
#define __put_user_1(x, ptr, ret)   __put_user_asm(sb, x, ptr, ret)
 
#define __put_user_2(x, ptr, ret)   __put_user_asm(sh, x, ptr, ret)
 
#define __put_user_4(x, ptr, ret)   __put_user_asm(sw, x, ptr, ret)
 
#define __put_user_8(x, ptr, ret)
 
#define __put_user(x, ptr)
 
#define put_user(x, ptr)
 
#define get_user(x, ptr)
 
#define copy_from_user   _copy_from_user
 
#define strlen_user(str)   strnlen_user(str, LONG_MAX)
 

Functions

int __range_ok (unsigned long addr, unsigned long size)
 
int fixup_exception (struct pt_regs *regs)
 
int __get_user_bad (void) __attribute__((warning("sizeof __get_user argument not 1
 
int __put_user_bad (void) __attribute__((warning("sizeof __put_user argument not 1
 
unsigned long __must_check __copy_to_user_inatomic (void __user *to, const void *from, unsigned long n)
 
unsigned long __must_check __copy_from_user_inatomic (void *to, const void __user *from, unsigned long n)
 
unsigned long __must_check __copy_from_user_zeroing (void *to, const void __user *from, unsigned long n)
 
long strnlen_user_asm (const char __user *str, long n)
 
long strncpy_from_user_asm (char *dst, const char __user *src, long)
 
unsigned long clear_user_asm (void __user *mem, unsigned long len)
 
unsigned long flush_user_asm (void __user *mem, unsigned long len)
 
unsigned long inv_user_asm (void __user *mem, unsigned long len)
 
unsigned long finv_user_asm (void __user *mem, unsigned long len)
 

Variables

int or
 

Macro Definition Documentation

#define __get_user (   x,
  ptr 
)
Value:
({ \
int __ret; \
__chk_user_ptr(ptr); \
switch (sizeof(*(ptr))) { \
case 1: __get_user_1(x, ptr, __ret); break; \
case 2: __get_user_2(x, ptr, __ret); break; \
case 4: __get_user_4(x, ptr, __ret); break; \
case 8: __get_user_8(x, ptr, __ret); break; \
default: __ret = __get_user_bad(); break; \
} \
__ret; \
})

__get_user: - Get a simple variable from user space, with less checking. : Variable to store result. : Source address, in user space.

Context: User context only. This function may sleep.

This macro copies a single simple variable from user space to kernel space. It supports simple types like char and int, but not larger data types like structures or arrays.

must have pointer-to-simple-variable type, and the result of dereferencing must be assignable to without a cast.

Returns zero on success, or -EFAULT on error. On error, the variable is set to zero.

Caller must check the pointer with access_ok() before calling this function.

Definition at line 206 of file uaccess.h.

#define __get_user_1 (   x,
  ptr,
  ret 
)    __get_user_asm(lb_u, x, ptr, ret)

Definition at line 152 of file uaccess.h.

#define __get_user_2 (   x,
  ptr,
  ret 
)    __get_user_asm(lh_u, x, ptr, ret)

Definition at line 153 of file uaccess.h.

#define __get_user_4 (   x,
  ptr,
  ret 
)    __get_user_asm(lw, x, ptr, ret)

Definition at line 154 of file uaccess.h.

#define __get_user_8 (   x,
  ptr,
  ret 
)
Value:
({ \
unsigned int __a, __b; \
asm volatile("1: { lw %1, %3; addi %2, %3, 4 }\n" \
"2: { lw %2, %2; movei %0, 0 }\n" \
".pushsection .fixup,\"ax\"\n" \
"0: { movei %1, 0; movei %2, 0 }\n" \
"{ movei %0, %4; j 9f }\n" \
".section __ex_table,\"a\"\n" \
".word 1b, 0b\n" \
".word 2b, 0b\n" \
".popsection\n" \
"9:" \
: "=r" (ret), "=r" (__a), "=&r" (__b) \
: "r" (ptr), "i" (-EFAULT)); \
(x) = (__typeof(x))(__typeof((x)-(x))) \
(((u64)__hi32(__a, __b) << 32) | \
__lo32(__a, __b)); \
})

Definition at line 162 of file uaccess.h.

#define __get_user_asm (   OP,
  x,
  ptr,
  ret 
)
Value:
asm volatile("1: {" #OP " %1, %2; movei %0, 0 }\n" \
".pushsection .fixup,\"ax\"\n" \
"0: { movei %1, 0; movei %0, %3 }\n" \
"j 9f\n" \
".section __ex_table,\"a\"\n" \
_ASM_PTR " 1b, 0b\n" \
".popsection\n" \
"9:" \
: "=r" (ret), "=r" (x) \
: "r" (ptr), "i" (-EFAULT))

Definition at line 134 of file uaccess.h.

#define __hi32 (   a,
  b 
)    a

Definition at line 160 of file uaccess.h.

#define __lo32 (   a,
  b 
)    b

Definition at line 159 of file uaccess.h.

#define __put_user (   x,
  ptr 
)
Value:
({ \
int __ret; \
__chk_user_ptr(ptr); \
switch (sizeof(*(ptr))) { \
case 1: __put_user_1(x, ptr, __ret); break; \
case 2: __put_user_2(x, ptr, __ret); break; \
case 4: __put_user_4(x, ptr, __ret); break; \
case 8: __put_user_8(x, ptr, __ret); break; \
default: __ret = __put_user_bad(); break; \
} \
__ret; \
})

__put_user: - Write a simple value into user space, with less checking. : Value to copy to user space. : Destination address, in user space.

Context: User context only. This function may sleep.

This macro copies a single simple value from kernel space to user space. It supports simple types like char and int, but not larger data types like structures or arrays.

must have pointer-to-simple-variable type, and must be assignable to the result of dereferencing .

Caller must check the pointer with access_ok() before calling this function.

Returns zero on success, or -EFAULT on error.

Definition at line 283 of file uaccess.h.

#define __put_user_1 (   x,
  ptr,
  ret 
)    __put_user_asm(sb, x, ptr, ret)

Definition at line 239 of file uaccess.h.

#define __put_user_2 (   x,
  ptr,
  ret 
)    __put_user_asm(sh, x, ptr, ret)

Definition at line 240 of file uaccess.h.

#define __put_user_4 (   x,
  ptr,
  ret 
)    __put_user_asm(sw, x, ptr, ret)

Definition at line 241 of file uaccess.h.

#define __put_user_8 (   x,
  ptr,
  ret 
)
Value:
({ \
u64 __x = (__typeof((x)-(x)))(x); \
int __lo = (int) __x, __hi = (int) (__x >> 32); \
asm volatile("1: { sw %1, %2; addi %0, %1, 4 }\n" \
"2: { sw %0, %3; movei %0, 0 }\n" \
".pushsection .fixup,\"ax\"\n" \
"0: { movei %0, %4; j 9f }\n" \
".section __ex_table,\"a\"\n" \
".word 1b, 0b\n" \
".word 2b, 0b\n" \
".popsection\n" \
"9:" \
: "=&r" (ret) \
: "r" (ptr), "r" (__lo32(__lo, __hi)), \
"r" (__hi32(__lo, __hi)), "i" (-EFAULT)); \
})

Definition at line 242 of file uaccess.h.

#define __put_user_asm (   OP,
  x,
  ptr,
  ret 
)
Value:
asm volatile("1: {" #OP " %1, %2; movei %0, 0 }\n" \
".pushsection .fixup,\"ax\"\n" \
"0: { movei %0, %3; j 9f }\n" \
".section __ex_table,\"a\"\n" \
_ASM_PTR " 1b, 0b\n" \
".popsection\n" \
"9:" \
: "=r" (ret) \
: "r" (ptr), "r" (x), "i" (-EFAULT))

Definition at line 222 of file uaccess.h.

#define _ASM_PTR   ".long"

Definition at line 131 of file uaccess.h.

#define access_ok (   type,
  addr,
  size 
)
Value:
({ \
__chk_user_ptr(addr); \
likely(__range_ok((unsigned long)(addr), (size)) == 0); \
})

access_ok: - Checks if a user space pointer is valid : Type of access: VERIFY_READ or VERIFY_WRITE. Note that VERIFY_WRITE is a superset of VERIFY_READ - if it is safe to write to a block, it is always safe to read from it. : User space pointer to start of block to check : Size of block to check

Context: User context only. This function may sleep.

Checks if a pointer to a block of memory in user space is valid.

Returns true (nonzero) if the memory block may be valid, false (zero) if it is definitely invalid.

Note that, depending on architecture, this function probably just checks that the pointer is in the user space range - after calling this function, memory access functions may still return -EFAULT.

Definition at line 92 of file uaccess.h.

#define copy_from_user   _copy_from_user

Definition at line 416 of file uaccess.h.

#define get_ds (   void)    (KERNEL_DS)

Definition at line 42 of file uaccess.h.

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

Definition at line 43 of file uaccess.h.

#define get_user (   x,
  ptr 
)
Value:
({ \
__typeof__(*(ptr)) const __user *__Gu_addr = (ptr); \
access_ok(VERIFY_READ, (__Gu_addr), sizeof(*(__Gu_addr))) ? \
__get_user((x), (__Gu_addr)) : \
((x) = 0, -EFAULT); \
})

Definition at line 310 of file uaccess.h.

#define is_arch_mappable_range   is_arch_mappable_range

Definition at line 62 of file uaccess.h.

#define KERNEL_DS   MAKE_MM_SEG(-1UL)

Definition at line 39 of file uaccess.h.

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

Definition at line 37 of file uaccess.h.

#define put_user (   x,
  ptr 
)
Value:
({ \
__typeof__(*(ptr)) __user *__Pu_addr = (ptr); \
access_ok(VERIFY_WRITE, (__Pu_addr), sizeof(*(__Pu_addr))) ? \
__put_user((x), (__Pu_addr)) : \
-EFAULT; \
})

Definition at line 302 of file uaccess.h.

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

Definition at line 46 of file uaccess.h.

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

Definition at line 44 of file uaccess.h.

#define strlen_user (   str)    strnlen_user(str, LONG_MAX)

Definition at line 474 of file uaccess.h.

#define USER_DS   MAKE_MM_SEG(PAGE_OFFSET)

Definition at line 40 of file uaccess.h.

#define VERIFY_READ   0

Definition at line 27 of file uaccess.h.

#define VERIFY_WRITE   1

Definition at line 28 of file uaccess.h.

Function Documentation

unsigned long __must_check __copy_from_user_inatomic ( void to,
const void __user from,
unsigned long  n 
)

__copy_from_user() - copy data from user space, with less checking. : Destination address, in kernel space. : Source address, in user space.
: Number of bytes to copy.

Context: User context only. This function may sleep.

Copy data from user space to kernel space. Caller must check the specified block with access_ok() before calling this function.

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

If some data could not be copied, this function will pad the copied data to the requested size using zero bytes.

An alternate version - __copy_from_user_inatomic() - is designed to be called from atomic context, typically bracketed by calls to pagefault_disable() and pagefault_enable(). This version does NOT pad with zeros.

Definition at line 258 of file memcpy_tile64.c.

unsigned long __must_check __copy_from_user_zeroing ( void to,
const void __user from,
unsigned long  n 
)

Definition at line 267 of file memcpy_tile64.c.

unsigned long __must_check __copy_to_user_inatomic ( void __user to,
const void from,
unsigned long  n 
)

__copy_to_user() - copy data into user space, with less checking. : 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. Caller must check the specified block with access_ok() before calling this function.

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

An alternate version - __copy_to_user_inatomic() - is designed to be called from atomic context, typically bracketed by calls to pagefault_disable() and pagefault_enable().

Definition at line 249 of file memcpy_tile64.c.

int __get_user_bad ( void  )
int __put_user_bad ( void  )
int __range_ok ( unsigned long  addr,
unsigned long  size 
)

Definition at line 18 of file uaccess.c.

unsigned long clear_user_asm ( void __user mem,
unsigned long  len 
)

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.

unsigned long finv_user_asm ( void __user mem,
unsigned long  len 
)

finv_user: - Flush-inval a block of memory in user space from cache. : Destination address, in user space. : Number of bytes to invalidate.

Returns number of bytes that could not be flush-invalidated. On success, this will be zero.

int fixup_exception ( struct pt_regs regs)

Definition at line 7 of file extable.c.

unsigned long flush_user_asm ( void __user mem,
unsigned long  len 
)

flush_user: - Flush a block of memory in user space from cache. : Destination address, in user space. : Number of bytes to flush.

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

unsigned long inv_user_asm ( void __user mem,
unsigned long  len 
)

inv_user: - Invalidate a block of memory in user space from cache. : Destination address, in user space. : Number of bytes to invalidate.

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

Note that on Tile64, the "inv" operation is in fact a "flush and invalidate", so cache write-backs will occur prior to the cache being marked invalid.

long strncpy_from_user_asm ( char dst,
const char __user src,
long   
)

strncpy_from_user: - Copy a NUL terminated string from userspace, with less checking. : 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. Caller must check the specified block with access_ok() before calling this function.

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 .

long strnlen_user_asm ( const char __user str,
long  n 
)

strlen_user: - Get the size of a string in user space. : 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.

Variable Documentation

int or

Definition at line 184 of file uaccess.h.