1 #ifndef __METAG_UACCESS_H
2 #define __METAG_UACCESS_H
5 * User space memory access functions
9 * The fs value determines whether argument validity checking should be
10 * performed or not. If get_fs() == USER_DS, checking is performed, with
11 * get_fs() == KERNEL_DS, checking is bypassed.
13 * For historical reasons, these macros are grossly misnamed.
16 #define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
18 #define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF)
19 #define USER_DS MAKE_MM_SEG(PAGE_OFFSET)
21 #define get_ds() (KERNEL_DS)
22 #define get_fs() (current_thread_info()->addr_limit)
23 #define set_fs(x) (current_thread_info()->addr_limit = (x))
25 #define segment_eq(a, b) ((a).seg == (b).seg)
27 #define __kernel_ok (uaccess_kernel())
29 * Explicitly allow NULL pointers here. Parts of the kernel such
30 * as readv/writev use access_ok to validate pointers, but want
31 * to allow NULL pointers for various reasons. NULL pointers are
32 * safe to allow through because the first page is not mappable on
35 * We also wish to avoid letting user code access the system area
36 * and the kernel half of the address space.
38 #define __user_bad(addr, size) (((addr) > 0 && (addr) < META_MEMORY_BASE) || \
39 ((addr) > PAGE_OFFSET && \
40 (addr) < LINCORE_BASE))
42 static inline int __access_ok(unsigned long addr, unsigned long size)
44 return __kernel_ok || !__user_bad(addr, size);
47 #define access_ok(type, addr, size) __access_ok((unsigned long)(addr), \
48 (unsigned long)(size))
50 #include <asm/extable.h>
53 * These are the main single-value transfer routines. They automatically
54 * use the right size if we just have the right pointer type.
57 #define put_user(x, ptr) \
58 __put_user_check((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
59 #define __put_user(x, ptr) \
60 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
62 extern void __put_user_bad(void);
64 #define __put_user_nocheck(x, ptr, size) \
67 __put_user_size((x), (ptr), (size), __pu_err); \
71 #define __put_user_check(x, ptr, size) \
73 long __pu_err = -EFAULT; \
74 __typeof__(*(ptr)) __user *__pu_addr = (ptr); \
75 if (access_ok(VERIFY_WRITE, __pu_addr, size)) \
76 __put_user_size((x), __pu_addr, (size), __pu_err); \
80 extern long __put_user_asm_b(unsigned int x, void __user *addr);
81 extern long __put_user_asm_w(unsigned int x, void __user *addr);
82 extern long __put_user_asm_d(unsigned int x, void __user *addr);
83 extern long __put_user_asm_l(unsigned long long x, void __user *addr);
85 #define __put_user_size(x, ptr, size, retval) \
90 retval = __put_user_asm_b((__force unsigned int)x, ptr);\
93 retval = __put_user_asm_w((__force unsigned int)x, ptr);\
96 retval = __put_user_asm_d((__force unsigned int)x, ptr);\
99 retval = __put_user_asm_l((__force unsigned long long)x,\
107 #define get_user(x, ptr) \
108 __get_user_check((x), (ptr), sizeof(*(ptr)))
109 #define __get_user(x, ptr) \
110 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
112 extern long __get_user_bad(void);
114 #define __get_user_nocheck(x, ptr, size) \
116 long __gu_err, __gu_val; \
117 __get_user_size(__gu_val, (ptr), (size), __gu_err); \
118 (x) = (__force __typeof__(*(ptr)))__gu_val; \
122 #define __get_user_check(x, ptr, size) \
124 long __gu_err = -EFAULT, __gu_val = 0; \
125 const __typeof__(*(ptr)) __user *__gu_addr = (ptr); \
126 if (access_ok(VERIFY_READ, __gu_addr, size)) \
127 __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
128 (x) = (__force __typeof__(*(ptr)))__gu_val; \
132 extern unsigned char __get_user_asm_b(const void __user *addr, long *err);
133 extern unsigned short __get_user_asm_w(const void __user *addr, long *err);
134 extern unsigned int __get_user_asm_d(const void __user *addr, long *err);
136 #define __get_user_size(x, ptr, size, retval) \
141 x = __get_user_asm_b(ptr, &retval); break; \
143 x = __get_user_asm_w(ptr, &retval); break; \
145 x = __get_user_asm_d(ptr, &retval); break; \
147 (x) = __get_user_bad(); \
152 * Copy a null terminated string from userspace.
155 * -EFAULT for an exception
156 * count if we hit the buffer limit
157 * bytes copied if we hit a null byte
158 * (without the null byte)
161 extern long __must_check __strncpy_from_user(char *dst, const char __user *src,
164 #define strncpy_from_user(dst, src, count) __strncpy_from_user(dst, src, count)
167 * Return the size of a string (including the ending 0)
169 * Return 0 on exception, a value greater than N if too long
171 extern long __must_check strnlen_user(const char __user *src, long count);
173 #define strlen_user(str) strnlen_user(str, 32767)
175 extern unsigned long raw_copy_from_user(void *to, const void __user *from,
177 extern unsigned long raw_copy_to_user(void __user *to, const void *from,
184 extern unsigned long __must_check __do_clear_user(void __user *to,
187 static inline unsigned long clear_user(void __user *to, unsigned long n)
189 if (access_ok(VERIFY_WRITE, to, n))
190 return __do_clear_user(to, n);
194 #define __clear_user(to, n) __do_clear_user(to, n)
196 #endif /* _METAG_UACCESS_H */