Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * include/asm-s390/uaccess.h |
| 3 | * |
| 4 | * S390 version |
| 5 | * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation |
| 6 | * Author(s): Hartmut Penner (hp@de.ibm.com), |
| 7 | * Martin Schwidefsky (schwidefsky@de.ibm.com) |
| 8 | * |
| 9 | * Derived from "include/asm-i386/uaccess.h" |
| 10 | */ |
| 11 | #ifndef __S390_UACCESS_H |
| 12 | #define __S390_UACCESS_H |
| 13 | |
| 14 | /* |
| 15 | * User space memory access functions |
| 16 | */ |
| 17 | #include <linux/sched.h> |
| 18 | #include <linux/errno.h> |
| 19 | |
| 20 | #define VERIFY_READ 0 |
| 21 | #define VERIFY_WRITE 1 |
| 22 | |
| 23 | |
| 24 | /* |
| 25 | * The fs value determines whether argument validity checking should be |
| 26 | * performed or not. If get_fs() == USER_DS, checking is performed, with |
| 27 | * get_fs() == KERNEL_DS, checking is bypassed. |
| 28 | * |
| 29 | * For historical reasons, these macros are grossly misnamed. |
| 30 | */ |
| 31 | |
| 32 | #define MAKE_MM_SEG(a) ((mm_segment_t) { (a) }) |
| 33 | |
| 34 | |
| 35 | #define KERNEL_DS MAKE_MM_SEG(0) |
| 36 | #define USER_DS MAKE_MM_SEG(1) |
| 37 | |
| 38 | #define get_ds() (KERNEL_DS) |
| 39 | #define get_fs() (current->thread.mm_segment) |
| 40 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #define set_fs(x) \ |
| 42 | ({ \ |
| 43 | unsigned long __pto; \ |
| 44 | current->thread.mm_segment = (x); \ |
| 45 | __pto = current->thread.mm_segment.ar4 ? \ |
| 46 | S390_lowcore.user_asce : S390_lowcore.kernel_asce; \ |
Martin Schwidefsky | 94c12cc | 2006-09-28 16:56:43 +0200 | [diff] [blame] | 47 | __ctl_load(__pto, 7, 7); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | #define segment_eq(a,b) ((a).ar4 == (b).ar4) |
| 51 | |
Heiko Carstens | 7683f74 | 2011-05-26 09:48:25 +0200 | [diff] [blame] | 52 | #define __access_ok(addr, size) \ |
| 53 | ({ \ |
| 54 | __chk_user_ptr(addr); \ |
| 55 | 1; \ |
| 56 | }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | |
Heiko Carstens | 7683f74 | 2011-05-26 09:48:25 +0200 | [diff] [blame] | 58 | #define access_ok(type, addr, size) __access_ok(addr, size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | /* |
| 61 | * The exception table consists of pairs of addresses: the first is the |
| 62 | * address of an instruction that is allowed to fault, and the second is |
| 63 | * the address at which the program should continue. No registers are |
| 64 | * modified, so it is entirely up to the continuation code to figure out |
| 65 | * what to do. |
| 66 | * |
| 67 | * All the routines below use bits of fixup code that are out of line |
| 68 | * with the main instruction path. This means when everything is well, |
| 69 | * we don't even have to jump over them. Further, they do not intrude |
| 70 | * on our cache or tlb entries. |
| 71 | */ |
| 72 | |
| 73 | struct exception_table_entry |
| 74 | { |
| 75 | unsigned long insn, fixup; |
| 76 | }; |
| 77 | |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 78 | struct uaccess_ops { |
| 79 | size_t (*copy_from_user)(size_t, const void __user *, void *); |
| 80 | size_t (*copy_from_user_small)(size_t, const void __user *, void *); |
| 81 | size_t (*copy_to_user)(size_t, void __user *, const void *); |
| 82 | size_t (*copy_to_user_small)(size_t, void __user *, const void *); |
| 83 | size_t (*copy_in_user)(size_t, void __user *, const void __user *); |
| 84 | size_t (*clear_user)(size_t, void __user *); |
| 85 | size_t (*strnlen_user)(size_t, const char __user *); |
| 86 | size_t (*strncpy_from_user)(size_t, const char __user *, char *); |
Michel Lespinasse | 8d7718a | 2011-03-10 18:50:58 -0800 | [diff] [blame] | 87 | int (*futex_atomic_op)(int op, u32 __user *, int oparg, int *old); |
| 88 | int (*futex_atomic_cmpxchg)(u32 *, u32 __user *, u32 old, u32 new); |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | extern struct uaccess_ops uaccess; |
| 92 | extern struct uaccess_ops uaccess_std; |
Gerald Schaefer | 6c2a9e6 | 2006-09-20 15:59:44 +0200 | [diff] [blame] | 93 | extern struct uaccess_ops uaccess_mvcos; |
Gerald Schaefer | c1821c2 | 2007-02-05 21:18:17 +0100 | [diff] [blame] | 94 | extern struct uaccess_ops uaccess_mvcos_switch; |
| 95 | extern struct uaccess_ops uaccess_pt; |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 96 | |
Gerald Schaefer | 6c1e3e7 | 2009-12-07 12:51:47 +0100 | [diff] [blame] | 97 | extern int __handle_fault(unsigned long, unsigned long, int); |
| 98 | |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 99 | static inline int __put_user_fn(size_t size, void __user *ptr, void *x) |
| 100 | { |
| 101 | size = uaccess.copy_to_user_small(size, ptr, x); |
| 102 | return size ? -EFAULT : size; |
| 103 | } |
| 104 | |
| 105 | static inline int __get_user_fn(size_t size, const void __user *ptr, void *x) |
| 106 | { |
| 107 | size = uaccess.copy_from_user_small(size, ptr, x); |
| 108 | return size ? -EFAULT : size; |
| 109 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | |
| 111 | /* |
| 112 | * These are the main single-value transfer routines. They automatically |
| 113 | * use the right size if we just have the right pointer type. |
| 114 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | #define __put_user(x, ptr) \ |
| 116 | ({ \ |
| 117 | __typeof__(*(ptr)) __x = (x); \ |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 118 | int __pu_err = -EFAULT; \ |
Al Viro | 17566c3 | 2005-08-23 22:48:22 +0100 | [diff] [blame] | 119 | __chk_user_ptr(ptr); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | switch (sizeof (*(ptr))) { \ |
| 121 | case 1: \ |
| 122 | case 2: \ |
| 123 | case 4: \ |
| 124 | case 8: \ |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 125 | __pu_err = __put_user_fn(sizeof (*(ptr)), \ |
| 126 | ptr, &__x); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | break; \ |
| 128 | default: \ |
| 129 | __put_user_bad(); \ |
| 130 | break; \ |
| 131 | } \ |
| 132 | __pu_err; \ |
| 133 | }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
| 135 | #define put_user(x, ptr) \ |
| 136 | ({ \ |
Heiko Carstens | dab4079d | 2009-06-12 10:26:32 +0200 | [diff] [blame] | 137 | might_fault(); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | __put_user(x, ptr); \ |
| 139 | }) |
| 140 | |
| 141 | |
| 142 | extern int __put_user_bad(void) __attribute__((noreturn)); |
| 143 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | #define __get_user(x, ptr) \ |
| 145 | ({ \ |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 146 | int __gu_err = -EFAULT; \ |
| 147 | __chk_user_ptr(ptr); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | switch (sizeof(*(ptr))) { \ |
Martin Schwidefsky | 1047aa7 | 2005-11-07 00:59:11 -0800 | [diff] [blame] | 149 | case 1: { \ |
| 150 | unsigned char __x; \ |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 151 | __gu_err = __get_user_fn(sizeof (*(ptr)), \ |
| 152 | ptr, &__x); \ |
Al Viro | 97fa5a6 | 2006-02-03 20:11:52 -0500 | [diff] [blame] | 153 | (x) = *(__force __typeof__(*(ptr)) *) &__x; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | break; \ |
Martin Schwidefsky | 1047aa7 | 2005-11-07 00:59:11 -0800 | [diff] [blame] | 155 | }; \ |
| 156 | case 2: { \ |
| 157 | unsigned short __x; \ |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 158 | __gu_err = __get_user_fn(sizeof (*(ptr)), \ |
| 159 | ptr, &__x); \ |
Al Viro | 97fa5a6 | 2006-02-03 20:11:52 -0500 | [diff] [blame] | 160 | (x) = *(__force __typeof__(*(ptr)) *) &__x; \ |
Martin Schwidefsky | 1047aa7 | 2005-11-07 00:59:11 -0800 | [diff] [blame] | 161 | break; \ |
| 162 | }; \ |
| 163 | case 4: { \ |
| 164 | unsigned int __x; \ |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 165 | __gu_err = __get_user_fn(sizeof (*(ptr)), \ |
| 166 | ptr, &__x); \ |
Al Viro | 97fa5a6 | 2006-02-03 20:11:52 -0500 | [diff] [blame] | 167 | (x) = *(__force __typeof__(*(ptr)) *) &__x; \ |
Martin Schwidefsky | 1047aa7 | 2005-11-07 00:59:11 -0800 | [diff] [blame] | 168 | break; \ |
| 169 | }; \ |
| 170 | case 8: { \ |
| 171 | unsigned long long __x; \ |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 172 | __gu_err = __get_user_fn(sizeof (*(ptr)), \ |
| 173 | ptr, &__x); \ |
Al Viro | 97fa5a6 | 2006-02-03 20:11:52 -0500 | [diff] [blame] | 174 | (x) = *(__force __typeof__(*(ptr)) *) &__x; \ |
Martin Schwidefsky | 1047aa7 | 2005-11-07 00:59:11 -0800 | [diff] [blame] | 175 | break; \ |
| 176 | }; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | default: \ |
| 178 | __get_user_bad(); \ |
| 179 | break; \ |
| 180 | } \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | __gu_err; \ |
| 182 | }) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
| 184 | #define get_user(x, ptr) \ |
| 185 | ({ \ |
Heiko Carstens | dab4079d | 2009-06-12 10:26:32 +0200 | [diff] [blame] | 186 | might_fault(); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | __get_user(x, ptr); \ |
| 188 | }) |
| 189 | |
| 190 | extern int __get_user_bad(void) __attribute__((noreturn)); |
| 191 | |
| 192 | #define __put_user_unaligned __put_user |
| 193 | #define __get_user_unaligned __get_user |
| 194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | /** |
| 196 | * __copy_to_user: - Copy a block of data into user space, with less checking. |
| 197 | * @to: Destination address, in user space. |
| 198 | * @from: Source address, in kernel space. |
| 199 | * @n: Number of bytes to copy. |
| 200 | * |
| 201 | * Context: User context only. This function may sleep. |
| 202 | * |
| 203 | * Copy data from kernel space to user space. Caller must check |
| 204 | * the specified block with access_ok() before calling this function. |
| 205 | * |
| 206 | * Returns number of bytes that could not be copied. |
| 207 | * On success, this will be zero. |
| 208 | */ |
Heiko Carstens | f7675ad | 2006-12-04 15:39:55 +0100 | [diff] [blame] | 209 | static inline unsigned long __must_check |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | __copy_to_user(void __user *to, const void *from, unsigned long n) |
| 211 | { |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 212 | if (__builtin_constant_p(n) && (n <= 256)) |
| 213 | return uaccess.copy_to_user_small(n, to, from); |
| 214 | else |
| 215 | return uaccess.copy_to_user(n, to, from); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
| 217 | |
| 218 | #define __copy_to_user_inatomic __copy_to_user |
| 219 | #define __copy_from_user_inatomic __copy_from_user |
| 220 | |
| 221 | /** |
| 222 | * copy_to_user: - Copy a block of data into user space. |
| 223 | * @to: Destination address, in user space. |
| 224 | * @from: Source address, in kernel space. |
| 225 | * @n: Number of bytes to copy. |
| 226 | * |
| 227 | * Context: User context only. This function may sleep. |
| 228 | * |
| 229 | * Copy data from kernel space to user space. |
| 230 | * |
| 231 | * Returns number of bytes that could not be copied. |
| 232 | * On success, this will be zero. |
| 233 | */ |
Heiko Carstens | f7675ad | 2006-12-04 15:39:55 +0100 | [diff] [blame] | 234 | static inline unsigned long __must_check |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | copy_to_user(void __user *to, const void *from, unsigned long n) |
| 236 | { |
Heiko Carstens | dab4079d | 2009-06-12 10:26:32 +0200 | [diff] [blame] | 237 | might_fault(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | if (access_ok(VERIFY_WRITE, to, n)) |
| 239 | n = __copy_to_user(to, from, n); |
| 240 | return n; |
| 241 | } |
| 242 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | /** |
| 244 | * __copy_from_user: - Copy a block of data from user space, with less checking. |
| 245 | * @to: Destination address, in kernel space. |
| 246 | * @from: Source address, in user space. |
| 247 | * @n: Number of bytes to copy. |
| 248 | * |
| 249 | * Context: User context only. This function may sleep. |
| 250 | * |
| 251 | * Copy data from user space to kernel space. Caller must check |
| 252 | * the specified block with access_ok() before calling this function. |
| 253 | * |
| 254 | * Returns number of bytes that could not be copied. |
| 255 | * On success, this will be zero. |
| 256 | * |
| 257 | * If some data could not be copied, this function will pad the copied |
| 258 | * data to the requested size using zero bytes. |
| 259 | */ |
Heiko Carstens | f7675ad | 2006-12-04 15:39:55 +0100 | [diff] [blame] | 260 | static inline unsigned long __must_check |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | __copy_from_user(void *to, const void __user *from, unsigned long n) |
| 262 | { |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 263 | if (__builtin_constant_p(n) && (n <= 256)) |
| 264 | return uaccess.copy_from_user_small(n, from, to); |
| 265 | else |
| 266 | return uaccess.copy_from_user(n, from, to); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | } |
| 268 | |
Heiko Carstens | 1dcec25 | 2010-02-26 22:37:22 +0100 | [diff] [blame] | 269 | extern void copy_from_user_overflow(void) |
| 270 | #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS |
| 271 | __compiletime_warning("copy_from_user() buffer size is not provably correct") |
| 272 | #endif |
| 273 | ; |
| 274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | /** |
| 276 | * copy_from_user: - Copy a block of data from user space. |
| 277 | * @to: Destination address, in kernel space. |
| 278 | * @from: Source address, in user space. |
| 279 | * @n: Number of bytes to copy. |
| 280 | * |
| 281 | * Context: User context only. This function may sleep. |
| 282 | * |
| 283 | * Copy data from user space to kernel space. |
| 284 | * |
| 285 | * Returns number of bytes that could not be copied. |
| 286 | * On success, this will be zero. |
| 287 | * |
| 288 | * If some data could not be copied, this function will pad the copied |
| 289 | * data to the requested size using zero bytes. |
| 290 | */ |
Heiko Carstens | f7675ad | 2006-12-04 15:39:55 +0100 | [diff] [blame] | 291 | static inline unsigned long __must_check |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | copy_from_user(void *to, const void __user *from, unsigned long n) |
| 293 | { |
Heiko Carstens | 1dcec25 | 2010-02-26 22:37:22 +0100 | [diff] [blame] | 294 | unsigned int sz = __compiletime_object_size(to); |
| 295 | |
Heiko Carstens | dab4079d | 2009-06-12 10:26:32 +0200 | [diff] [blame] | 296 | might_fault(); |
Heiko Carstens | 1dcec25 | 2010-02-26 22:37:22 +0100 | [diff] [blame] | 297 | if (unlikely(sz != -1 && sz < n)) { |
| 298 | copy_from_user_overflow(); |
| 299 | return n; |
| 300 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | if (access_ok(VERIFY_READ, from, n)) |
| 302 | n = __copy_from_user(to, from, n); |
| 303 | else |
| 304 | memset(to, 0, n); |
| 305 | return n; |
| 306 | } |
| 307 | |
Heiko Carstens | f7675ad | 2006-12-04 15:39:55 +0100 | [diff] [blame] | 308 | static inline unsigned long __must_check |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | __copy_in_user(void __user *to, const void __user *from, unsigned long n) |
| 310 | { |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 311 | return uaccess.copy_in_user(n, to, from); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Heiko Carstens | f7675ad | 2006-12-04 15:39:55 +0100 | [diff] [blame] | 314 | static inline unsigned long __must_check |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | copy_in_user(void __user *to, const void __user *from, unsigned long n) |
| 316 | { |
Heiko Carstens | dab4079d | 2009-06-12 10:26:32 +0200 | [diff] [blame] | 317 | might_fault(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | if (__access_ok(from,n) && __access_ok(to,n)) |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 319 | n = __copy_in_user(to, from, n); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | return n; |
| 321 | } |
| 322 | |
| 323 | /* |
| 324 | * Copy a null terminated string from userspace. |
| 325 | */ |
Heiko Carstens | f7675ad | 2006-12-04 15:39:55 +0100 | [diff] [blame] | 326 | static inline long __must_check |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | strncpy_from_user(char *dst, const char __user *src, long count) |
| 328 | { |
| 329 | long res = -EFAULT; |
Heiko Carstens | dab4079d | 2009-06-12 10:26:32 +0200 | [diff] [blame] | 330 | might_fault(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | if (access_ok(VERIFY_READ, src, 1)) |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 332 | res = uaccess.strncpy_from_user(count, src, dst); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | return res; |
| 334 | } |
| 335 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | static inline unsigned long |
| 337 | strnlen_user(const char __user * src, unsigned long n) |
| 338 | { |
Heiko Carstens | dab4079d | 2009-06-12 10:26:32 +0200 | [diff] [blame] | 339 | might_fault(); |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 340 | return uaccess.strnlen_user(n, src); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | } |
| 342 | |
| 343 | /** |
| 344 | * strlen_user: - Get the size of a string in user space. |
| 345 | * @str: The string to measure. |
| 346 | * |
| 347 | * Context: User context only. This function may sleep. |
| 348 | * |
| 349 | * Get the size of a NUL-terminated string in user space. |
| 350 | * |
| 351 | * Returns the size of the string INCLUDING the terminating NUL. |
| 352 | * On exception, returns 0. |
| 353 | * |
| 354 | * If there is a limit on the length of a valid string, you may wish to |
| 355 | * consider using strnlen_user() instead. |
| 356 | */ |
| 357 | #define strlen_user(str) strnlen_user(str, ~0UL) |
| 358 | |
| 359 | /* |
| 360 | * Zero Userspace |
| 361 | */ |
| 362 | |
Heiko Carstens | f7675ad | 2006-12-04 15:39:55 +0100 | [diff] [blame] | 363 | static inline unsigned long __must_check |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | __clear_user(void __user *to, unsigned long n) |
| 365 | { |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 366 | return uaccess.clear_user(n, to); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } |
| 368 | |
Heiko Carstens | f7675ad | 2006-12-04 15:39:55 +0100 | [diff] [blame] | 369 | static inline unsigned long __must_check |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | clear_user(void __user *to, unsigned long n) |
| 371 | { |
Heiko Carstens | dab4079d | 2009-06-12 10:26:32 +0200 | [diff] [blame] | 372 | might_fault(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | if (access_ok(VERIFY_WRITE, to, n)) |
Gerald Schaefer | d02765d | 2006-09-20 15:59:42 +0200 | [diff] [blame] | 374 | n = uaccess.clear_user(n, to); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | return n; |
| 376 | } |
| 377 | |
| 378 | #endif /* __S390_UACCESS_H */ |