~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/metag/include/asm/uaccess.h

Version: ~ [ linux-5.16 ] ~ [ linux-5.15.13 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.90 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.170 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.224 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.261 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.296 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.298 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 #ifndef __METAG_UACCESS_H
  2 #define __METAG_UACCESS_H
  3 
  4 /*
  5  * User space memory access functions
  6  */
  7 #include <linux/sched.h>
  8 
  9 #define VERIFY_READ     0
 10 #define VERIFY_WRITE    1
 11 
 12 /*
 13  * The fs value determines whether argument validity checking should be
 14  * performed or not.  If get_fs() == USER_DS, checking is performed, with
 15  * get_fs() == KERNEL_DS, checking is bypassed.
 16  *
 17  * For historical reasons, these macros are grossly misnamed.
 18  */
 19 
 20 #define MAKE_MM_SEG(s)  ((mm_segment_t) { (s) })
 21 
 22 #define KERNEL_DS       MAKE_MM_SEG(0xFFFFFFFF)
 23 #define USER_DS         MAKE_MM_SEG(PAGE_OFFSET)
 24 
 25 #define get_ds()        (KERNEL_DS)
 26 #define get_fs()        (current_thread_info()->addr_limit)
 27 #define set_fs(x)       (current_thread_info()->addr_limit = (x))
 28 
 29 #define segment_eq(a, b)        ((a).seg == (b).seg)
 30 
 31 #define __kernel_ok (segment_eq(get_fs(), KERNEL_DS))
 32 /*
 33  * Explicitly allow NULL pointers here. Parts of the kernel such
 34  * as readv/writev use access_ok to validate pointers, but want
 35  * to allow NULL pointers for various reasons. NULL pointers are
 36  * safe to allow through because the first page is not mappable on
 37  * Meta.
 38  *
 39  * We also wish to avoid letting user code access the system area
 40  * and the kernel half of the address space.
 41  */
 42 #define __user_bad(addr, size) (((addr) > 0 && (addr) < META_MEMORY_BASE) || \
 43                                 ((addr) > PAGE_OFFSET &&                \
 44                                  (addr) < LINCORE_BASE))
 45 
 46 static inline int __access_ok(unsigned long addr, unsigned long size)
 47 {
 48         return __kernel_ok || !__user_bad(addr, size);
 49 }
 50 
 51 #define access_ok(type, addr, size) __access_ok((unsigned long)(addr),  \
 52                                                 (unsigned long)(size))
 53 
 54 static inline int verify_area(int type, const void *addr, unsigned long size)
 55 {
 56         return access_ok(type, addr, size) ? 0 : -EFAULT;
 57 }
 58 
 59 /*
 60  * The exception table consists of pairs of addresses: the first is the
 61  * address of an instruction that is allowed to fault, and the second is
 62  * the address at which the program should continue.  No registers are
 63  * modified, so it is entirely up to the continuation code to figure out
 64  * what to do.
 65  *
 66  * All the routines below use bits of fixup code that are out of line
 67  * with the main instruction path.  This means when everything is well,
 68  * we don't even have to jump over them.  Further, they do not intrude
 69  * on our cache or tlb entries.
 70  */
 71 struct exception_table_entry {
 72         unsigned long insn, fixup;
 73 };
 74 
 75 extern int fixup_exception(struct pt_regs *regs);
 76 
 77 /*
 78  * These are the main single-value transfer routines.  They automatically
 79  * use the right size if we just have the right pointer type.
 80  */
 81 
 82 #define put_user(x, ptr) \
 83         __put_user_check((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
 84 #define __put_user(x, ptr) \
 85         __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
 86 
 87 extern void __put_user_bad(void);
 88 
 89 #define __put_user_nocheck(x, ptr, size)                \
 90 ({                                                      \
 91         long __pu_err;                                  \
 92         __put_user_size((x), (ptr), (size), __pu_err);  \
 93         __pu_err;                                       \
 94 })
 95 
 96 #define __put_user_check(x, ptr, size)                          \
 97 ({                                                              \
 98         long __pu_err = -EFAULT;                                \
 99         __typeof__(*(ptr)) __user *__pu_addr = (ptr);           \
100         if (access_ok(VERIFY_WRITE, __pu_addr, size))           \
101                 __put_user_size((x), __pu_addr, (size), __pu_err);      \
102         __pu_err;                                               \
103 })
104 
105 extern long __put_user_asm_b(unsigned int x, void __user *addr);
106 extern long __put_user_asm_w(unsigned int x, void __user *addr);
107 extern long __put_user_asm_d(unsigned int x, void __user *addr);
108 extern long __put_user_asm_l(unsigned long long x, void __user *addr);
109 
110 #define __put_user_size(x, ptr, size, retval)                   \
111 do {                                                            \
112         retval = 0;                                             \
113         switch (size) {                                         \
114         case 1:                                                         \
115                 retval = __put_user_asm_b((unsigned int)x, ptr); break; \
116         case 2:                                                         \
117                 retval = __put_user_asm_w((unsigned int)x, ptr); break; \
118         case 4:                                                         \
119                 retval = __put_user_asm_d((unsigned int)x, ptr); break; \
120         case 8:                                                         \
121                 retval = __put_user_asm_l((unsigned long long)x, ptr); break; \
122         default:                                                        \
123                 __put_user_bad();                                       \
124         }                                                               \
125 } while (0)
126 
127 #define get_user(x, ptr) \
128         __get_user_check((x), (ptr), sizeof(*(ptr)))
129 #define __get_user(x, ptr) \
130         __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
131 
132 extern long __get_user_bad(void);
133 
134 #define __get_user_nocheck(x, ptr, size)                        \
135 ({                                                              \
136         long __gu_err, __gu_val;                                \
137         __get_user_size(__gu_val, (ptr), (size), __gu_err);     \
138         (x) = (__typeof__(*(ptr)))__gu_val;                     \
139         __gu_err;                                               \
140 })
141 
142 #define __get_user_check(x, ptr, size)                                  \
143 ({                                                                      \
144         long __gu_err = -EFAULT, __gu_val = 0;                          \
145         const __typeof__(*(ptr)) __user *__gu_addr = (ptr);             \
146         if (access_ok(VERIFY_READ, __gu_addr, size))                    \
147                 __get_user_size(__gu_val, __gu_addr, (size), __gu_err); \
148         (x) = (__typeof__(*(ptr)))__gu_val;                             \
149         __gu_err;                                                       \
150 })
151 
152 extern unsigned char __get_user_asm_b(const void __user *addr, long *err);
153 extern unsigned short __get_user_asm_w(const void __user *addr, long *err);
154 extern unsigned int __get_user_asm_d(const void __user *addr, long *err);
155 
156 #define __get_user_size(x, ptr, size, retval)                   \
157 do {                                                            \
158         retval = 0;                                             \
159         switch (size) {                                         \
160         case 1:                                                 \
161                 x = __get_user_asm_b(ptr, &retval); break;      \
162         case 2:                                                 \
163                 x = __get_user_asm_w(ptr, &retval); break;      \
164         case 4:                                                 \
165                 x = __get_user_asm_d(ptr, &retval); break;      \
166         default:                                                \
167                 (x) = __get_user_bad();                         \
168         }                                                       \
169 } while (0)
170 
171 /*
172  * Copy a null terminated string from userspace.
173  *
174  * Must return:
175  * -EFAULT              for an exception
176  * count                if we hit the buffer limit
177  * bytes copied         if we hit a null byte
178  * (without the null byte)
179  */
180 
181 extern long __must_check __strncpy_from_user(char *dst, const char __user *src,
182                                              long count);
183 
184 #define strncpy_from_user(dst, src, count) __strncpy_from_user(dst, src, count)
185 
186 /*
187  * Return the size of a string (including the ending 0)
188  *
189  * Return 0 on exception, a value greater than N if too long
190  */
191 extern long __must_check strnlen_user(const char __user *src, long count);
192 
193 #define strlen_user(str) strnlen_user(str, 32767)
194 
195 extern unsigned long raw_copy_from_user(void *to, const void __user *from,
196                                         unsigned long n);
197 
198 static inline unsigned long
199 copy_from_user(void *to, const void __user *from, unsigned long n)
200 {
201         unsigned long res = n;
202         if (likely(access_ok(VERIFY_READ, from, n)))
203                 res = raw_copy_from_user(to, from, n);
204         if (unlikely(res))
205                 memset(to + (n - res), 0, res);
206         return res;
207 }
208 
209 #define __copy_from_user(to, from, n) raw_copy_from_user(to, from, n)
210 #define __copy_from_user_inatomic __copy_from_user
211 
212 extern unsigned long __must_check __copy_user(void __user *to,
213                                               const void *from,
214                                               unsigned long n);
215 
216 static inline unsigned long copy_to_user(void __user *to, const void *from,
217                                          unsigned long n)
218 {
219         if (access_ok(VERIFY_WRITE, to, n))
220                 return __copy_user(to, from, n);
221         return n;
222 }
223 
224 #define __copy_to_user(to, from, n) __copy_user(to, from, n)
225 #define __copy_to_user_inatomic __copy_to_user
226 
227 /*
228  * Zero Userspace
229  */
230 
231 extern unsigned long __must_check __do_clear_user(void __user *to,
232                                                   unsigned long n);
233 
234 static inline unsigned long clear_user(void __user *to, unsigned long n)
235 {
236         if (access_ok(VERIFY_WRITE, to, n))
237                 return __do_clear_user(to, n);
238         return n;
239 }
240 
241 #define __clear_user(to, n)            __do_clear_user(to, n)
242 
243 #endif /* _METAG_UACCESS_H */
244 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp