[32] | 1 | /* $Id: uaccess.h,v 1.1.1.1 2003/07/02 13:57:00 eleph Exp $ */
|
---|
| 2 |
|
---|
| 3 | #ifndef __i386_UACCESS_H
|
---|
| 4 | #define __i386_UACCESS_H
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
| 7 | * User space memory access functions
|
---|
| 8 | */
|
---|
| 9 | //#include <linux/config.h>
|
---|
| 10 | //#include <linux/sched.h>
|
---|
| 11 | #include <asm/page.h>
|
---|
| 12 |
|
---|
| 13 | #define VERIFY_READ 0
|
---|
| 14 | #define VERIFY_WRITE 1
|
---|
| 15 |
|
---|
| 16 | /*
|
---|
| 17 | * The fs value determines whether argument validity checking should be
|
---|
| 18 | * performed or not. If get_fs() == USER_DS, checking is performed, with
|
---|
| 19 | * get_fs() == KERNEL_DS, checking is bypassed.
|
---|
| 20 | *
|
---|
| 21 | * For historical reasons, these macros are grossly misnamed.
|
---|
| 22 | */
|
---|
| 23 |
|
---|
| 24 | #define MAKE_MM_SEG(s) (mm_segment_t)(s)
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | #define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF)
|
---|
| 28 | #define USER_DS MAKE_MM_SEG(PAGE_OFFSET)
|
---|
| 29 |
|
---|
| 30 | #define get_ds() (KERNEL_DS)
|
---|
| 31 | #define get_fs() (KERNEL_DS)
|
---|
| 32 | #define set_fs(x)
|
---|
| 33 |
|
---|
| 34 | #define segment_eq(a,b) ((a).seg == (b).seg)
|
---|
| 35 |
|
---|
| 36 | extern int __verify_write(const void *, unsigned long);
|
---|
| 37 |
|
---|
| 38 | #define __addr_ok(addr) ((unsigned long)(addr) < (current->addr_limit.seg))
|
---|
| 39 |
|
---|
| 40 | /*
|
---|
| 41 | * Uhhuh, this needs 33-bit arithmetic. We have a carry..
|
---|
| 42 | */
|
---|
| 43 |
|
---|
| 44 | int is_access_ok(int type, void *addr, unsigned long size);
|
---|
| 45 |
|
---|
[679] | 46 | /*
|
---|
| 47 | * The architecture should really override this if possible, at least
|
---|
| 48 | * doing a check on the get_fs()
|
---|
| 49 | */
|
---|
[772] | 50 | static inline int __access_ok(const void __user *ptr, unsigned long size)
|
---|
| 51 |
|
---|
[679] | 52 | {
|
---|
| 53 | return 1;
|
---|
| 54 | }
|
---|
| 55 |
|
---|
[772] | 56 | #define access_ok(addr, size) __access_ok(addr, size)
|
---|
| 57 |
|
---|
[32] | 58 | #define verify_area(type, addr, size) (access_ok(type, (void *)addr,size) ? 0 : -EFAULT)
|
---|
| 59 |
|
---|
| 60 |
|
---|
| 61 | /*
|
---|
| 62 | * The exception table consists of pairs of addresses: the first is the
|
---|
| 63 | * address of an instruction that is allowed to fault, and the second is
|
---|
| 64 | * the address at which the program should continue. No registers are
|
---|
| 65 | * modified, so it is entirely up to the continuation code to figure out
|
---|
| 66 | * what to do.
|
---|
| 67 | *
|
---|
| 68 | * All the routines below use bits of fixup code that are out of line
|
---|
| 69 | * with the main instruction path. This means when everything is well,
|
---|
| 70 | * we don't even have to jump over them. Further, they do not intrude
|
---|
| 71 | * on our cache or tlb entries.
|
---|
| 72 | */
|
---|
| 73 |
|
---|
| 74 | struct exception_table_entry
|
---|
| 75 | {
|
---|
| 76 | unsigned long insn, fixup;
|
---|
| 77 | };
|
---|
| 78 |
|
---|
| 79 | /* Returns 0 if exception not found and fixup otherwise. */
|
---|
| 80 | extern unsigned long search_exception_table(unsigned long);
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | /*
|
---|
| 84 | * These are the main single-value transfer routines. They automatically
|
---|
| 85 | * use the right size if we just have the right pointer type.
|
---|
| 86 | *
|
---|
| 87 | * This gets kind of ugly. We want to return _two_ values in "get_user()"
|
---|
| 88 | * and yet we don't want to do any pointers, because that is too much
|
---|
| 89 | * of a performance impact. Thus we have a few rather ugly macros here,
|
---|
| 90 | * and hide all the uglyness from the user.
|
---|
| 91 | *
|
---|
| 92 | * The "__xxx" versions of the user access functions are versions that
|
---|
| 93 | * do not verify the address space, that must have been done previously
|
---|
| 94 | * with a separate "access_ok()" call (this is used when we do multiple
|
---|
| 95 | * accesses to the same area of user memory).
|
---|
| 96 | */
|
---|
| 97 |
|
---|
| 98 | /* Careful: we have to cast the result to the type of the pointer for sign reasons */
|
---|
| 99 | int __get_user(int size, void *dest, void *src);
|
---|
| 100 |
|
---|
| 101 | extern void __put_user_bad(void);
|
---|
| 102 |
|
---|
| 103 | #define get_user(x,ptr) \
|
---|
| 104 | __get_user(sizeof(*ptr), &x,(ptr))
|
---|
| 105 |
|
---|
| 106 | int _put_user(int size, int x, void *ptr);
|
---|
| 107 |
|
---|
| 108 | #define put_user(x,ptr) \
|
---|
| 109 | _put_user(sizeof(*ptr), x, (ptr))
|
---|
| 110 |
|
---|
| 111 | #define __put_user(x,ptr) \
|
---|
| 112 | _put_user(sizeof(*ptr), x, (ptr))
|
---|
| 113 |
|
---|
| 114 | #define __put_user_nocheck(x,ptr,size) lksjdflksdjf
|
---|
| 115 |
|
---|
| 116 | #define __put_user_size(x,ptr,size,retval) asdlkfjsdklfj
|
---|
| 117 |
|
---|
| 118 | struct __large_struct { unsigned long buf[100]; };
|
---|
| 119 | #define __m(x) (*(struct __large_struct *)(x))
|
---|
| 120 |
|
---|
| 121 | /*
|
---|
| 122 | * Tell gcc we read from memory instead of writing: this is because
|
---|
| 123 | * we do not write to any memory gcc knows about, so there are no
|
---|
| 124 | * aliasing issues.
|
---|
| 125 | */
|
---|
| 126 | #define __put_user_asm(x, addr, err, itype, rtype, ltype) lksjdf
|
---|
| 127 |
|
---|
| 128 |
|
---|
| 129 | #define __get_user_nocheck(x,ptr,size) lsjdf
|
---|
| 130 |
|
---|
| 131 | extern long __get_user_bad(void);
|
---|
| 132 |
|
---|
| 133 | #define __get_user_size(x,ptr,size,retval) ksjdf
|
---|
| 134 |
|
---|
| 135 | #define __get_user_asm(x, addr, err, itype, rtype, ltype) sldkjf
|
---|
| 136 |
|
---|
| 137 | /*
|
---|
| 138 | * The "xxx_ret" versions return constant specified in third argument, if
|
---|
| 139 | * something bad happens. These macros can be optimized for the
|
---|
| 140 | * case of just returning from the function xxx_ret is used.
|
---|
| 141 | */
|
---|
| 142 |
|
---|
| 143 | #define put_user_ret(x,ptr,ret) ({ if (put_user(x,ptr)) return ret; })
|
---|
| 144 |
|
---|
| 145 | #define get_user_ret(x,ptr,ret) if (get_user(sizeof(x), (void *)&x, (void *)ptr)) return ret;
|
---|
| 146 |
|
---|
| 147 |
|
---|
| 148 | /*
|
---|
| 149 | * Copy To/From Userspace
|
---|
| 150 | */
|
---|
| 151 |
|
---|
| 152 | /* Generic arbitrary sized copy. */
|
---|
| 153 | void __copy_user(void *to, const void *from, unsigned long n);
|
---|
| 154 |
|
---|
| 155 | void __copy_user_zeroing(void *to, const void *from, unsigned long n);
|
---|
| 156 |
|
---|
| 157 | /* We let the __ versions of copy_from/to_user inline, because they're often
|
---|
| 158 | * used in fast paths and have only a small space overhead.
|
---|
| 159 | */
|
---|
| 160 | static __inline unsigned long
|
---|
| 161 | __generic_copy_from_user_nocheck(void *to, const void *from, unsigned long n)
|
---|
| 162 | {
|
---|
| 163 | __copy_user_zeroing(to,from,n);
|
---|
| 164 | return n;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | static __inline unsigned long
|
---|
| 168 | __generic_copy_to_user_nocheck(void *to, const void *from, unsigned long n)
|
---|
| 169 | {
|
---|
| 170 | __copy_user(to,from,n);
|
---|
| 171 | return n;
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 |
|
---|
| 175 | /* Optimize just a little bit when we know the size of the move. */
|
---|
| 176 | void __constant_copy_user(void *to, const void *from, unsigned long n);
|
---|
| 177 |
|
---|
| 178 | /* Optimize just a little bit when we know the size of the move. */
|
---|
| 179 | void __constant_copy_user_zeroing(void *to, const void *from, unsigned long n);
|
---|
| 180 |
|
---|
| 181 | unsigned long __generic_copy_to_user(void *, const void *, unsigned long);
|
---|
| 182 | unsigned long __generic_copy_from_user(void *, const void *, unsigned long);
|
---|
| 183 |
|
---|
[679] | 184 | #if 0
|
---|
[32] | 185 | static __inline unsigned long
|
---|
| 186 | __constant_copy_to_user(void *to, const void *from, unsigned long n)
|
---|
| 187 | {
|
---|
| 188 | if (access_ok(VERIFY_WRITE, to, n))
|
---|
| 189 | __constant_copy_user(to,from,n);
|
---|
| 190 | return n;
|
---|
| 191 | }
|
---|
| 192 |
|
---|
| 193 | static __inline unsigned long
|
---|
| 194 | __constant_copy_from_user(void *to, const void *from, unsigned long n)
|
---|
| 195 | {
|
---|
| 196 | if (access_ok(VERIFY_READ, (void *)from, n))
|
---|
| 197 | __constant_copy_user_zeroing(to,from,n);
|
---|
| 198 | return n;
|
---|
| 199 | }
|
---|
[679] | 200 | #endif
|
---|
[32] | 201 |
|
---|
| 202 | static __inline unsigned long
|
---|
| 203 | __constant_copy_to_user_nocheck(void *to, const void *from, unsigned long n)
|
---|
| 204 | {
|
---|
| 205 | __constant_copy_user(to,from,n);
|
---|
| 206 | return n;
|
---|
| 207 | }
|
---|
| 208 |
|
---|
| 209 | static __inline unsigned long
|
---|
| 210 | __constant_copy_from_user_nocheck(void *to, const void *from, unsigned long n)
|
---|
| 211 | {
|
---|
| 212 | __constant_copy_user_zeroing(to,from,n);
|
---|
| 213 | return n;
|
---|
| 214 | }
|
---|
| 215 |
|
---|
| 216 | unsigned long copy_to_user(void *to, const void *from, unsigned long n);
|
---|
| 217 |
|
---|
| 218 | unsigned long copy_from_user(void *to, const void *from, unsigned long n);
|
---|
| 219 |
|
---|
| 220 | #define copy_to_user_ret(to,from,n,retval) ({ if (copy_to_user(to,from,n)) return retval; })
|
---|
| 221 |
|
---|
| 222 | #define copy_from_user_ret(to,from,n,retval) ({ if (copy_from_user(to,from,n)) return retval; })
|
---|
| 223 |
|
---|
| 224 | #define __copy_to_user(to,from,n) \
|
---|
| 225 | (__builtin_constant_p(n) ? \
|
---|
| 226 | __constant_copy_to_user_nocheck((to),(from),(n)) : \
|
---|
| 227 | __generic_copy_to_user_nocheck((to),(from),(n)))
|
---|
| 228 |
|
---|
| 229 | #define __copy_from_user(to,from,n) \
|
---|
| 230 | (__builtin_constant_p(n) ? \
|
---|
| 231 | __constant_copy_from_user_nocheck((to),(from),(n)) : \
|
---|
| 232 | __generic_copy_from_user_nocheck((to),(from),(n)))
|
---|
| 233 |
|
---|
| 234 | long strncpy_from_user(char *dst, const char *src, long count);
|
---|
| 235 | long __strncpy_from_user(char *dst, const char *src, long count);
|
---|
| 236 | #define strlen_user(str) strnlen_user(str, ~0UL >> 1)
|
---|
| 237 | long strnlen_user(const char *str, long n);
|
---|
[772] | 238 | /*
|
---|
| 239 | * Zero Userspace
|
---|
| 240 | */
|
---|
| 241 | #ifndef __clear_user
|
---|
| 242 | static inline __must_check unsigned long
|
---|
| 243 | __clear_user(void __user *to, unsigned long n)
|
---|
| 244 | {
|
---|
| 245 | memset((void __force *)to, 0, n);
|
---|
| 246 | return 0;
|
---|
| 247 | }
|
---|
| 248 | #endif
|
---|
[32] | 249 |
|
---|
[772] | 250 | static inline __must_check unsigned long
|
---|
| 251 | clear_user(void __user *to, unsigned long n)
|
---|
| 252 | {
|
---|
| 253 | if (!access_ok(to, n))
|
---|
| 254 | return n;
|
---|
| 255 |
|
---|
| 256 | return __clear_user(to, n);
|
---|
| 257 | }
|
---|
| 258 |
|
---|
[32] | 259 | #endif /* __i386_UACCESS_H */
|
---|