]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - arch/s390/include/asm/uaccess.h
3 * Copyright IBM Corp. 1999, 2000
4 * Author(s): Hartmut Penner (hp@de.ibm.com),
5 * Martin Schwidefsky (schwidefsky@de.ibm.com)
7 * Derived from "include/asm-i386/uaccess.h"
9 #ifndef __S390_UACCESS_H
10 #define __S390_UACCESS_H
13 * User space memory access functions
15 #include <asm/processor.h>
16 #include <asm/ctl_reg.h>
17 #include <asm/extable.h>
21 * The fs value determines whether argument validity checking should be
22 * performed or not. If get_fs() == USER_DS, checking is performed, with
23 * get_fs() == KERNEL_DS, checking is bypassed.
25 * For historical reasons, these macros are grossly misnamed.
28 #define MAKE_MM_SEG(a) ((mm_segment_t) { (a) })
31 #define KERNEL_DS MAKE_MM_SEG(0)
32 #define USER_DS MAKE_MM_SEG(1)
34 #define get_ds() (KERNEL_DS)
35 #define get_fs() (current->thread.mm_segment)
36 #define segment_eq(a,b) ((a).ar4 == (b).ar4)
38 static inline void set_fs(mm_segment_t fs
)
40 current
->thread
.mm_segment
= fs
;
41 if (uaccess_kernel()) {
42 set_cpu_flag(CIF_ASCE_SECONDARY
);
43 __ctl_load(S390_lowcore
.kernel_asce
, 7, 7);
45 clear_cpu_flag(CIF_ASCE_SECONDARY
);
46 __ctl_load(S390_lowcore
.user_asce
, 7, 7);
50 static inline int __range_ok(unsigned long addr
, unsigned long size
)
55 #define __access_ok(addr, size) \
57 __chk_user_ptr(addr); \
58 __range_ok((unsigned long)(addr), (size)); \
61 #define access_ok(type, addr, size) __access_ok(addr, size)
63 unsigned long __must_check
64 raw_copy_from_user(void *to
, const void __user
*from
, unsigned long n
);
66 unsigned long __must_check
67 raw_copy_to_user(void __user
*to
, const void *from
, unsigned long n
);
69 #define INLINE_COPY_FROM_USER
70 #define INLINE_COPY_TO_USER
72 #ifdef CONFIG_HAVE_MARCH_Z10_FEATURES
74 #define __put_get_user_asm(to, from, size, spec) \
76 register unsigned long __reg0 asm("0") = spec; \
80 "0: mvcos %1,%3,%2\n" \
83 ".pushsection .fixup, \"ax\"\n" \
87 EX_TABLE(0b,3b) EX_TABLE(1b,3b) \
88 : "=d" (__rc), "+Q" (*(to)) \
89 : "d" (size), "Q" (*(from)), \
90 "d" (__reg0), "K" (-EFAULT) \
95 static inline int __put_user_fn(void *x
, void __user
*ptr
, unsigned long size
)
97 unsigned long spec
= 0x810000UL
;
102 rc
= __put_get_user_asm((unsigned char __user
*)ptr
,
107 rc
= __put_get_user_asm((unsigned short __user
*)ptr
,
112 rc
= __put_get_user_asm((unsigned int __user
*)ptr
,
117 rc
= __put_get_user_asm((unsigned long __user
*)ptr
,
125 static inline int __get_user_fn(void *x
, const void __user
*ptr
, unsigned long size
)
127 unsigned long spec
= 0x81UL
;
132 rc
= __put_get_user_asm((unsigned char *)x
,
133 (unsigned char __user
*)ptr
,
137 rc
= __put_get_user_asm((unsigned short *)x
,
138 (unsigned short __user
*)ptr
,
142 rc
= __put_get_user_asm((unsigned int *)x
,
143 (unsigned int __user
*)ptr
,
147 rc
= __put_get_user_asm((unsigned long *)x
,
148 (unsigned long __user
*)ptr
,
155 #else /* CONFIG_HAVE_MARCH_Z10_FEATURES */
157 static inline int __put_user_fn(void *x
, void __user
*ptr
, unsigned long size
)
159 size
= raw_copy_to_user(ptr
, x
, size
);
160 return size
? -EFAULT
: 0;
163 static inline int __get_user_fn(void *x
, const void __user
*ptr
, unsigned long size
)
165 size
= raw_copy_from_user(x
, ptr
, size
);
166 return size
? -EFAULT
: 0;
169 #endif /* CONFIG_HAVE_MARCH_Z10_FEATURES */
172 * These are the main single-value transfer routines. They automatically
173 * use the right size if we just have the right pointer type.
175 #define __put_user(x, ptr) \
177 __typeof__(*(ptr)) __x = (x); \
178 int __pu_err = -EFAULT; \
179 __chk_user_ptr(ptr); \
180 switch (sizeof (*(ptr))) { \
185 __pu_err = __put_user_fn(&__x, ptr, \
192 __builtin_expect(__pu_err, 0); \
195 #define put_user(x, ptr) \
198 __put_user(x, ptr); \
202 int __put_user_bad(void) __attribute__((noreturn
));
204 #define __get_user(x, ptr) \
206 int __gu_err = -EFAULT; \
207 __chk_user_ptr(ptr); \
208 switch (sizeof(*(ptr))) { \
210 unsigned char __x = 0; \
211 __gu_err = __get_user_fn(&__x, ptr, \
213 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
217 unsigned short __x = 0; \
218 __gu_err = __get_user_fn(&__x, ptr, \
220 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
224 unsigned int __x = 0; \
225 __gu_err = __get_user_fn(&__x, ptr, \
227 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
231 unsigned long long __x = 0; \
232 __gu_err = __get_user_fn(&__x, ptr, \
234 (x) = *(__force __typeof__(*(ptr)) *) &__x; \
241 __builtin_expect(__gu_err, 0); \
244 #define get_user(x, ptr) \
247 __get_user(x, ptr); \
250 int __get_user_bad(void) __attribute__((noreturn
));
252 #define __put_user_unaligned __put_user
253 #define __get_user_unaligned __get_user
255 unsigned long __must_check
256 raw_copy_in_user(void __user
*to
, const void __user
*from
, unsigned long n
);
259 * Copy a null terminated string from userspace.
262 long __strncpy_from_user(char *dst
, const char __user
*src
, long count
);
264 static inline long __must_check
265 strncpy_from_user(char *dst
, const char __user
*src
, long count
)
268 return __strncpy_from_user(dst
, src
, count
);
271 unsigned long __must_check
__strnlen_user(const char __user
*src
, unsigned long count
);
273 static inline unsigned long strnlen_user(const char __user
*src
, unsigned long n
)
276 return __strnlen_user(src
, n
);
282 unsigned long __must_check
__clear_user(void __user
*to
, unsigned long size
);
284 static inline unsigned long __must_check
clear_user(void __user
*to
, unsigned long n
)
287 return __clear_user(to
, n
);
290 int copy_to_user_real(void __user
*dest
, void *src
, unsigned long count
);
291 void s390_kernel_write(void *dst
, const void *src
, size_t size
);
293 #endif /* __S390_UACCESS_H */