2 * include/asm-s390/uaccess.h
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)
9 * Derived from "include/asm-i386/uaccess.h"
11 #ifndef __S390_UACCESS_H
12 #define __S390_UACCESS_H
15 * User space memory access functions
17 #include <linux/sched.h>
18 #include <linux/errno.h>
21 #define VERIFY_WRITE 1
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.
29 * For historical reasons, these macros are grossly misnamed.
32 #define MAKE_MM_SEG(a) ((mm_segment_t) { (a) })
35 #define KERNEL_DS MAKE_MM_SEG(0)
36 #define USER_DS MAKE_MM_SEG(1)
38 #define get_ds() (KERNEL_DS)
39 #define get_fs() (current->thread.mm_segment)
44 unsigned long __pto; \
45 current->thread.mm_segment = (x); \
46 __pto = current->thread.mm_segment.ar4 ? \
47 S390_lowcore.user_asce : S390_lowcore.kernel_asce; \
48 asm volatile ("lctlg 7,7,%0" : : "m" (__pto) ); \
53 unsigned long __pto; \
54 current->thread.mm_segment = (x); \
55 __pto = current->thread.mm_segment.ar4 ? \
56 S390_lowcore.user_asce : S390_lowcore.kernel_asce; \
57 asm volatile ("lctl 7,7,%0" : : "m" (__pto) ); \
61 #define segment_eq(a,b) ((a).ar4 == (b).ar4)
64 #define __access_ok(addr,size) (1)
66 #define access_ok(type,addr,size) __access_ok(addr,size)
68 /* this function will go away soon - use access_ok() instead */
69 extern inline int __deprecated
verify_area(int type
, const void __user
*addr
,
72 return access_ok(type
, addr
, size
) ? 0 : -EFAULT
;
76 * The exception table consists of pairs of addresses: the first is the
77 * address of an instruction that is allowed to fault, and the second is
78 * the address at which the program should continue. No registers are
79 * modified, so it is entirely up to the continuation code to figure out
82 * All the routines below use bits of fixup code that are out of line
83 * with the main instruction path. This means when everything is well,
84 * we don't even have to jump over them. Further, they do not intrude
85 * on our cache or tlb entries.
88 struct exception_table_entry
90 unsigned long insn
, fixup
;
94 #define __uaccess_fixup \
95 ".section .fixup,\"ax\"\n" \
102 ".section __ex_table,\"a\"\n" \
106 #define __uaccess_clobber "cc", "1"
107 #else /* __s390x__ */
108 #define __uaccess_fixup \
109 ".section .fixup,\"ax\"\n" \
113 ".section __ex_table,\"a\"\n" \
117 #define __uaccess_clobber "cc"
118 #endif /* __s390x__ */
121 * These are the main single-value transfer routines. They automatically
122 * use the right size if we just have the right pointer type.
124 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 2)
125 #define __put_user_asm(x, ptr, err) \
129 "0: mvcs 0(%1,%2),%3,%0\n" \
133 : "d" (sizeof(*(ptr))), "a" (ptr), "Q" (x), \
135 : __uaccess_clobber ); \
138 #define __put_user_asm(x, ptr, err) \
142 "0: mvcs 0(%1,%2),0(%3),%0\n" \
146 : "d" (sizeof(*(ptr))), "a" (ptr), "a" (&(x)), \
147 "K" (-EFAULT), "m" (x) \
148 : __uaccess_clobber ); \
153 #define __put_user(x, ptr) \
155 __typeof__(*(ptr)) __x = (x); \
157 switch (sizeof (*(ptr))) { \
162 __put_user_asm(__x, ptr, __pu_err); \
171 #define __put_user(x, ptr) \
179 #define put_user(x, ptr) \
182 __put_user(x, ptr); \
186 extern int __put_user_bad(void) __attribute__((noreturn
));
188 #if __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 2)
189 #define __get_user_asm(x, ptr, err) \
193 "0: mvcp %O1(%2,%R1),0(%3),%0\n" \
196 : "+&d" (err), "=Q" (x) \
197 : "d" (sizeof(*(ptr))), "a" (ptr), \
199 : __uaccess_clobber ); \
202 #define __get_user_asm(x, ptr, err) \
206 "0: mvcp 0(%2,%5),0(%3),%0\n" \
209 : "+&d" (err), "=m" (x) \
210 : "d" (sizeof(*(ptr))), "a" (ptr), \
211 "K" (-EFAULT), "a" (&(x)) \
212 : __uaccess_clobber ); \
217 #define __get_user(x, ptr) \
219 __typeof__(*(ptr)) __x; \
221 switch (sizeof(*(ptr))) { \
226 __get_user_asm(__x, ptr, __gu_err); \
236 #define __get_user(x, ptr) \
245 #define get_user(x, ptr) \
248 __get_user(x, ptr); \
251 extern int __get_user_bad(void) __attribute__((noreturn
));
253 #define __put_user_unaligned __put_user
254 #define __get_user_unaligned __get_user
256 extern long __copy_to_user_asm(const void *from
, long n
, void __user
*to
);
259 * __copy_to_user: - Copy a block of data into user space, with less checking.
260 * @to: Destination address, in user space.
261 * @from: Source address, in kernel space.
262 * @n: Number of bytes to copy.
264 * Context: User context only. This function may sleep.
266 * Copy data from kernel space to user space. Caller must check
267 * the specified block with access_ok() before calling this function.
269 * Returns number of bytes that could not be copied.
270 * On success, this will be zero.
272 static inline unsigned long
273 __copy_to_user(void __user
*to
, const void *from
, unsigned long n
)
275 return __copy_to_user_asm(from
, n
, to
);
278 #define __copy_to_user_inatomic __copy_to_user
279 #define __copy_from_user_inatomic __copy_from_user
282 * copy_to_user: - Copy a block of data into user space.
283 * @to: Destination address, in user space.
284 * @from: Source address, in kernel space.
285 * @n: Number of bytes to copy.
287 * Context: User context only. This function may sleep.
289 * Copy data from kernel space to user space.
291 * Returns number of bytes that could not be copied.
292 * On success, this will be zero.
294 static inline unsigned long
295 copy_to_user(void __user
*to
, const void *from
, unsigned long n
)
298 if (access_ok(VERIFY_WRITE
, to
, n
))
299 n
= __copy_to_user(to
, from
, n
);
303 extern long __copy_from_user_asm(void *to
, long n
, const void __user
*from
);
306 * __copy_from_user: - Copy a block of data from user space, with less checking.
307 * @to: Destination address, in kernel space.
308 * @from: Source address, in user space.
309 * @n: Number of bytes to copy.
311 * Context: User context only. This function may sleep.
313 * Copy data from user space to kernel space. Caller must check
314 * the specified block with access_ok() before calling this function.
316 * Returns number of bytes that could not be copied.
317 * On success, this will be zero.
319 * If some data could not be copied, this function will pad the copied
320 * data to the requested size using zero bytes.
322 static inline unsigned long
323 __copy_from_user(void *to
, const void __user
*from
, unsigned long n
)
325 return __copy_from_user_asm(to
, n
, from
);
329 * copy_from_user: - Copy a block of data from user space.
330 * @to: Destination address, in kernel space.
331 * @from: Source address, in user space.
332 * @n: Number of bytes to copy.
334 * Context: User context only. This function may sleep.
336 * Copy data from user space to kernel space.
338 * Returns number of bytes that could not be copied.
339 * On success, this will be zero.
341 * If some data could not be copied, this function will pad the copied
342 * data to the requested size using zero bytes.
344 static inline unsigned long
345 copy_from_user(void *to
, const void __user
*from
, unsigned long n
)
348 if (access_ok(VERIFY_READ
, from
, n
))
349 n
= __copy_from_user(to
, from
, n
);
355 extern unsigned long __copy_in_user_asm(const void __user
*from
, long n
,
358 static inline unsigned long
359 __copy_in_user(void __user
*to
, const void __user
*from
, unsigned long n
)
361 return __copy_in_user_asm(from
, n
, to
);
364 static inline unsigned long
365 copy_in_user(void __user
*to
, const void __user
*from
, unsigned long n
)
368 if (__access_ok(from
,n
) && __access_ok(to
,n
))
369 n
= __copy_in_user_asm(from
, n
, to
);
374 * Copy a null terminated string from userspace.
376 extern long __strncpy_from_user_asm(long count
, char *dst
,
377 const char __user
*src
);
380 strncpy_from_user(char *dst
, const char __user
*src
, long count
)
384 if (access_ok(VERIFY_READ
, src
, 1))
385 res
= __strncpy_from_user_asm(count
, dst
, src
);
390 extern long __strnlen_user_asm(long count
, const char __user
*src
);
392 static inline unsigned long
393 strnlen_user(const char __user
* src
, unsigned long n
)
396 return __strnlen_user_asm(n
, src
);
400 * strlen_user: - Get the size of a string in user space.
401 * @str: The string to measure.
403 * Context: User context only. This function may sleep.
405 * Get the size of a NUL-terminated string in user space.
407 * Returns the size of the string INCLUDING the terminating NUL.
408 * On exception, returns 0.
410 * If there is a limit on the length of a valid string, you may wish to
411 * consider using strnlen_user() instead.
413 #define strlen_user(str) strnlen_user(str, ~0UL)
419 extern long __clear_user_asm(void __user
*to
, long n
);
421 static inline unsigned long
422 __clear_user(void __user
*to
, unsigned long n
)
424 return __clear_user_asm(to
, n
);
427 static inline unsigned long
428 clear_user(void __user
*to
, unsigned long n
)
431 if (access_ok(VERIFY_WRITE
, to
, n
))
432 n
= __clear_user_asm(to
, n
);
436 #endif /* __S390_UACCESS_H */