]>
git.proxmox.com Git - mirror_ubuntu-disco-kernel.git/blob - arch/nds32/include/asm/uaccess.h
1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (C) 2005-2017 Andes Technology Corporation
4 #ifndef _ASMANDES_UACCESS_H
5 #define _ASMANDES_UACCESS_H
8 * User space memory access functions
10 #include <linux/sched.h>
11 #include <asm/errno.h>
12 #include <asm/memory.h>
13 #include <asm/types.h>
16 #define __asmeq(x, y) ".ifnc " x "," y " ; .err ; .endif\n\t"
19 * The exception table consists of pairs of addresses: the first is the
20 * address of an instruction that is allowed to fault, and the second is
21 * the address at which the program should continue. No registers are
22 * modified, so it is entirely up to the continuation code to figure out
25 * All the routines below use bits of fixup code that are out of line
26 * with the main instruction path. This means when everything is well,
27 * we don't even have to jump over them. Further, they do not intrude
28 * on our cache or tlb entries.
31 struct exception_table_entry
{
32 unsigned long insn
, fixup
;
35 extern int fixup_exception(struct pt_regs
*regs
);
37 #define KERNEL_DS ((mm_segment_t) { ~0UL })
38 #define USER_DS ((mm_segment_t) {TASK_SIZE - 1})
40 #define get_ds() (KERNEL_DS)
41 #define get_fs() (current_thread_info()->addr_limit)
42 #define user_addr_max get_fs
44 static inline void set_fs(mm_segment_t fs
)
46 current_thread_info()->addr_limit
= fs
;
49 #define segment_eq(a, b) ((a) == (b))
51 #define __range_ok(addr, size) (size <= get_fs() && addr <= (get_fs() -size))
53 #define access_ok(addr, size) \
54 __range_ok((unsigned long)addr, (unsigned long)size)
56 * Single-value transfer routines. They automatically use the right
57 * size if we just have the right pointer type. Note that the functions
58 * which read from user space (*get_*) need to take care not to leak
59 * kernel data even if the calling code is buggy and fails to check
60 * the return value. This means zeroing out the destination variable
61 * or buffer on error. Normally this is done out of line by the
62 * fixup code, but there are a few places where it intrudes on the
63 * main code path. When we only write to user space, there is no
66 * The "__xxx" versions of the user access functions do not verify the
67 * address space - it must have been done previously with a separate
70 * The "xxx_error" versions set the third argument to EFAULT if an
71 * error occurs, and leave it unchanged on success. Note that these
72 * versions are void (ie, don't return a value as such).
75 #define get_user __get_user \
77 #define __get_user(x, ptr) \
80 __get_user_check((x), (ptr), __gu_err); \
84 #define __get_user_error(x, ptr, err) \
86 __get_user_check((x), (ptr), (err)); \
90 #define __get_user_check(x, ptr, err) \
92 const __typeof__(*(ptr)) __user *__p = (ptr); \
94 if (access_ok(__p, sizeof(*__p))) { \
95 __get_user_err((x), __p, (err)); \
97 (x) = 0; (err) = -EFAULT; \
101 #define __get_user_err(x, ptr, err) \
103 unsigned long __gu_val; \
104 __chk_user_ptr(ptr); \
105 switch (sizeof(*(ptr))) { \
107 __get_user_asm("lbi", __gu_val, (ptr), (err)); \
110 __get_user_asm("lhi", __gu_val, (ptr), (err)); \
113 __get_user_asm("lwi", __gu_val, (ptr), (err)); \
116 __get_user_asm_dword(__gu_val, (ptr), (err)); \
122 (x) = (__force __typeof__(*(ptr)))__gu_val; \
125 #define __get_user_asm(inst, x, addr, err) \
126 __asm__ __volatile__ ( \
127 "1: "inst" %1,[%2]\n" \
129 " .section .fixup,\"ax\"\n" \
135 " .section __ex_table,\"a\"\n" \
139 : "+r" (err), "=&r" (x) \
140 : "r" (addr), "i" (-EFAULT) \
144 #define __gu_reg_oper0 "%H1"
145 #define __gu_reg_oper1 "%L1"
147 #define __gu_reg_oper0 "%L1"
148 #define __gu_reg_oper1 "%H1"
151 #define __get_user_asm_dword(x, addr, err) \
152 __asm__ __volatile__ ( \
153 "\n1:\tlwi " __gu_reg_oper0 ",[%2]\n" \
154 "\n2:\tlwi " __gu_reg_oper1 ",[%2+4]\n" \
156 " .section .fixup,\"ax\"\n" \
161 " .section __ex_table,\"a\"\n" \
166 : "+r"(err), "=&r"(x) \
167 : "r"(addr), "i"(-EFAULT) \
170 #define put_user __put_user \
172 #define __put_user(x, ptr) \
175 __put_user_err((x), (ptr), __pu_err); \
179 #define __put_user_error(x, ptr, err) \
181 __put_user_err((x), (ptr), (err)); \
185 #define __put_user_check(x, ptr, err) \
187 __typeof__(*(ptr)) __user *__p = (ptr); \
189 if (access_ok(__p, sizeof(*__p))) { \
190 __put_user_err((x), __p, (err)); \
196 #define __put_user_err(x, ptr, err) \
198 __typeof__(*(ptr)) __pu_val = (x); \
199 __chk_user_ptr(ptr); \
200 switch (sizeof(*(ptr))) { \
202 __put_user_asm("sbi", __pu_val, (ptr), (err)); \
205 __put_user_asm("shi", __pu_val, (ptr), (err)); \
208 __put_user_asm("swi", __pu_val, (ptr), (err)); \
211 __put_user_asm_dword(__pu_val, (ptr), (err)); \
219 #define __put_user_asm(inst, x, addr, err) \
220 __asm__ __volatile__ ( \
221 "1: "inst" %1,[%2]\n" \
223 " .section .fixup,\"ax\"\n" \
228 " .section __ex_table,\"a\"\n" \
233 : "r" (x), "r" (addr), "i" (-EFAULT) \
237 #define __pu_reg_oper0 "%H2"
238 #define __pu_reg_oper1 "%L2"
240 #define __pu_reg_oper0 "%L2"
241 #define __pu_reg_oper1 "%H2"
244 #define __put_user_asm_dword(x, addr, err) \
245 __asm__ __volatile__ ( \
246 "\n1:\tswi " __pu_reg_oper0 ",[%1]\n" \
247 "\n2:\tswi " __pu_reg_oper1 ",[%1+4]\n" \
249 " .section .fixup,\"ax\"\n" \
254 " .section __ex_table,\"a\"\n" \
260 : "r"(addr), "r"(x), "i"(-EFAULT) \
263 extern unsigned long __arch_clear_user(void __user
* addr
, unsigned long n
);
264 extern long strncpy_from_user(char *dest
, const char __user
* src
, long count
);
265 extern __must_check
long strlen_user(const char __user
* str
);
266 extern __must_check
long strnlen_user(const char __user
* str
, long n
);
267 extern unsigned long __arch_copy_from_user(void *to
, const void __user
* from
,
269 extern unsigned long __arch_copy_to_user(void __user
* to
, const void *from
,
272 #define raw_copy_from_user __arch_copy_from_user
273 #define raw_copy_to_user __arch_copy_to_user
275 #define INLINE_COPY_FROM_USER
276 #define INLINE_COPY_TO_USER
277 static inline unsigned long clear_user(void __user
* to
, unsigned long n
)
279 if (access_ok(to
, n
))
280 n
= __arch_clear_user(to
, n
);
284 static inline unsigned long __clear_user(void __user
* to
, unsigned long n
)
286 return __arch_clear_user(to
, n
);
289 #endif /* _ASMNDS32_UACCESS_H */