1/* 2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com) 3 * Licensed under the GPL 4 */ 5 6#ifndef __ARCH_UM_UACCESS_H 7#define __ARCH_UM_UACCESS_H 8 9#include "choose-mode.h" 10 11#ifdef CONFIG_MODE_TT 12#include "uaccess-tt.h" 13#endif 14 15#ifdef CONFIG_MODE_SKAS 16#include "uaccess-skas.h" 17#endif 18 19#include "asm/fixmap.h" 20 21#define __under_task_size(addr, size) \ 22 (((unsigned long) (addr) < TASK_SIZE) && \ 23 (((unsigned long) (addr) + (size)) < TASK_SIZE)) 24 25#define __access_ok_vsyscall(type, addr, size) \ 26 ((type == VERIFY_READ) && \ 27 ((unsigned long) (addr) >= FIXADDR_USER_START) && \ 28 ((unsigned long) (addr) + (size) <= FIXADDR_USER_END) && \ 29 ((unsigned long) (addr) + (size) >= (unsigned long)(addr))) 30 31#define __addr_range_nowrap(addr, size) \ 32 ((unsigned long) (addr) <= ((unsigned long) (addr) + (size))) 33 34#define access_ok(type, addr, size) \ 35 (__addr_range_nowrap(addr, size) && \ 36 (__under_task_size(addr, size) || \ 37 __access_ok_vsyscall(type, addr, size) || \ 38 segment_eq(get_fs(), KERNEL_DS) || \ 39 CHOOSE_MODE_PROC(access_ok_tt, access_ok_skas, type, addr, size))) 40 41static inline int copy_from_user(void *to, const void __user *from, int n) 42{ 43 return(CHOOSE_MODE_PROC(copy_from_user_tt, copy_from_user_skas, to, 44 from, n)); 45} 46 47static inline int copy_to_user(void __user *to, const void *from, int n) 48{ 49 return(CHOOSE_MODE_PROC(copy_to_user_tt, copy_to_user_skas, to, 50 from, n)); 51} 52 53/* 54 * strncpy_from_user: - Copy a NUL terminated string from userspace. 55 * @dst: Destination address, in kernel space. This buffer must be at 56 * least @count bytes long. 57 * @src: Source address, in user space. 58 * @count: Maximum number of bytes to copy, including the trailing NUL. 59 * 60 * Copies a NUL-terminated string from userspace to kernel space. 61 * 62 * On success, returns the length of the string (not including the trailing 63 * NUL). 64 * 65 * If access to userspace fails, returns -EFAULT (some data may have been 66 * copied). 67 * 68 * If @count is smaller than the length of the string, copies @count bytes 69 * and returns @count. 70 */ 71 72static inline int strncpy_from_user(char *dst, const char __user *src, int count) 73{ 74 return(CHOOSE_MODE_PROC(strncpy_from_user_tt, strncpy_from_user_skas, 75 dst, src, count)); 76} 77 78/* 79 * __clear_user: - Zero a block of memory in user space, with less checking. 80 * @to: Destination address, in user space. 81 * @n: Number of bytes to zero. 82 * 83 * Zero a block of memory in user space. Caller must check 84 * the specified block with access_ok() before calling this function. 85 * 86 * Returns number of bytes that could not be cleared. 87 * On success, this will be zero. 88 */ 89static inline int __clear_user(void *mem, int len) 90{ 91 return(CHOOSE_MODE_PROC(__clear_user_tt, __clear_user_skas, mem, len)); 92} 93 94/* 95 * clear_user: - Zero a block of memory in user space. 96 * @to: Destination address, in user space. 97 * @n: Number of bytes to zero. 98 * 99 * Zero a block of memory in user space. 100 * 101 * Returns number of bytes that could not be cleared. 102 * On success, this will be zero. 103 */ 104static inline int clear_user(void __user *mem, int len) 105{ 106 return(CHOOSE_MODE_PROC(clear_user_tt, clear_user_skas, mem, len)); 107} 108 109/* 110 * strlen_user: - Get the size of a string in user space. 111 * @str: The string to measure. 112 * @n: The maximum valid length 113 * 114 * Get the size of a NUL-terminated string in user space. 115 * 116 * Returns the size of the string INCLUDING the terminating NUL. 117 * On exception, returns 0. 118 * If the string is too long, returns a value greater than @n. 119 */ 120static inline int strnlen_user(const void __user *str, long len) 121{ 122 return(CHOOSE_MODE_PROC(strnlen_user_tt, strnlen_user_skas, str, len)); 123} 124 125#endif 126 127/* 128 * Overrides for Emacs so that we follow Linus's tabbing style. 129 * Emacs will notice this stuff at the end of the file and automatically 130 * adjust the settings for this buffer only. This must remain at the end 131 * of the file. 132 * --------------------------------------------------------------------------- 133 * Local variables: 134 * c-file-style: "linux" 135 * End: 136 */ 137