| 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 |
|
|---|
| 46 | #define access_ok(type, addr, size) __access_ok((unsigned long)(addr),(size))
|
|---|
| 47 |
|
|---|
| 48 | /*
|
|---|
| 49 | * The architecture should really override this if possible, at least
|
|---|
| 50 | * doing a check on the get_fs()
|
|---|
| 51 | */
|
|---|
| 52 | static inline int __access_ok(unsigned long addr, unsigned long size)
|
|---|
| 53 | {
|
|---|
| 54 | return 1;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | #define verify_area(type, addr, size) (access_ok(type, (void *)addr,size) ? 0 : -EFAULT)
|
|---|
| 58 |
|
|---|
| 59 |
|
|---|
| 60 | /*
|
|---|
| 61 | * The exception table consists of pairs of addresses: the first is the
|
|---|
| 62 | * address of an instruction that is allowed to fault, and the second is
|
|---|
| 63 | * the address at which the program should continue. No registers are
|
|---|
| 64 | * modified, so it is entirely up to the continuation code to figure out
|
|---|
| 65 | * what to do.
|
|---|
| 66 | *
|
|---|
| 67 | * All the routines below use bits of fixup code that are out of line
|
|---|
| 68 | * with the main instruction path. This means when everything is well,
|
|---|
| 69 | * we don't even have to jump over them. Further, they do not intrude
|
|---|
| 70 | * on our cache or tlb entries.
|
|---|
| 71 | */
|
|---|
| 72 |
|
|---|
| 73 | struct exception_table_entry
|
|---|
| 74 | {
|
|---|
| 75 | unsigned long insn, fixup;
|
|---|
| 76 | };
|
|---|
| 77 |
|
|---|
| 78 | /* Returns 0 if exception not found and fixup otherwise. */
|
|---|
| 79 | extern unsigned long search_exception_table(unsigned long);
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 | /*
|
|---|
| 83 | * These are the main single-value transfer routines. They automatically
|
|---|
| 84 | * use the right size if we just have the right pointer type.
|
|---|
| 85 | *
|
|---|
| 86 | * This gets kind of ugly. We want to return _two_ values in "get_user()"
|
|---|
| 87 | * and yet we don't want to do any pointers, because that is too much
|
|---|
| 88 | * of a performance impact. Thus we have a few rather ugly macros here,
|
|---|
| 89 | * and hide all the uglyness from the user.
|
|---|
| 90 | *
|
|---|
| 91 | * The "__xxx" versions of the user access functions are versions that
|
|---|
| 92 | * do not verify the address space, that must have been done previously
|
|---|
| 93 | * with a separate "access_ok()" call (this is used when we do multiple
|
|---|
| 94 | * accesses to the same area of user memory).
|
|---|
| 95 | */
|
|---|
| 96 |
|
|---|
| 97 | /* Careful: we have to cast the result to the type of the pointer for sign reasons */
|
|---|
| 98 | int __get_user(int size, void *dest, void *src);
|
|---|
| 99 |
|
|---|
| 100 | extern void __put_user_bad(void);
|
|---|
| 101 |
|
|---|
| 102 | #define get_user(x,ptr) \
|
|---|
| 103 | __get_user(sizeof(*ptr), &x,(ptr))
|
|---|
| 104 |
|
|---|
| 105 | int _put_user(int size, int x, void *ptr);
|
|---|
| 106 |
|
|---|
| 107 | #define put_user(x,ptr) \
|
|---|
| 108 | _put_user(sizeof(*ptr), x, (ptr))
|
|---|
| 109 |
|
|---|
| 110 | #define __put_user(x,ptr) \
|
|---|
| 111 | _put_user(sizeof(*ptr), x, (ptr))
|
|---|
| 112 |
|
|---|
| 113 | #define __put_user_nocheck(x,ptr,size) lksjdflksdjf
|
|---|
| 114 |
|
|---|
| 115 | #define __put_user_size(x,ptr,size,retval) asdlkfjsdklfj
|
|---|
| 116 |
|
|---|
| 117 | struct __large_struct { unsigned long buf[100]; };
|
|---|
| 118 | #define __m(x) (*(struct __large_struct *)(x))
|
|---|
| 119 |
|
|---|
| 120 | /*
|
|---|
| 121 | * Tell gcc we read from memory instead of writing: this is because
|
|---|
| 122 | * we do not write to any memory gcc knows about, so there are no
|
|---|
| 123 | * aliasing issues.
|
|---|
| 124 | */
|
|---|
| 125 | #define __put_user_asm(x, addr, err, itype, rtype, ltype) lksjdf
|
|---|
| 126 |
|
|---|
| 127 |
|
|---|
| 128 | #define __get_user_nocheck(x,ptr,size) lsjdf
|
|---|
| 129 |
|
|---|
| 130 | extern long __get_user_bad(void);
|
|---|
| 131 |
|
|---|
| 132 | #define __get_user_size(x,ptr,size,retval) ksjdf
|
|---|
| 133 |
|
|---|
| 134 | #define __get_user_asm(x, addr, err, itype, rtype, ltype) sldkjf
|
|---|
| 135 |
|
|---|
| 136 | /*
|
|---|
| 137 | * The "xxx_ret" versions return constant specified in third argument, if
|
|---|
| 138 | * something bad happens. These macros can be optimized for the
|
|---|
| 139 | * case of just returning from the function xxx_ret is used.
|
|---|
| 140 | */
|
|---|
| 141 |
|
|---|
| 142 | #define put_user_ret(x,ptr,ret) ({ if (put_user(x,ptr)) return ret; })
|
|---|
| 143 |
|
|---|
| 144 | #define get_user_ret(x,ptr,ret) if (get_user(sizeof(x), (void *)&x, (void *)ptr)) return ret;
|
|---|
| 145 |
|
|---|
| 146 |
|
|---|
| 147 | /*
|
|---|
| 148 | * Copy To/From Userspace
|
|---|
| 149 | */
|
|---|
| 150 |
|
|---|
| 151 | /* Generic arbitrary sized copy. */
|
|---|
| 152 | void __copy_user(void *to, const void *from, unsigned long n);
|
|---|
| 153 |
|
|---|
| 154 | void __copy_user_zeroing(void *to, const void *from, unsigned long n);
|
|---|
| 155 |
|
|---|
| 156 | /* We let the __ versions of copy_from/to_user inline, because they're often
|
|---|
| 157 | * used in fast paths and have only a small space overhead.
|
|---|
| 158 | */
|
|---|
| 159 | static __inline unsigned long
|
|---|
| 160 | __generic_copy_from_user_nocheck(void *to, const void *from, unsigned long n)
|
|---|
| 161 | {
|
|---|
| 162 | __copy_user_zeroing(to,from,n);
|
|---|
| 163 | return n;
|
|---|
| 164 | }
|
|---|
| 165 |
|
|---|
| 166 | static __inline unsigned long
|
|---|
| 167 | __generic_copy_to_user_nocheck(void *to, const void *from, unsigned long n)
|
|---|
| 168 | {
|
|---|
| 169 | __copy_user(to,from,n);
|
|---|
| 170 | return n;
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 |
|
|---|
| 174 | /* Optimize just a little bit when we know the size of the move. */
|
|---|
| 175 | void __constant_copy_user(void *to, const void *from, unsigned long n);
|
|---|
| 176 |
|
|---|
| 177 | /* Optimize just a little bit when we know the size of the move. */
|
|---|
| 178 | void __constant_copy_user_zeroing(void *to, const void *from, unsigned long n);
|
|---|
| 179 |
|
|---|
| 180 | unsigned long __generic_copy_to_user(void *, const void *, unsigned long);
|
|---|
| 181 | unsigned long __generic_copy_from_user(void *, const void *, unsigned long);
|
|---|
| 182 |
|
|---|
| 183 | #if 0
|
|---|
| 184 | static __inline unsigned long
|
|---|
| 185 | __constant_copy_to_user(void *to, const void *from, unsigned long n)
|
|---|
| 186 | {
|
|---|
| 187 | if (access_ok(VERIFY_WRITE, to, n))
|
|---|
| 188 | __constant_copy_user(to,from,n);
|
|---|
| 189 | return n;
|
|---|
| 190 | }
|
|---|
| 191 |
|
|---|
| 192 | static __inline unsigned long
|
|---|
| 193 | __constant_copy_from_user(void *to, const void *from, unsigned long n)
|
|---|
| 194 | {
|
|---|
| 195 | if (access_ok(VERIFY_READ, (void *)from, n))
|
|---|
| 196 | __constant_copy_user_zeroing(to,from,n);
|
|---|
| 197 | return n;
|
|---|
| 198 | }
|
|---|
| 199 | #endif
|
|---|
| 200 |
|
|---|
| 201 | static __inline unsigned long
|
|---|
| 202 | __constant_copy_to_user_nocheck(void *to, const void *from, unsigned long n)
|
|---|
| 203 | {
|
|---|
| 204 | __constant_copy_user(to,from,n);
|
|---|
| 205 | return n;
|
|---|
| 206 | }
|
|---|
| 207 |
|
|---|
| 208 | static __inline unsigned long
|
|---|
| 209 | __constant_copy_from_user_nocheck(void *to, const void *from, unsigned long n)
|
|---|
| 210 | {
|
|---|
| 211 | __constant_copy_user_zeroing(to,from,n);
|
|---|
| 212 | return n;
|
|---|
| 213 | }
|
|---|
| 214 |
|
|---|
| 215 | unsigned long copy_to_user(void *to, const void *from, unsigned long n);
|
|---|
| 216 |
|
|---|
| 217 | unsigned long copy_from_user(void *to, const void *from, unsigned long n);
|
|---|
| 218 |
|
|---|
| 219 | #define copy_to_user_ret(to,from,n,retval) ({ if (copy_to_user(to,from,n)) return retval; })
|
|---|
| 220 |
|
|---|
| 221 | #define copy_from_user_ret(to,from,n,retval) ({ if (copy_from_user(to,from,n)) return retval; })
|
|---|
| 222 |
|
|---|
| 223 | #define __copy_to_user(to,from,n) \
|
|---|
| 224 | (__builtin_constant_p(n) ? \
|
|---|
| 225 | __constant_copy_to_user_nocheck((to),(from),(n)) : \
|
|---|
| 226 | __generic_copy_to_user_nocheck((to),(from),(n)))
|
|---|
| 227 |
|
|---|
| 228 | #define __copy_from_user(to,from,n) \
|
|---|
| 229 | (__builtin_constant_p(n) ? \
|
|---|
| 230 | __constant_copy_from_user_nocheck((to),(from),(n)) : \
|
|---|
| 231 | __generic_copy_from_user_nocheck((to),(from),(n)))
|
|---|
| 232 |
|
|---|
| 233 | long strncpy_from_user(char *dst, const char *src, long count);
|
|---|
| 234 | long __strncpy_from_user(char *dst, const char *src, long count);
|
|---|
| 235 | #define strlen_user(str) strnlen_user(str, ~0UL >> 1)
|
|---|
| 236 | long strnlen_user(const char *str, long n);
|
|---|
| 237 | unsigned long clear_user(void *mem, unsigned long len);
|
|---|
| 238 | unsigned long __clear_user(void *mem, unsigned long len);
|
|---|
| 239 |
|
|---|
| 240 | #endif /* __i386_UACCESS_H */
|
|---|