uaccess.h
来自「Linux Kernel 2.6.9 for OMAP1710」· C头文件 代码 · 共 826 行 · 第 1/2 页
H
826 行
#else#define __MODULE_JAL(destination) \ "jal\t" #destination "\n\t"#endifextern size_t __copy_user(void *__to, const void *__from, size_t __n);#define __invoke_copy_to_user(to,from,n) \({ \ register void *__cu_to_r __asm__ ("$4"); \ register const void *__cu_from_r __asm__ ("$5"); \ register long __cu_len_r __asm__ ("$6"); \ \ __cu_to_r = (to); \ __cu_from_r = (from); \ __cu_len_r = (n); \ __asm__ __volatile__( \ __MODULE_JAL(__copy_user) \ : "+r" (__cu_to_r), "+r" (__cu_from_r), "+r" (__cu_len_r) \ : \ : "$8", "$9", "$10", "$11", "$12", "$15", "$24", "$31", \ "memory"); \ __cu_len_r; \})/* * __copy_to_user: - Copy a block of data into user space, with less checking. * @to: Destination address, in user space. * @from: Source address, in kernel space. * @n: 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. */#define __copy_to_user(to,from,n) \({ \ void *__cu_to; \ const void *__cu_from; \ long __cu_len; \ \ might_sleep(); \ __cu_to = (to); \ __cu_from = (from); \ __cu_len = (n); \ __cu_len = __invoke_copy_to_user(__cu_to, __cu_from, __cu_len); \ __cu_len; \})#define __copy_to_user_inatomic __copy_to_user#define __copy_from_user_inatomic __copy_from_user/* * copy_to_user: - Copy a block of data into user space. * @to: Destination address, in user space. * @from: Source address, in kernel space. * @n: 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. */#define copy_to_user(to,from,n) \({ \ void *__cu_to; \ const void *__cu_from; \ long __cu_len; \ \ might_sleep(); \ __cu_to = (to); \ __cu_from = (from); \ __cu_len = (n); \ if (access_ok(VERIFY_WRITE, __cu_to, __cu_len)) \ __cu_len = __invoke_copy_to_user(__cu_to, __cu_from, \ __cu_len); \ __cu_len; \})#define __invoke_copy_from_user(to,from,n) \({ \ register void *__cu_to_r __asm__ ("$4"); \ register const void *__cu_from_r __asm__ ("$5"); \ register long __cu_len_r __asm__ ("$6"); \ \ __cu_to_r = (to); \ __cu_from_r = (from); \ __cu_len_r = (n); \ __asm__ __volatile__( \ ".set\tnoreorder\n\t" \ __MODULE_JAL(__copy_user) \ ".set\tnoat\n\t" \ __UA_ADDU "\t$1, %1, %2\n\t" \ ".set\tat\n\t" \ ".set\treorder\n\t" \ "move\t%0, $6" /* XXX */ \ : "+r" (__cu_to_r), "+r" (__cu_from_r), "+r" (__cu_len_r) \ : \ : "$8", "$9", "$10", "$11", "$12", "$15", "$24", "$31", \ "memory"); \ __cu_len_r; \})/* * __copy_from_user: - Copy a block of data from user space, with less checking. * @to: Destination address, in kernel space. * @from: Source address, in user space. * @n: 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. */#define __copy_from_user(to,from,n) \({ \ void *__cu_to; \ const void *__cu_from; \ long __cu_len; \ \ might_sleep(); \ __cu_to = (to); \ __cu_from = (from); \ __cu_len = (n); \ __cu_len = __invoke_copy_from_user(__cu_to, __cu_from, \ __cu_len); \ __cu_len; \})/* * copy_from_user: - Copy a block of data from user space. * @to: Destination address, in kernel space. * @from: Source address, in user space. * @n: Number of bytes to copy. * * Context: User context only. This function may sleep. * * Copy data from user space to kernel space. * * 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. */#define copy_from_user(to,from,n) \({ \ void *__cu_to; \ const void *__cu_from; \ long __cu_len; \ \ might_sleep(); \ __cu_to = (to); \ __cu_from = (from); \ __cu_len = (n); \ if (access_ok(VERIFY_READ, __cu_from, __cu_len)) \ __cu_len = __invoke_copy_from_user(__cu_to, __cu_from, \ __cu_len); \ __cu_len; \})#define __copy_in_user(to, from, n) __copy_from_user(to, from, n)#define copy_in_user(to,from,n) \({ \ void *__cu_to; \ const void *__cu_from; \ long __cu_len; \ \ might_sleep(); \ __cu_to = (to); \ __cu_from = (from); \ __cu_len = (n); \ if (likely(access_ok(VERIFY_READ, __cu_from, __cu_len) && \ access_ok(VERIFY_WRITE, __cu_to, __cu_len))) \ __cu_len = __invoke_copy_from_user(__cu_to, __cu_from, \ __cu_len); \ __cu_len; \})/* * __clear_user: - Zero a block of memory in user space, with less checking. * @to: Destination address, in user space. * @n: 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. */static inline __kernel_size_t__clear_user(void *addr, __kernel_size_t size){ __kernel_size_t res; might_sleep(); __asm__ __volatile__( "move\t$4, %1\n\t" "move\t$5, $0\n\t" "move\t$6, %2\n\t" __MODULE_JAL(__bzero) "move\t%0, $6" : "=r" (res) : "r" (addr), "r" (size) : "$4", "$5", "$6", __UA_t0, __UA_t1, "$31"); return res;}#define clear_user(addr,n) \({ \ void * __cl_addr = (addr); \ unsigned long __cl_size = (n); \ if (__cl_size && access_ok(VERIFY_WRITE, \ ((unsigned long)(__cl_addr)), __cl_size)) \ __cl_size = __clear_user(__cl_addr, __cl_size); \ __cl_size; \})/* * __strncpy_from_user: - Copy a NUL terminated string from userspace, with less checking. * @dst: Destination address, in kernel space. This buffer must be at * least @count bytes long. * @src: Source address, in user space. * @count: 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 @count is smaller than the length of the string, copies @count bytes * and returns @count. */static inline long__strncpy_from_user(char *__to, const char *__from, long __len){ long res; might_sleep(); __asm__ __volatile__( "move\t$4, %1\n\t" "move\t$5, %2\n\t" "move\t$6, %3\n\t" __MODULE_JAL(__strncpy_from_user_nocheck_asm) "move\t%0, $2" : "=r" (res) : "r" (__to), "r" (__from), "r" (__len) : "$2", "$3", "$4", "$5", "$6", __UA_t0, "$31", "memory"); return res;}/* * strncpy_from_user: - Copy a NUL terminated string from userspace. * @dst: Destination address, in kernel space. This buffer must be at * least @count bytes long. * @src: Source address, in user space. * @count: 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 @count is smaller than the length of the string, copies @count bytes * and returns @count. */static inline longstrncpy_from_user(char *__to, const char *__from, long __len){ long res; might_sleep(); __asm__ __volatile__( "move\t$4, %1\n\t" "move\t$5, %2\n\t" "move\t$6, %3\n\t" __MODULE_JAL(__strncpy_from_user_asm) "move\t%0, $2" : "=r" (res) : "r" (__to), "r" (__from), "r" (__len) : "$2", "$3", "$4", "$5", "$6", __UA_t0, "$31", "memory"); return res;}/* Returns: 0 if bad, string length+1 (memory size) of string if ok */static inline long __strlen_user(const char *s){ long res; might_sleep(); __asm__ __volatile__( "move\t$4, %1\n\t" __MODULE_JAL(__strlen_user_nocheck_asm) "move\t%0, $2" : "=r" (res) : "r" (s) : "$2", "$4", __UA_t0, "$31"); return res;}/* * strlen_user: - Get the size of a string in user space. * @str: 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. */static inline long strlen_user(const char *s){ long res; might_sleep(); __asm__ __volatile__( "move\t$4, %1\n\t" __MODULE_JAL(__strlen_user_asm) "move\t%0, $2" : "=r" (res) : "r" (s) : "$2", "$4", __UA_t0, "$31"); return res;}/* Returns: 0 if bad, string length+1 (memory size) of string if ok */static inline long __strnlen_user(const char *s, long n){ long res; might_sleep(); __asm__ __volatile__( "move\t$4, %1\n\t" "move\t$5, %2\n\t" __MODULE_JAL(__strnlen_user_nocheck_asm) "move\t%0, $2" : "=r" (res) : "r" (s), "r" (n) : "$2", "$4", "$5", __UA_t0, "$31"); return res;}/* * strlen_user: - Get the size of a string in user space. * @str: 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. */static inline long strnlen_user(const char *s, long n){ long res; might_sleep(); __asm__ __volatile__( "move\t$4, %1\n\t" "move\t$5, %2\n\t" __MODULE_JAL(__strnlen_user_asm) "move\t%0, $2" : "=r" (res) : "r" (s), "r" (n) : "$2", "$4", "$5", __UA_t0, "$31"); return res;}struct exception_table_entry{ unsigned long insn; unsigned long nextinsn;};extern int fixup_exception(struct pt_regs *regs);#endif /* _ASM_UACCESS_H */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?