1 /* SPDX-License-Identifier: GPL-2.0 */
4 * Copyright IBM Corp. 1999, 2000
5 * Author(s): Hartmut Penner (hp@de.ibm.com),
6 * Martin Schwidefsky (schwidefsky@de.ibm.com)
8 * Derived from "include/asm-i386/uaccess.h"
10 #ifndef __S390_UACCESS_H
11 #define __S390_UACCESS_H
14 * User space memory access functions
16 #include <asm/processor.h>
17 #include <asm/ctl_reg.h>
18 #include <asm/extable.h>
19 #include <asm/facility.h>
22 * The fs value determines whether argument validity checking should be
23 * performed or not. If get_fs() == USER_DS, checking is performed, with
24 * get_fs() == KERNEL_DS, checking is bypassed.
26 * For historical reasons, these macros are grossly misnamed.
30 #define KERNEL_DS_SACF (1)
32 #define USER_DS_SACF (3)
34 #define get_fs() (current->thread.mm_segment)
35 #define segment_eq(a,b) (((a) & 2) == ((b) & 2))
37 void set_fs(mm_segment_t fs
);
39 static inline int __range_ok(unsigned long addr
, unsigned long size
)
44 #define __access_ok(addr, size) \
46 __chk_user_ptr(addr); \
47 __range_ok((unsigned long)(addr), (size)); \
50 #define access_ok(addr, size) __access_ok(addr, size)
52 unsigned long __must_check
53 raw_copy_from_user(void *to
, const void __user
*from
, unsigned long n
);
55 unsigned long __must_check
56 raw_copy_to_user(void __user
*to
, const void *from
, unsigned long n
);
59 #define INLINE_COPY_FROM_USER
60 #define INLINE_COPY_TO_USER
63 #ifdef CONFIG_HAVE_MARCH_Z10_FEATURES
65 #define __put_get_user_asm(to, from, size, spec) \
67 register unsigned long __reg0 asm("0") = spec; \
71 "0: mvcos %1,%3,%2\n" \
74 ".pushsection .fixup, \"ax\"\n" \
78 EX_TABLE(0b,3b) EX_TABLE(1b,3b) \
79 : "=d" (__rc), "+Q" (*(to)) \
80 : "d" (size), "Q" (*(from)), \
81 "d" (__reg0), "K" (-EFAULT) \
86 static __always_inline
int __put_user_fn(void *x
, void __user
*ptr
, unsigned long size
)
88 unsigned long spec
= 0x010000UL
;
93 rc
= __put_get_user_asm((unsigned char __user
*)ptr
,
98 rc
= __put_get_user_asm((unsigned short __user
*)ptr
,
103 rc
= __put_get_user_asm((unsigned int __user
*)ptr
,
108 rc
= __put_get_user_asm((unsigned long __user
*)ptr
,
116 static __always_inline
int __get_user_fn(void *x
, const void __user
*ptr
, unsigned long size
)
118 unsigned long spec
= 0x01UL
;
123 rc
= __put_get_user_asm((unsigned char *)x
,
124 (unsigned char __user
*)ptr
,
128 rc
= __put_get_user_asm((unsigned short *)x
,
129 (unsigned short __user
*)ptr
,
133 rc
= __put_get_user_asm((unsigned int *)x
,
134 (unsigned int __user
*)ptr
,
138 rc
= __put_get_user_asm((unsigned long *)x
,
139 (unsigned long __user
*)ptr
,
146 #else /* CONFIG_HAVE_MARCH_Z10_FEATURES */
148 static inline int __put_user_fn(void *x
, void __user
*ptr
, unsigned long size
)
150 size
= raw_copy_to_user(ptr
, x
, size
);
151 return size
? -EFAULT
: 0;
154 static inline int __get_user_fn(void *x
, const void __user
*ptr
, unsigned long size
)
156 size
= raw_copy_from_user(x
, ptr
, size
);
157 return size
? -EFAULT
: 0;
160 #endif /* CONFIG_HAVE_MARCH_Z10_FEATURES */
163 * These are the main single-value transfer routines. They automatically
164 * use the right size if we just have the right pointer type.
166 #define __put_user(x, ptr) \
168 __typeof__(*(ptr)) __x = (x); \
169 int __pu_err = -EFAULT; \
170 __chk_user_ptr(ptr); \
171 switch (sizeof (*(ptr))) { \
176 __pu_err = __put_user_fn(&__x, ptr, \
183 __builtin_expect(__pu_err, 0); \
186 #define put_user(x, ptr) \
189 __put_user(x, ptr); \
193 int __put_user_bad(void) __attribute__((noreturn
));
195 #define __get_user(x, ptr) \
197 int __gu_err = -EFAULT; \
198 __chk_user_ptr(ptr); \
199 switch (sizeof(*(ptr))) { \
201 unsigned char __x = 0; \
202 __gu_err = __get_user_fn(&__x, ptr, \
204 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
208 unsigned short __x = 0; \
209 __gu_err = __get_user_fn(&__x, ptr, \
211 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
215 unsigned int __x = 0; \
216 __gu_err = __get_user_fn(&__x, ptr, \
218 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
222 unsigned long long __x = 0; \
223 __gu_err = __get_user_fn(&__x, ptr, \
225 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
232 __builtin_expect(__gu_err, 0); \
235 #define get_user(x, ptr) \
238 __get_user(x, ptr); \
241 int __get_user_bad(void) __attribute__((noreturn
));
243 unsigned long __must_check
244 raw_copy_in_user(void __user
*to
, const void __user
*from
, unsigned long n
);
247 * Copy a null terminated string from userspace.
250 long __strncpy_from_user(char *dst
, const char __user
*src
, long count
);
252 static inline long __must_check
253 strncpy_from_user(char *dst
, const char __user
*src
, long count
)
256 return __strncpy_from_user(dst
, src
, count
);
259 unsigned long __must_check
__strnlen_user(const char __user
*src
, unsigned long count
);
261 static inline unsigned long strnlen_user(const char __user
*src
, unsigned long n
)
264 return __strnlen_user(src
, n
);
270 unsigned long __must_check
__clear_user(void __user
*to
, unsigned long size
);
272 static inline unsigned long __must_check
clear_user(void __user
*to
, unsigned long n
)
275 return __clear_user(to
, n
);
278 int copy_to_user_real(void __user
*dest
, void *src
, unsigned long count
);
279 void s390_kernel_write(void *dst
, const void *src
, size_t size
);
281 #endif /* __S390_UACCESS_H */