Michal Simek | 2660663 | 2009-03-27 14:25:23 +0100 | [diff] [blame] | 1 | /* |
Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 2 | * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu> |
| 3 | * Copyright (C) 2008-2009 PetaLogix |
Michal Simek | 2660663 | 2009-03-27 14:25:23 +0100 | [diff] [blame] | 4 | * Copyright (C) 2006 Atmark Techno, Inc. |
| 5 | * |
| 6 | * This file is subject to the terms and conditions of the GNU General Public |
| 7 | * License. See the file "COPYING" in the main directory of this archive |
| 8 | * for more details. |
| 9 | */ |
| 10 | |
| 11 | #ifndef _ASM_MICROBLAZE_UACCESS_H |
| 12 | #define _ASM_MICROBLAZE_UACCESS_H |
| 13 | |
Michal Simek | 2660663 | 2009-03-27 14:25:23 +0100 | [diff] [blame] | 14 | #include <linux/kernel.h> |
Michal Simek | 2660663 | 2009-03-27 14:25:23 +0100 | [diff] [blame] | 15 | #include <linux/mm.h> |
| 16 | |
| 17 | #include <asm/mmu.h> |
| 18 | #include <asm/page.h> |
| 19 | #include <asm/pgtable.h> |
Al Viro | 730132e | 2016-12-25 14:34:44 -0500 | [diff] [blame] | 20 | #include <asm/extable.h> |
Michal Simek | 2660663 | 2009-03-27 14:25:23 +0100 | [diff] [blame] | 21 | #include <linux/string.h> |
| 22 | |
Michal Simek | 40db083 | 2010-03-05 15:34:12 +0100 | [diff] [blame] | 23 | /* |
| 24 | * On Microblaze the fs value is actually the top of the corresponding |
| 25 | * address space. |
| 26 | * |
| 27 | * The fs value determines whether argument validity checking should be |
| 28 | * performed or not. If get_fs() == USER_DS, checking is performed, with |
| 29 | * get_fs() == KERNEL_DS, checking is bypassed. |
| 30 | * |
| 31 | * For historical reasons, these macros are grossly misnamed. |
| 32 | * |
| 33 | * For non-MMU arch like Microblaze, KERNEL_DS and USER_DS is equal. |
| 34 | */ |
| 35 | # define MAKE_MM_SEG(s) ((mm_segment_t) { (s) }) |
| 36 | |
| 37 | # ifndef CONFIG_MMU |
| 38 | # define KERNEL_DS MAKE_MM_SEG(0) |
| 39 | # define USER_DS KERNEL_DS |
| 40 | # else |
| 41 | # define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF) |
| 42 | # define USER_DS MAKE_MM_SEG(TASK_SIZE - 1) |
| 43 | # endif |
| 44 | |
| 45 | # define get_ds() (KERNEL_DS) |
| 46 | # define get_fs() (current_thread_info()->addr_limit) |
| 47 | # define set_fs(val) (current_thread_info()->addr_limit = (val)) |
| 48 | |
| 49 | # define segment_eq(a, b) ((a).seg == (b).seg) |
| 50 | |
Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 51 | #ifndef CONFIG_MMU |
| 52 | |
Michal Simek | 60a729f | 2010-03-05 15:49:53 +0100 | [diff] [blame] | 53 | /* Check against bounds of physical memory */ |
| 54 | static inline int ___range_ok(unsigned long addr, unsigned long size) |
| 55 | { |
| 56 | return ((addr < memory_start) || |
Michal Simek | 83a9252 | 2011-12-19 13:46:35 +0100 | [diff] [blame] | 57 | ((addr + size - 1) > (memory_start + memory_size - 1))); |
Michal Simek | 60a729f | 2010-03-05 15:49:53 +0100 | [diff] [blame] | 58 | } |
Michal Simek | 2660663 | 2009-03-27 14:25:23 +0100 | [diff] [blame] | 59 | |
| 60 | #define __range_ok(addr, size) \ |
| 61 | ___range_ok((unsigned long)(addr), (unsigned long)(size)) |
| 62 | |
| 63 | #define access_ok(type, addr, size) (__range_ok((addr), (size)) == 0) |
Michal Simek | 40b1156 | 2010-03-05 16:50:01 +0100 | [diff] [blame] | 64 | |
| 65 | #else |
| 66 | |
Michal Simek | f663b60 | 2013-03-28 16:42:44 +0100 | [diff] [blame] | 67 | static inline int access_ok(int type, const void __user *addr, |
| 68 | unsigned long size) |
| 69 | { |
| 70 | if (!size) |
| 71 | goto ok; |
Michal Simek | 40b1156 | 2010-03-05 16:50:01 +0100 | [diff] [blame] | 72 | |
Michal Simek | f663b60 | 2013-03-28 16:42:44 +0100 | [diff] [blame] | 73 | if ((get_fs().seg < ((unsigned long)addr)) || |
| 74 | (get_fs().seg < ((unsigned long)addr + size - 1))) { |
Chen Gang | de295cf | 2014-08-06 00:25:52 +0800 | [diff] [blame] | 75 | pr_devel("ACCESS fail: %s at 0x%08x (size 0x%x), seg 0x%08x\n", |
Michal Simek | 8706a6b | 2013-05-30 15:10:52 +0200 | [diff] [blame] | 76 | type ? "WRITE" : "READ ", (__force u32)addr, (u32)size, |
Michal Simek | f663b60 | 2013-03-28 16:42:44 +0100 | [diff] [blame] | 77 | (u32)get_fs().seg); |
| 78 | return 0; |
| 79 | } |
| 80 | ok: |
Chen Gang | de295cf | 2014-08-06 00:25:52 +0800 | [diff] [blame] | 81 | pr_devel("ACCESS OK: %s at 0x%08x (size 0x%x), seg 0x%08x\n", |
Michal Simek | 8706a6b | 2013-05-30 15:10:52 +0200 | [diff] [blame] | 82 | type ? "WRITE" : "READ ", (__force u32)addr, (u32)size, |
Michal Simek | f663b60 | 2013-03-28 16:42:44 +0100 | [diff] [blame] | 83 | (u32)get_fs().seg); |
| 84 | return 1; |
| 85 | } |
Michal Simek | 40b1156 | 2010-03-05 16:50:01 +0100 | [diff] [blame] | 86 | #endif |
| 87 | |
| 88 | #ifdef CONFIG_MMU |
| 89 | # define __FIXUP_SECTION ".section .fixup,\"ax\"\n" |
| 90 | # define __EX_TABLE_SECTION ".section __ex_table,\"a\"\n" |
| 91 | #else |
| 92 | # define __FIXUP_SECTION ".section .discard,\"ax\"\n" |
Michal Simek | 7e27815 | 2012-12-21 10:53:40 +0100 | [diff] [blame] | 93 | # define __EX_TABLE_SECTION ".section .discard,\"ax\"\n" |
Michal Simek | 40b1156 | 2010-03-05 16:50:01 +0100 | [diff] [blame] | 94 | #endif |
| 95 | |
Michal Simek | 94804a9 | 2010-03-22 18:39:20 +0100 | [diff] [blame] | 96 | extern unsigned long __copy_tofrom_user(void __user *to, |
| 97 | const void __user *from, unsigned long size); |
| 98 | |
Michal Simek | 527bdb5 | 2010-03-22 16:02:59 +0100 | [diff] [blame] | 99 | /* Return: number of not copied bytes, i.e. 0 if OK or non-zero if fail. */ |
| 100 | static inline unsigned long __must_check __clear_user(void __user *to, |
| 101 | unsigned long n) |
| 102 | { |
| 103 | /* normal memset with two words to __ex_table */ |
| 104 | __asm__ __volatile__ ( \ |
Steven J. Magnani | 6f3946b | 2011-02-10 12:12:13 -0600 | [diff] [blame] | 105 | "1: sb r0, %1, r0;" \ |
Michal Simek | 527bdb5 | 2010-03-22 16:02:59 +0100 | [diff] [blame] | 106 | " addik %0, %0, -1;" \ |
| 107 | " bneid %0, 1b;" \ |
Steven J. Magnani | 6f3946b | 2011-02-10 12:12:13 -0600 | [diff] [blame] | 108 | " addik %1, %1, 1;" \ |
Michal Simek | 527bdb5 | 2010-03-22 16:02:59 +0100 | [diff] [blame] | 109 | "2: " \ |
| 110 | __EX_TABLE_SECTION \ |
| 111 | ".word 1b,2b;" \ |
| 112 | ".previous;" \ |
Steven J. Magnani | 6f3946b | 2011-02-10 12:12:13 -0600 | [diff] [blame] | 113 | : "=r"(n), "=r"(to) \ |
| 114 | : "0"(n), "1"(to) |
Michal Simek | 527bdb5 | 2010-03-22 16:02:59 +0100 | [diff] [blame] | 115 | ); |
| 116 | return n; |
| 117 | } |
| 118 | |
| 119 | static inline unsigned long __must_check clear_user(void __user *to, |
| 120 | unsigned long n) |
| 121 | { |
Michael S. Tsirkin | ac093f8 | 2013-05-26 17:30:56 +0300 | [diff] [blame] | 122 | might_fault(); |
Michal Simek | 527bdb5 | 2010-03-22 16:02:59 +0100 | [diff] [blame] | 123 | if (unlikely(!access_ok(VERIFY_WRITE, to, n))) |
| 124 | return n; |
| 125 | |
| 126 | return __clear_user(to, n); |
| 127 | } |
| 128 | |
Michal Simek | cca7912 | 2010-03-22 18:23:45 +0100 | [diff] [blame] | 129 | /* put_user and get_user macros */ |
Michal Simek | 3a6d772 | 2010-03-08 10:52:24 +0100 | [diff] [blame] | 130 | extern long __user_bad(void); |
Arnd Bergmann | 838d240 | 2009-05-01 13:36:13 +0000 | [diff] [blame] | 131 | |
Michal Simek | 3a6d772 | 2010-03-08 10:52:24 +0100 | [diff] [blame] | 132 | #define __get_user_asm(insn, __gu_ptr, __gu_val, __gu_err) \ |
| 133 | ({ \ |
| 134 | __asm__ __volatile__ ( \ |
| 135 | "1:" insn " %1, %2, r0;" \ |
| 136 | " addk %0, r0, r0;" \ |
| 137 | "2: " \ |
| 138 | __FIXUP_SECTION \ |
| 139 | "3: brid 2b;" \ |
| 140 | " addik %0, r0, %3;" \ |
| 141 | ".previous;" \ |
| 142 | __EX_TABLE_SECTION \ |
| 143 | ".word 1b,3b;" \ |
| 144 | ".previous;" \ |
| 145 | : "=&r"(__gu_err), "=r"(__gu_val) \ |
| 146 | : "r"(__gu_ptr), "i"(-EFAULT) \ |
| 147 | ); \ |
Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 148 | }) |
Michal Simek | 2660663 | 2009-03-27 14:25:23 +0100 | [diff] [blame] | 149 | |
Michal Simek | 3a6d772 | 2010-03-08 10:52:24 +0100 | [diff] [blame] | 150 | /** |
| 151 | * get_user: - Get a simple variable from user space. |
| 152 | * @x: Variable to store result. |
| 153 | * @ptr: Source address, in user space. |
| 154 | * |
David Hildenbrand | b3c395ef | 2015-05-11 17:52:08 +0200 | [diff] [blame] | 155 | * Context: User context only. This function may sleep if pagefaults are |
| 156 | * enabled. |
Michal Simek | 3a6d772 | 2010-03-08 10:52:24 +0100 | [diff] [blame] | 157 | * |
| 158 | * This macro copies a single simple variable from user space to kernel |
| 159 | * space. It supports simple types like char and int, but not larger |
| 160 | * data types like structures or arrays. |
| 161 | * |
| 162 | * @ptr must have pointer-to-simple-variable type, and the result of |
| 163 | * dereferencing @ptr must be assignable to @x without a cast. |
| 164 | * |
| 165 | * Returns zero on success, or -EFAULT on error. |
| 166 | * On error, the variable @x is set to zero. |
| 167 | */ |
Steven J. Magnani | 538722c | 2010-05-06 16:38:33 -0500 | [diff] [blame] | 168 | #define get_user(x, ptr) \ |
| 169 | __get_user_check((x), (ptr), sizeof(*(ptr))) |
| 170 | |
| 171 | #define __get_user_check(x, ptr, size) \ |
| 172 | ({ \ |
| 173 | unsigned long __gu_val = 0; \ |
| 174 | const typeof(*(ptr)) __user *__gu_addr = (ptr); \ |
| 175 | int __gu_err = 0; \ |
| 176 | \ |
| 177 | if (access_ok(VERIFY_READ, __gu_addr, size)) { \ |
| 178 | switch (size) { \ |
| 179 | case 1: \ |
| 180 | __get_user_asm("lbu", __gu_addr, __gu_val, \ |
| 181 | __gu_err); \ |
| 182 | break; \ |
| 183 | case 2: \ |
| 184 | __get_user_asm("lhu", __gu_addr, __gu_val, \ |
| 185 | __gu_err); \ |
| 186 | break; \ |
| 187 | case 4: \ |
| 188 | __get_user_asm("lw", __gu_addr, __gu_val, \ |
| 189 | __gu_err); \ |
| 190 | break; \ |
| 191 | default: \ |
| 192 | __gu_err = __user_bad(); \ |
| 193 | break; \ |
| 194 | } \ |
| 195 | } else { \ |
| 196 | __gu_err = -EFAULT; \ |
| 197 | } \ |
Michael S. Tsirkin | 0774bf6 | 2015-01-06 17:44:02 +0200 | [diff] [blame] | 198 | x = (__force typeof(*(ptr)))__gu_val; \ |
Steven J. Magnani | 538722c | 2010-05-06 16:38:33 -0500 | [diff] [blame] | 199 | __gu_err; \ |
| 200 | }) |
Michal Simek | 3a6d772 | 2010-03-08 10:52:24 +0100 | [diff] [blame] | 201 | |
| 202 | #define __get_user(x, ptr) \ |
| 203 | ({ \ |
Al Viro | e98b9e3 | 2016-09-09 19:23:33 -0400 | [diff] [blame] | 204 | unsigned long __gu_val = 0; \ |
Michal Simek | 3a6d772 | 2010-03-08 10:52:24 +0100 | [diff] [blame] | 205 | /*unsigned long __gu_ptr = (unsigned long)(ptr);*/ \ |
| 206 | long __gu_err; \ |
| 207 | switch (sizeof(*(ptr))) { \ |
| 208 | case 1: \ |
| 209 | __get_user_asm("lbu", (ptr), __gu_val, __gu_err); \ |
| 210 | break; \ |
| 211 | case 2: \ |
| 212 | __get_user_asm("lhu", (ptr), __gu_val, __gu_err); \ |
| 213 | break; \ |
| 214 | case 4: \ |
| 215 | __get_user_asm("lw", (ptr), __gu_val, __gu_err); \ |
| 216 | break; \ |
| 217 | default: \ |
| 218 | /* __gu_val = 0; __gu_err = -EINVAL;*/ __gu_err = __user_bad();\ |
| 219 | } \ |
Michael S. Tsirkin | 0774bf6 | 2015-01-06 17:44:02 +0200 | [diff] [blame] | 220 | x = (__force __typeof__(*(ptr))) __gu_val; \ |
Michal Simek | 3a6d772 | 2010-03-08 10:52:24 +0100 | [diff] [blame] | 221 | __gu_err; \ |
| 222 | }) |
| 223 | |
| 224 | |
Michal Simek | ef4e277 | 2010-03-22 16:22:41 +0100 | [diff] [blame] | 225 | #define __put_user_asm(insn, __gu_ptr, __gu_val, __gu_err) \ |
Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 226 | ({ \ |
Michal Simek | ef4e277 | 2010-03-22 16:22:41 +0100 | [diff] [blame] | 227 | __asm__ __volatile__ ( \ |
| 228 | "1:" insn " %1, %2, r0;" \ |
| 229 | " addk %0, r0, r0;" \ |
| 230 | "2: " \ |
| 231 | __FIXUP_SECTION \ |
| 232 | "3: brid 2b;" \ |
| 233 | " addik %0, r0, %3;" \ |
| 234 | ".previous;" \ |
| 235 | __EX_TABLE_SECTION \ |
| 236 | ".word 1b,3b;" \ |
| 237 | ".previous;" \ |
| 238 | : "=&r"(__gu_err) \ |
| 239 | : "r"(__gu_val), "r"(__gu_ptr), "i"(-EFAULT) \ |
| 240 | ); \ |
Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 241 | }) |
Michal Simek | 2660663 | 2009-03-27 14:25:23 +0100 | [diff] [blame] | 242 | |
Michal Simek | ef4e277 | 2010-03-22 16:22:41 +0100 | [diff] [blame] | 243 | #define __put_user_asm_8(__gu_ptr, __gu_val, __gu_err) \ |
| 244 | ({ \ |
| 245 | __asm__ __volatile__ (" lwi %0, %1, 0;" \ |
| 246 | "1: swi %0, %2, 0;" \ |
| 247 | " lwi %0, %1, 4;" \ |
| 248 | "2: swi %0, %2, 4;" \ |
| 249 | " addk %0, r0, r0;" \ |
| 250 | "3: " \ |
| 251 | __FIXUP_SECTION \ |
| 252 | "4: brid 3b;" \ |
| 253 | " addik %0, r0, %3;" \ |
| 254 | ".previous;" \ |
| 255 | __EX_TABLE_SECTION \ |
| 256 | ".word 1b,4b,2b,4b;" \ |
| 257 | ".previous;" \ |
| 258 | : "=&r"(__gu_err) \ |
| 259 | : "r"(&__gu_val), "r"(__gu_ptr), "i"(-EFAULT) \ |
| 260 | ); \ |
| 261 | }) |
| 262 | |
Michal Simek | 0dcb409 | 2010-03-22 15:46:56 +0100 | [diff] [blame] | 263 | /** |
| 264 | * put_user: - Write a simple value into user space. |
| 265 | * @x: Value to copy to user space. |
| 266 | * @ptr: Destination address, in user space. |
| 267 | * |
David Hildenbrand | b3c395ef | 2015-05-11 17:52:08 +0200 | [diff] [blame] | 268 | * Context: User context only. This function may sleep if pagefaults are |
| 269 | * enabled. |
Michal Simek | 0dcb409 | 2010-03-22 15:46:56 +0100 | [diff] [blame] | 270 | * |
| 271 | * This macro copies a single simple value from kernel space to user |
| 272 | * space. It supports simple types like char and int, but not larger |
| 273 | * data types like structures or arrays. |
| 274 | * |
| 275 | * @ptr must have pointer-to-simple-variable type, and @x must be assignable |
| 276 | * to the result of dereferencing @ptr. |
| 277 | * |
| 278 | * Returns zero on success, or -EFAULT on error. |
| 279 | */ |
Steven J. Magnani | 538722c | 2010-05-06 16:38:33 -0500 | [diff] [blame] | 280 | #define put_user(x, ptr) \ |
| 281 | __put_user_check((x), (ptr), sizeof(*(ptr))) |
| 282 | |
| 283 | #define __put_user_check(x, ptr, size) \ |
| 284 | ({ \ |
Michael S. Tsirkin | 132d5df | 2015-01-06 17:45:03 +0200 | [diff] [blame] | 285 | typeof(*(ptr)) volatile __pu_val = x; \ |
Steven J. Magnani | 538722c | 2010-05-06 16:38:33 -0500 | [diff] [blame] | 286 | typeof(*(ptr)) __user *__pu_addr = (ptr); \ |
| 287 | int __pu_err = 0; \ |
| 288 | \ |
Steven J. Magnani | 538722c | 2010-05-06 16:38:33 -0500 | [diff] [blame] | 289 | if (access_ok(VERIFY_WRITE, __pu_addr, size)) { \ |
| 290 | switch (size) { \ |
| 291 | case 1: \ |
| 292 | __put_user_asm("sb", __pu_addr, __pu_val, \ |
| 293 | __pu_err); \ |
| 294 | break; \ |
| 295 | case 2: \ |
| 296 | __put_user_asm("sh", __pu_addr, __pu_val, \ |
| 297 | __pu_err); \ |
| 298 | break; \ |
| 299 | case 4: \ |
| 300 | __put_user_asm("sw", __pu_addr, __pu_val, \ |
| 301 | __pu_err); \ |
| 302 | break; \ |
| 303 | case 8: \ |
| 304 | __put_user_asm_8(__pu_addr, __pu_val, __pu_err);\ |
| 305 | break; \ |
| 306 | default: \ |
| 307 | __pu_err = __user_bad(); \ |
| 308 | break; \ |
| 309 | } \ |
| 310 | } else { \ |
| 311 | __pu_err = -EFAULT; \ |
| 312 | } \ |
| 313 | __pu_err; \ |
| 314 | }) |
Michal Simek | 0dcb409 | 2010-03-22 15:46:56 +0100 | [diff] [blame] | 315 | |
Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 316 | #define __put_user(x, ptr) \ |
| 317 | ({ \ |
Michal Simek | 7bcb63b | 2009-07-13 16:46:54 +0200 | [diff] [blame] | 318 | __typeof__(*(ptr)) volatile __gu_val = (x); \ |
Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 319 | long __gu_err = 0; \ |
| 320 | switch (sizeof(__gu_val)) { \ |
| 321 | case 1: \ |
| 322 | __put_user_asm("sb", (ptr), __gu_val, __gu_err); \ |
| 323 | break; \ |
Michal Simek | cca7912 | 2010-03-22 18:23:45 +0100 | [diff] [blame] | 324 | case 2: \ |
Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 325 | __put_user_asm("sh", (ptr), __gu_val, __gu_err); \ |
| 326 | break; \ |
| 327 | case 4: \ |
| 328 | __put_user_asm("sw", (ptr), __gu_val, __gu_err); \ |
| 329 | break; \ |
| 330 | case 8: \ |
| 331 | __put_user_asm_8((ptr), __gu_val, __gu_err); \ |
| 332 | break; \ |
| 333 | default: \ |
Michal Simek | 0dcb409 | 2010-03-22 15:46:56 +0100 | [diff] [blame] | 334 | /*__gu_err = -EINVAL;*/ __gu_err = __user_bad(); \ |
Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 335 | } \ |
| 336 | __gu_err; \ |
| 337 | }) |
| 338 | |
Al Viro | d491afb | 2017-03-21 12:10:12 -0400 | [diff] [blame] | 339 | static inline unsigned long |
| 340 | raw_copy_from_user(void *to, const void __user *from, unsigned long n) |
Michal Simek | 4270690 | 2010-03-22 15:56:32 +0100 | [diff] [blame] | 341 | { |
Al Viro | d491afb | 2017-03-21 12:10:12 -0400 | [diff] [blame] | 342 | return __copy_tofrom_user((__force void __user *)to, from, n); |
Michal Simek | 4270690 | 2010-03-22 15:56:32 +0100 | [diff] [blame] | 343 | } |
| 344 | |
Al Viro | d491afb | 2017-03-21 12:10:12 -0400 | [diff] [blame] | 345 | static inline unsigned long |
| 346 | raw_copy_to_user(void __user *to, const void *from, unsigned long n) |
Michal Simek | cc5a428 | 2010-03-22 15:52:53 +0100 | [diff] [blame] | 347 | { |
Al Viro | d491afb | 2017-03-21 12:10:12 -0400 | [diff] [blame] | 348 | return __copy_tofrom_user(to, (__force const void __user *)from, n); |
Michal Simek | 89ae975 | 2010-03-22 18:49:45 +0100 | [diff] [blame] | 349 | } |
Al Viro | d491afb | 2017-03-21 12:10:12 -0400 | [diff] [blame] | 350 | #define INLINE_COPY_FROM_USER |
| 351 | #define INLINE_COPY_TO_USER |
Michal Simek | 89ae975 | 2010-03-22 18:49:45 +0100 | [diff] [blame] | 352 | |
| 353 | /* |
| 354 | * Copy a null terminated string from userspace. |
| 355 | */ |
| 356 | extern int __strncpy_user(char *to, const char __user *from, int len); |
| 357 | |
| 358 | #define __strncpy_from_user __strncpy_user |
| 359 | |
| 360 | static inline long |
| 361 | strncpy_from_user(char *dst, const char __user *src, long count) |
| 362 | { |
| 363 | if (!access_ok(VERIFY_READ, src, 1)) |
| 364 | return -EFAULT; |
| 365 | return __strncpy_from_user(dst, src, count); |
| 366 | } |
| 367 | |
| 368 | /* |
| 369 | * Return the size of a string (including the ending 0) |
| 370 | * |
| 371 | * Return 0 on exception, a value greater than N if too long |
| 372 | */ |
| 373 | extern int __strnlen_user(const char __user *sstr, int len); |
| 374 | |
| 375 | static inline long strnlen_user(const char __user *src, long n) |
| 376 | { |
| 377 | if (!access_ok(VERIFY_READ, src, 1)) |
| 378 | return 0; |
| 379 | return __strnlen_user(src, n); |
Michal Simek | cc5a428 | 2010-03-22 15:52:53 +0100 | [diff] [blame] | 380 | } |
| 381 | |
Michal Simek | 2660663 | 2009-03-27 14:25:23 +0100 | [diff] [blame] | 382 | #endif /* _ASM_MICROBLAZE_UACCESS_H */ |