| 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 |  | 
 | 14 | #ifdef __KERNEL__ | 
 | 15 | #ifndef __ASSEMBLY__ | 
 | 16 |  | 
 | 17 | #include <linux/kernel.h> | 
 | 18 | #include <linux/errno.h> | 
 | 19 | #include <linux/sched.h> /* RLIMIT_FSIZE */ | 
 | 20 | #include <linux/mm.h> | 
 | 21 |  | 
 | 22 | #include <asm/mmu.h> | 
 | 23 | #include <asm/page.h> | 
 | 24 | #include <asm/pgtable.h> | 
| Michal Simek | 2660663 | 2009-03-27 14:25:23 +0100 | [diff] [blame] | 25 | #include <linux/string.h> | 
 | 26 |  | 
 | 27 | #define VERIFY_READ	0 | 
 | 28 | #define VERIFY_WRITE	1 | 
 | 29 |  | 
| Michal Simek | 40db083 | 2010-03-05 15:34:12 +0100 | [diff] [blame] | 30 | /* | 
 | 31 |  * On Microblaze the fs value is actually the top of the corresponding | 
 | 32 |  * address space. | 
 | 33 |  * | 
 | 34 |  * The fs value determines whether argument validity checking should be | 
 | 35 |  * performed or not. If get_fs() == USER_DS, checking is performed, with | 
 | 36 |  * get_fs() == KERNEL_DS, checking is bypassed. | 
 | 37 |  * | 
 | 38 |  * For historical reasons, these macros are grossly misnamed. | 
 | 39 |  * | 
 | 40 |  * For non-MMU arch like Microblaze, KERNEL_DS and USER_DS is equal. | 
 | 41 |  */ | 
 | 42 | # define MAKE_MM_SEG(s)       ((mm_segment_t) { (s) }) | 
 | 43 |  | 
 | 44 | #  ifndef CONFIG_MMU | 
 | 45 | #  define KERNEL_DS	MAKE_MM_SEG(0) | 
 | 46 | #  define USER_DS	KERNEL_DS | 
 | 47 | #  else | 
 | 48 | #  define KERNEL_DS	MAKE_MM_SEG(0xFFFFFFFF) | 
 | 49 | #  define USER_DS	MAKE_MM_SEG(TASK_SIZE - 1) | 
 | 50 | #  endif | 
 | 51 |  | 
 | 52 | # define get_ds()	(KERNEL_DS) | 
 | 53 | # define get_fs()	(current_thread_info()->addr_limit) | 
 | 54 | # define set_fs(val)	(current_thread_info()->addr_limit = (val)) | 
 | 55 |  | 
 | 56 | # define segment_eq(a, b)	((a).seg == (b).seg) | 
 | 57 |  | 
| Michal Simek | 357bc3c | 2010-03-05 15:37:57 +0100 | [diff] [blame] | 58 | /* | 
 | 59 |  * The exception table consists of pairs of addresses: the first is the | 
 | 60 |  * address of an instruction that is allowed to fault, and the second is | 
 | 61 |  * the address at which the program should continue. No registers are | 
 | 62 |  * modified, so it is entirely up to the continuation code to figure out | 
 | 63 |  * what to do. | 
 | 64 |  * | 
 | 65 |  * All the routines below use bits of fixup code that are out of line | 
 | 66 |  * with the main instruction path. This means when everything is well, | 
 | 67 |  * we don't even have to jump over them. Further, they do not intrude | 
 | 68 |  * on our cache or tlb entries. | 
 | 69 |  */ | 
 | 70 | struct exception_table_entry { | 
 | 71 | 	unsigned long insn, fixup; | 
 | 72 | }; | 
| Michal Simek | 40db083 | 2010-03-05 15:34:12 +0100 | [diff] [blame] | 73 |  | 
| Michal Simek | 527bdb5 | 2010-03-22 16:02:59 +0100 | [diff] [blame] | 74 | /* Returns 0 if exception not found and fixup otherwise.  */ | 
 | 75 | extern unsigned long search_exception_table(unsigned long); | 
 | 76 |  | 
| Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 77 | #ifndef CONFIG_MMU | 
 | 78 |  | 
| Michal Simek | 60a729f | 2010-03-05 15:49:53 +0100 | [diff] [blame] | 79 | /* Check against bounds of physical memory */ | 
 | 80 | static inline int ___range_ok(unsigned long addr, unsigned long size) | 
 | 81 | { | 
 | 82 | 	return ((addr < memory_start) || | 
 | 83 | 		((addr + size) > memory_end)); | 
 | 84 | } | 
| Michal Simek | 2660663 | 2009-03-27 14:25:23 +0100 | [diff] [blame] | 85 |  | 
 | 86 | #define __range_ok(addr, size) \ | 
 | 87 | 		___range_ok((unsigned long)(addr), (unsigned long)(size)) | 
 | 88 |  | 
 | 89 | #define access_ok(type, addr, size) (__range_ok((addr), (size)) == 0) | 
| Michal Simek | 40b1156 | 2010-03-05 16:50:01 +0100 | [diff] [blame] | 90 |  | 
 | 91 | #else | 
 | 92 |  | 
 | 93 | /* | 
 | 94 |  * Address is valid if: | 
 | 95 |  *  - "addr", "addr + size" and "size" are all below the limit | 
 | 96 |  */ | 
 | 97 | #define access_ok(type, addr, size) \ | 
 | 98 | 	(get_fs().seg > (((unsigned long)(addr)) | \ | 
 | 99 | 		(size) | ((unsigned long)(addr) + (size)))) | 
 | 100 |  | 
 | 101 | /* || printk("access_ok failed for %s at 0x%08lx (size %d), seg 0x%08x\n", | 
 | 102 |  type?"WRITE":"READ",addr,size,get_fs().seg)) */ | 
 | 103 |  | 
 | 104 | #endif | 
 | 105 |  | 
 | 106 | #ifdef CONFIG_MMU | 
 | 107 | # define __FIXUP_SECTION	".section .fixup,\"ax\"\n" | 
 | 108 | # define __EX_TABLE_SECTION	".section __ex_table,\"a\"\n" | 
 | 109 | #else | 
 | 110 | # define __FIXUP_SECTION	".section .discard,\"ax\"\n" | 
 | 111 | # define __EX_TABLE_SECTION	".section .discard,\"a\"\n" | 
 | 112 | #endif | 
 | 113 |  | 
| Michal Simek | 527bdb5 | 2010-03-22 16:02:59 +0100 | [diff] [blame] | 114 | /* Return: number of not copied bytes, i.e. 0 if OK or non-zero if fail. */ | 
 | 115 | static inline unsigned long __must_check __clear_user(void __user *to, | 
 | 116 | 							unsigned long n) | 
 | 117 | { | 
 | 118 | 	/* normal memset with two words to __ex_table */ | 
 | 119 | 	__asm__ __volatile__ (				\ | 
 | 120 | 			"1:	sb	r0, %2, r0;"	\ | 
 | 121 | 			"	addik	%0, %0, -1;"	\ | 
 | 122 | 			"	bneid	%0, 1b;"	\ | 
 | 123 | 			"	addik	%2, %2, 1;"	\ | 
 | 124 | 			"2:			"	\ | 
 | 125 | 			__EX_TABLE_SECTION		\ | 
 | 126 | 			".word	1b,2b;"			\ | 
 | 127 | 			".previous;"			\ | 
 | 128 | 		: "=r"(n)				\ | 
 | 129 | 		: "0"(n), "r"(to) | 
 | 130 | 	); | 
 | 131 | 	return n; | 
 | 132 | } | 
 | 133 |  | 
 | 134 | static inline unsigned long __must_check clear_user(void __user *to, | 
 | 135 | 							unsigned long n) | 
 | 136 | { | 
 | 137 | 	might_sleep(); | 
 | 138 | 	if (unlikely(!access_ok(VERIFY_WRITE, to, n))) | 
 | 139 | 		return n; | 
 | 140 |  | 
 | 141 | 	return __clear_user(to, n); | 
 | 142 | } | 
 | 143 |  | 
| Michal Simek | cca7912 | 2010-03-22 18:23:45 +0100 | [diff] [blame^] | 144 | /* put_user and get_user macros */ | 
| Michal Simek | 3a6d772 | 2010-03-08 10:52:24 +0100 | [diff] [blame] | 145 | extern long __user_bad(void); | 
| Arnd Bergmann | 838d240 | 2009-05-01 13:36:13 +0000 | [diff] [blame] | 146 |  | 
| Michal Simek | 3a6d772 | 2010-03-08 10:52:24 +0100 | [diff] [blame] | 147 | #define __get_user_asm(insn, __gu_ptr, __gu_val, __gu_err)	\ | 
 | 148 | ({								\ | 
 | 149 | 	__asm__ __volatile__ (					\ | 
 | 150 | 			"1:"	insn	" %1, %2, r0;"		\ | 
 | 151 | 			"	addk	%0, r0, r0;"		\ | 
 | 152 | 			"2:			"		\ | 
 | 153 | 			__FIXUP_SECTION				\ | 
 | 154 | 			"3:	brid	2b;"			\ | 
 | 155 | 			"	addik	%0, r0, %3;"		\ | 
 | 156 | 			".previous;"				\ | 
 | 157 | 			__EX_TABLE_SECTION			\ | 
 | 158 | 			".word	1b,3b;"				\ | 
 | 159 | 			".previous;"				\ | 
 | 160 | 		: "=&r"(__gu_err), "=r"(__gu_val)		\ | 
 | 161 | 		: "r"(__gu_ptr), "i"(-EFAULT)			\ | 
 | 162 | 	);							\ | 
| Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 163 | }) | 
| Michal Simek | 2660663 | 2009-03-27 14:25:23 +0100 | [diff] [blame] | 164 |  | 
| Michal Simek | 3a6d772 | 2010-03-08 10:52:24 +0100 | [diff] [blame] | 165 | /** | 
 | 166 |  * get_user: - Get a simple variable from user space. | 
 | 167 |  * @x:   Variable to store result. | 
 | 168 |  * @ptr: Source address, in user space. | 
 | 169 |  * | 
 | 170 |  * Context: User context only.  This function may sleep. | 
 | 171 |  * | 
 | 172 |  * This macro copies a single simple variable from user space to kernel | 
 | 173 |  * space.  It supports simple types like char and int, but not larger | 
 | 174 |  * data types like structures or arrays. | 
 | 175 |  * | 
 | 176 |  * @ptr must have pointer-to-simple-variable type, and the result of | 
 | 177 |  * dereferencing @ptr must be assignable to @x without a cast. | 
 | 178 |  * | 
 | 179 |  * Returns zero on success, or -EFAULT on error. | 
 | 180 |  * On error, the variable @x is set to zero. | 
 | 181 |  */ | 
 | 182 |  | 
 | 183 | #define __get_user(x, ptr)						\ | 
 | 184 | ({									\ | 
 | 185 | 	unsigned long __gu_val;						\ | 
 | 186 | 	/*unsigned long __gu_ptr = (unsigned long)(ptr);*/		\ | 
 | 187 | 	long __gu_err;							\ | 
 | 188 | 	switch (sizeof(*(ptr))) {					\ | 
 | 189 | 	case 1:								\ | 
 | 190 | 		__get_user_asm("lbu", (ptr), __gu_val, __gu_err);	\ | 
 | 191 | 		break;							\ | 
 | 192 | 	case 2:								\ | 
 | 193 | 		__get_user_asm("lhu", (ptr), __gu_val, __gu_err);	\ | 
 | 194 | 		break;							\ | 
 | 195 | 	case 4:								\ | 
 | 196 | 		__get_user_asm("lw", (ptr), __gu_val, __gu_err);	\ | 
 | 197 | 		break;							\ | 
 | 198 | 	default:							\ | 
 | 199 | 		/* __gu_val = 0; __gu_err = -EINVAL;*/ __gu_err = __user_bad();\ | 
 | 200 | 	}								\ | 
 | 201 | 	x = (__typeof__(*(ptr))) __gu_val;				\ | 
 | 202 | 	__gu_err;							\ | 
 | 203 | }) | 
 | 204 |  | 
 | 205 |  | 
 | 206 | #define get_user(x, ptr)						\ | 
 | 207 | ({									\ | 
 | 208 | 	access_ok(VERIFY_READ, (ptr), sizeof(*(ptr)))			\ | 
 | 209 | 		? __get_user((x), (ptr)) : -EFAULT;			\ | 
 | 210 | }) | 
 | 211 |  | 
| Michal Simek | ef4e277 | 2010-03-22 16:22:41 +0100 | [diff] [blame] | 212 | #define __put_user_asm(insn, __gu_ptr, __gu_val, __gu_err)	\ | 
| Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 213 | ({								\ | 
| Michal Simek | ef4e277 | 2010-03-22 16:22:41 +0100 | [diff] [blame] | 214 | 	__asm__ __volatile__ (					\ | 
 | 215 | 			"1:"	insn	" %1, %2, r0;"		\ | 
 | 216 | 			"	addk	%0, r0, r0;"		\ | 
 | 217 | 			"2:			"		\ | 
 | 218 | 			__FIXUP_SECTION				\ | 
 | 219 | 			"3:	brid	2b;"			\ | 
 | 220 | 			"	addik	%0, r0, %3;"		\ | 
 | 221 | 			".previous;"				\ | 
 | 222 | 			__EX_TABLE_SECTION			\ | 
 | 223 | 			".word	1b,3b;"				\ | 
 | 224 | 			".previous;"				\ | 
 | 225 | 		: "=&r"(__gu_err)				\ | 
 | 226 | 		: "r"(__gu_val), "r"(__gu_ptr), "i"(-EFAULT)	\ | 
 | 227 | 	);							\ | 
| Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 228 | }) | 
| Michal Simek | 2660663 | 2009-03-27 14:25:23 +0100 | [diff] [blame] | 229 |  | 
| Michal Simek | ef4e277 | 2010-03-22 16:22:41 +0100 | [diff] [blame] | 230 | #define __put_user_asm_8(__gu_ptr, __gu_val, __gu_err)		\ | 
 | 231 | ({								\ | 
 | 232 | 	__asm__ __volatile__ ("	lwi	%0, %1, 0;"		\ | 
 | 233 | 			"1:	swi	%0, %2, 0;"		\ | 
 | 234 | 			"	lwi	%0, %1, 4;"		\ | 
 | 235 | 			"2:	swi	%0, %2, 4;"		\ | 
 | 236 | 			"	addk	%0, r0, r0;"		\ | 
 | 237 | 			"3:			"		\ | 
 | 238 | 			__FIXUP_SECTION				\ | 
 | 239 | 			"4:	brid	3b;"			\ | 
 | 240 | 			"	addik	%0, r0, %3;"		\ | 
 | 241 | 			".previous;"				\ | 
 | 242 | 			__EX_TABLE_SECTION			\ | 
 | 243 | 			".word	1b,4b,2b,4b;"			\ | 
 | 244 | 			".previous;"				\ | 
 | 245 | 		: "=&r"(__gu_err)				\ | 
 | 246 | 		: "r"(&__gu_val), "r"(__gu_ptr), "i"(-EFAULT)	\ | 
 | 247 | 		);						\ | 
 | 248 | }) | 
 | 249 |  | 
| Michal Simek | 0dcb409 | 2010-03-22 15:46:56 +0100 | [diff] [blame] | 250 | /** | 
 | 251 |  * put_user: - Write a simple value into user space. | 
 | 252 |  * @x:   Value to copy to user space. | 
 | 253 |  * @ptr: Destination address, in user space. | 
 | 254 |  * | 
 | 255 |  * Context: User context only.  This function may sleep. | 
 | 256 |  * | 
 | 257 |  * This macro copies a single simple value from kernel space to user | 
 | 258 |  * space.  It supports simple types like char and int, but not larger | 
 | 259 |  * data types like structures or arrays. | 
 | 260 |  * | 
 | 261 |  * @ptr must have pointer-to-simple-variable type, and @x must be assignable | 
 | 262 |  * to the result of dereferencing @ptr. | 
 | 263 |  * | 
 | 264 |  * Returns zero on success, or -EFAULT on error. | 
 | 265 |  */ | 
 | 266 |  | 
| Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 267 | #define __put_user(x, ptr)						\ | 
 | 268 | ({									\ | 
| Michal Simek | 7bcb63b | 2009-07-13 16:46:54 +0200 | [diff] [blame] | 269 | 	__typeof__(*(ptr)) volatile __gu_val = (x);			\ | 
| Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 270 | 	long __gu_err = 0;						\ | 
 | 271 | 	switch (sizeof(__gu_val)) {					\ | 
 | 272 | 	case 1:								\ | 
 | 273 | 		__put_user_asm("sb", (ptr), __gu_val, __gu_err);	\ | 
 | 274 | 		break;							\ | 
| Michal Simek | cca7912 | 2010-03-22 18:23:45 +0100 | [diff] [blame^] | 275 | 	case 2:								\ | 
| Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 276 | 		__put_user_asm("sh", (ptr), __gu_val, __gu_err);	\ | 
 | 277 | 		break;							\ | 
 | 278 | 	case 4:								\ | 
 | 279 | 		__put_user_asm("sw", (ptr), __gu_val, __gu_err);	\ | 
 | 280 | 		break;							\ | 
 | 281 | 	case 8:								\ | 
 | 282 | 		__put_user_asm_8((ptr), __gu_val, __gu_err);		\ | 
 | 283 | 		break;							\ | 
 | 284 | 	default:							\ | 
| Michal Simek | 0dcb409 | 2010-03-22 15:46:56 +0100 | [diff] [blame] | 285 | 		/*__gu_err = -EINVAL;*/	__gu_err = __user_bad();	\ | 
| Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 286 | 	}								\ | 
 | 287 | 	__gu_err;							\ | 
 | 288 | }) | 
 | 289 |  | 
| Michal Simek | cca7912 | 2010-03-22 18:23:45 +0100 | [diff] [blame^] | 290 | #ifndef CONFIG_MMU | 
 | 291 |  | 
 | 292 | #define put_user(x, ptr)	__put_user((x), (ptr)) | 
 | 293 |  | 
 | 294 | static inline long strnlen_user(const char __user *src, long count) | 
 | 295 | { | 
 | 296 | 	return strlen(src) + 1; | 
 | 297 | } | 
 | 298 |  | 
 | 299 | #define __do_strncpy_from_user(dst, src, count, res)			\ | 
 | 300 | 	do {								\ | 
 | 301 | 		char *tmp;						\ | 
 | 302 | 		strncpy(dst, src, count);				\ | 
 | 303 | 		for (tmp = dst; *tmp && count > 0; tmp++, count--)	\ | 
 | 304 | 			;						\ | 
 | 305 | 		res = (tmp - dst);					\ | 
 | 306 | 	} while (0) | 
 | 307 |  | 
 | 308 | static inline long __strncpy_from_user(char *dst, | 
 | 309 | 				const char __user *src, long count) | 
 | 310 | { | 
 | 311 | 	long res; | 
 | 312 | 	__do_strncpy_from_user(dst, src, count, res); | 
 | 313 | 	return res; | 
 | 314 | } | 
 | 315 |  | 
 | 316 | static inline long strncpy_from_user(char *dst, | 
 | 317 | 				const char __user *src, long count) | 
 | 318 | { | 
 | 319 | 	long res = -EFAULT; | 
 | 320 | 	if (access_ok(VERIFY_READ, src, 1)) | 
 | 321 | 		__do_strncpy_from_user(dst, src, count, res); | 
 | 322 | 	return res; | 
 | 323 | } | 
 | 324 |  | 
 | 325 | static inline unsigned long __copy_tofrom_user(void __user *to, | 
 | 326 | 		const void __user *from, unsigned long size) | 
 | 327 | { | 
 | 328 | 	memcpy(to, from, size); | 
 | 329 | 	return 0; | 
 | 330 | } | 
 | 331 |  | 
 | 332 | #define copy_to_user(to, from, n)	(memcpy((to), (from), (n)), 0) | 
 | 333 | #define copy_from_user(to, from, n)	(memcpy((to), (from), (n)), 0) | 
 | 334 |  | 
 | 335 | #define __copy_to_user(to, from, n)	(copy_to_user((to), (from), (n))) | 
 | 336 | #define __copy_from_user(to, from, n)	(copy_from_user((to), (from), (n))) | 
 | 337 | #define __copy_to_user_inatomic(to, from, n) \ | 
 | 338 | 			(__copy_to_user((to), (from), (n))) | 
 | 339 | #define __copy_from_user_inatomic(to, from, n) \ | 
 | 340 | 			(__copy_from_user((to), (from), (n))) | 
 | 341 |  | 
 | 342 | extern long strncpy_from_user(char *dst, const char *src, long count); | 
 | 343 | extern long strnlen_user(const char *src, long count); | 
 | 344 |  | 
 | 345 | #else /* CONFIG_MMU */ | 
 | 346 |  | 
| Michal Simek | 8b651aa | 2010-03-22 15:25:12 +0100 | [diff] [blame] | 347 | #define put_user(x, ptr)						\ | 
 | 348 | ({									\ | 
 | 349 | 	access_ok(VERIFY_WRITE, (ptr), sizeof(*(ptr)))			\ | 
 | 350 | 		? __put_user((x), (ptr)) : -EFAULT;			\ | 
| Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 351 | }) | 
 | 352 |  | 
| Michal Simek | cca7912 | 2010-03-22 18:23:45 +0100 | [diff] [blame^] | 353 | extern unsigned long __copy_tofrom_user(void __user *to, | 
 | 354 | 		const void __user *from, unsigned long size); | 
 | 355 |  | 
| Michal Simek | 4270690 | 2010-03-22 15:56:32 +0100 | [diff] [blame] | 356 | #define __copy_from_user(to, from, n)	\ | 
 | 357 | 	__copy_tofrom_user((__force void __user *)(to), \ | 
 | 358 | 				(void __user *)(from), (n)) | 
| John Williams | 95dfbbe | 2009-08-14 12:06:46 +1000 | [diff] [blame] | 359 | #define __copy_from_user_inatomic(to, from, n) \ | 
 | 360 | 		copy_from_user((to), (from), (n)) | 
| Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 361 |  | 
| Michal Simek | 4270690 | 2010-03-22 15:56:32 +0100 | [diff] [blame] | 362 | static inline long copy_from_user(void *to, | 
 | 363 | 		const void __user *from, unsigned long n) | 
 | 364 | { | 
 | 365 | 	might_sleep(); | 
 | 366 | 	if (access_ok(VERIFY_READ, from, n)) | 
 | 367 | 		return __copy_from_user(to, from, n); | 
 | 368 | 	else | 
 | 369 | 		return n; | 
 | 370 | } | 
 | 371 |  | 
| Michal Simek | cc5a428 | 2010-03-22 15:52:53 +0100 | [diff] [blame] | 372 | #define __copy_to_user(to, from, n)	\ | 
| Michal Simek | 4270690 | 2010-03-22 15:56:32 +0100 | [diff] [blame] | 373 | 		__copy_tofrom_user((void __user *)(to), \ | 
| Michal Simek | cc5a428 | 2010-03-22 15:52:53 +0100 | [diff] [blame] | 374 | 			(__force const void __user *)(from), (n)) | 
| Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 375 | #define __copy_to_user_inatomic(to, from, n)	copy_to_user((to), (from), (n)) | 
 | 376 |  | 
| Michal Simek | cc5a428 | 2010-03-22 15:52:53 +0100 | [diff] [blame] | 377 | static inline long copy_to_user(void __user *to, | 
 | 378 | 		const void *from, unsigned long n) | 
 | 379 | { | 
 | 380 | 	might_sleep(); | 
 | 381 | 	if (access_ok(VERIFY_WRITE, to, n)) | 
 | 382 | 		return __copy_to_user(to, from, n); | 
 | 383 | 	else | 
 | 384 | 		return n; | 
 | 385 | } | 
 | 386 |  | 
| Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 387 | extern int __strncpy_user(char *to, const char __user *from, int len); | 
| Michal Simek | 40e11e3 | 2010-03-08 09:38:02 +0100 | [diff] [blame] | 388 |  | 
 | 389 | #define __strncpy_from_user	__strncpy_user | 
 | 390 |  | 
 | 391 | static inline long | 
 | 392 | strncpy_from_user(char *dst, const char __user *src, long count) | 
 | 393 | { | 
 | 394 | 	if (!access_ok(VERIFY_READ, src, 1)) | 
 | 395 | 		return -EFAULT; | 
 | 396 | 	return __strncpy_from_user(dst, src, count); | 
 | 397 | } | 
 | 398 |  | 
| Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 399 | extern int __strnlen_user(const char __user *sstr, int len); | 
 | 400 |  | 
| Michal Simek | 0d6de95 | 2009-05-26 16:30:23 +0200 | [diff] [blame] | 401 | #define strnlen_user(str, len)	\ | 
 | 402 | 		(access_ok(VERIFY_READ, str, 1) ? __strnlen_user(str, len) : 0) | 
 | 403 |  | 
 | 404 | #endif /* CONFIG_MMU */ | 
| Michal Simek | 2660663 | 2009-03-27 14:25:23 +0100 | [diff] [blame] | 405 |  | 
| Michal Simek | 2660663 | 2009-03-27 14:25:23 +0100 | [diff] [blame] | 406 | #endif  /* __ASSEMBLY__ */ | 
 | 407 | #endif /* __KERNEL__ */ | 
 | 408 |  | 
 | 409 | #endif /* _ASM_MICROBLAZE_UACCESS_H */ |