source: GPL/include/asm/uaccess.h@ 18

Last change on this file since 18 was 18, checked in by vladest, 20 years ago

initial import

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