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_ds() (KERNEL_DS)
35 #define get_fs() (current->thread.mm_segment)
36 #define segment_eq(a,b) (((a) & 2) == ((b) & 2))
38 void set_fs(mm_segment_t fs
);
40 static inline int __range_ok(unsigned long addr
, unsigned long size
)
45 #define __access_ok(addr, size) \
47 __chk_user_ptr(addr); \
48 __range_ok((unsigned long)(addr), (size)); \
51 #define access_ok(type, addr, size) __access_ok(addr, size)
53 unsigned long __must_check
54 raw_copy_from_user(void *to
, const void __user
*from
, unsigned long n
);
56 unsigned long __must_check
57 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
62 #ifdef CONFIG_HAVE_MARCH_Z10_FEATURES
64 #define __put_get_user_asm(to, from, size, spec) \
66 register unsigned long __reg0 asm("0") = spec; \
70 "0: mvcos %1,%3,%2\n" \
73 ".pushsection .fixup, \"ax\"\n" \
77 EX_TABLE(0b,3b) EX_TABLE(1b,3b) \
78 : "=d" (__rc), "+Q" (*(to)) \
79 : "d" (size), "Q" (*(from)), \
80 "d" (__reg0), "K" (-EFAULT) \
85 static inline int __put_user_fn(void *x
, void __user
*ptr
, unsigned long size
)
87 unsigned long spec
= 0x010000UL
;
92 rc
= __put_get_user_asm((unsigned char __user
*)ptr
,
97 rc
= __put_get_user_asm((unsigned short __user
*)ptr
,
102 rc
= __put_get_user_asm((unsigned int __user
*)ptr
,
107 rc
= __put_get_user_asm((unsigned long __user
*)ptr
,
115 static inline int __get_user_fn(void *x
, const void __user
*ptr
, unsigned long size
)
117 unsigned long spec
= 0x01UL
;
122 rc
= __put_get_user_asm((unsigned char *)x
,
123 (unsigned char __user
*)ptr
,
127 rc
= __put_get_user_asm((unsigned short *)x
,
128 (unsigned short __user
*)ptr
,
132 rc
= __put_get_user_asm((unsigned int *)x
,
133 (unsigned int __user
*)ptr
,
137 rc
= __put_get_user_asm((unsigned long *)x
,
138 (unsigned long __user
*)ptr
,
145 #else /* CONFIG_HAVE_MARCH_Z10_FEATURES */
147 static inline int __put_user_fn(void *x
, void __user
*ptr
, unsigned long size
)
149 size
= raw_copy_to_user(ptr
, x
, size
);
150 return size
? -EFAULT
: 0;
153 static inline int __get_user_fn(void *x
, const void __user
*ptr
, unsigned long size
)
155 size
= raw_copy_from_user(x
, ptr
, size
);
156 return size
? -EFAULT
: 0;
159 #endif /* CONFIG_HAVE_MARCH_Z10_FEATURES */
162 * These are the main single-value transfer routines. They automatically
163 * use the right size if we just have the right pointer type.
165 #define __put_user(x, ptr) \
167 __typeof__(*(ptr)) __x = (x); \
168 int __pu_err = -EFAULT; \
169 __chk_user_ptr(ptr); \
170 switch (sizeof (*(ptr))) { \
175 __pu_err = __put_user_fn(&__x, ptr, \
182 __builtin_expect(__pu_err, 0); \
185 #define put_user(x, ptr) \
188 __put_user(x, ptr); \
192 int __put_user_bad(void) __attribute__((noreturn
));
194 #define __get_user(x, ptr) \
196 int __gu_err = -EFAULT; \
197 __chk_user_ptr(ptr); \
198 switch (sizeof(*(ptr))) { \
200 unsigned char __x = 0; \
201 __gu_err = __get_user_fn(&__x, ptr, \
203 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
207 unsigned short __x = 0; \
208 __gu_err = __get_user_fn(&__x, ptr, \
210 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
214 unsigned int __x = 0; \
215 __gu_err = __get_user_fn(&__x, ptr, \
217 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
221 unsigned long long __x = 0; \
222 __gu_err = __get_user_fn(&__x, ptr, \
224 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
231 __builtin_expect(__gu_err, 0); \
234 #define get_user(x, ptr) \
237 __get_user(x, ptr); \
240 int __get_user_bad(void) __attribute__((noreturn
));
242 unsigned long __must_check
243 raw_copy_in_user(void __user
*to
, const void __user
*from
, unsigned long n
);
246 * Copy a null terminated string from userspace.
249 long __strncpy_from_user(char *dst
, const char __user
*src
, long count
);
251 static inline long __must_check
252 strncpy_from_user(char *dst
, const char __user
*src
, long count
)
255 return __strncpy_from_user(dst
, src
, count
);
258 unsigned long __must_check
__strnlen_user(const char __user
*src
, unsigned long count
);
260 static inline unsigned long strnlen_user(const char __user
*src
, unsigned long n
)
263 return __strnlen_user(src
, n
);
269 unsigned long __must_check
__clear_user(void __user
*to
, unsigned long size
);
271 static inline unsigned long __must_check
clear_user(void __user
*to
, unsigned long n
)
274 return __clear_user(to
, n
);
277 int copy_to_user_real(void __user
*dest
, void *src
, unsigned long count
);
278 void s390_kernel_write(void *dst
, const void *src
, size_t size
);
280 #endif /* __S390_UACCESS_H */