2 * Copyright (C) 2006 Atmark Techno, Inc.
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
9 #ifndef _ASM_MICROBLAZE_UACCESS_H
10 #define _ASM_MICROBLAZE_UACCESS_H
15 #include <linux/kernel.h>
16 #include <linux/errno.h>
17 #include <linux/sched.h> /* RLIMIT_FSIZE */
22 #include <asm/pgtable.h>
23 #include <asm/segment.h>
24 #include <linux/string.h>
27 #define VERIFY_WRITE 1
29 extern int ___range_ok(unsigned long addr, unsigned long size);
31 #define __range_ok(addr, size) \
32 ___range_ok((unsigned long)(addr), (unsigned long)(size))
34 #define access_ok(type, addr, size) (__range_ok((addr), (size)) == 0)
35 #define __access_ok(add, size) (__range_ok((addr), (size)) == 0)
37 extern inline int bad_user_access_length(void)
41 /* FIXME this is function for optimalization -> memcpy */
42 #define __get_user(var, ptr) \
45 switch (sizeof(*(ptr))) { \
52 memcpy((void *) &(var), (ptr), 8); \
56 __gu_err = __get_user_bad(); \
62 #define __get_user_bad() (bad_user_access_length(), (-EFAULT))
64 #define __put_user(var, ptr) \
67 switch (sizeof(*(ptr))) { \
74 typeof(*(ptr)) __pu_val = var; \
75 memcpy(ptr, &__pu_val, sizeof(__pu_val));\
79 __pu_err = __put_user_bad(); \
85 #define __put_user_bad() (bad_user_access_length(), (-EFAULT))
87 #define put_user(x, ptr) __put_user(x, ptr)
88 #define get_user(x, ptr) __get_user(x, ptr)
90 #define copy_to_user(to, from, n) (memcpy(to, from, n), 0)
91 #define copy_from_user(to, from, n) (memcpy(to, from, n), 0)
93 #define __copy_to_user(to, from, n) (copy_to_user(to, from, n))
94 #define __copy_from_user(to, from, n) (copy_from_user(to, from, n))
95 #define __copy_to_user_inatomic(to, from, n) (__copy_to_user(to, from, n))
96 #define __copy_from_user_inatomic(to, from, n) (__copy_from_user(to, from, n))
98 #define __clear_user(addr, n) (memset((void *)addr, 0, n), 0)
100 static inline unsigned long clear_user(void *addr, unsigned long size)
102 if (access_ok(VERIFY_WRITE, addr, size))
103 size = __clear_user(addr, size);
107 /* Returns 0 if exception not found and fixup otherwise. */
108 extern unsigned long search_exception_table(unsigned long);
111 extern long strncpy_from_user(char *dst, const char __user *src, long count);
112 extern long strnlen_user(const char __user *src, long count);
113 extern long __strncpy_from_user(char *dst, const char __user *src, long count);
116 * The exception table consists of pairs of addresses: the first is the
117 * address of an instruction that is allowed to fault, and the second is
118 * the address at which the program should continue. No registers are
119 * modified, so it is entirely up to the continuation code to figure out
122 * All the routines below use bits of fixup code that are out of line
123 * with the main instruction path. This means when everything is well,
124 * we don't even have to jump over them. Further, they do not intrude
125 * on our cache or tlb entries.
127 struct exception_table_entry {
128 unsigned long insn, fixup;
131 #endif /* __ASSEMBLY__ */
132 #endif /* __KERNEL__ */
134 #endif /* _ASM_MICROBLAZE_UACCESS_H */