Fedora Core 2 - 1.492
[linux-2.6.git] / include / asm-um / uaccess.h
1 /* 
2  * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3  * Licensed under the GPL
4  */
5
6 #ifndef __UM_UACCESS_H
7 #define __UM_UACCESS_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(TASK_SIZE)
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 #include "um_uaccess.h"
32
33 #define __copy_from_user(to, from, n) copy_from_user(to, from, n)
34
35 #define __copy_to_user(to, from, n) copy_to_user(to, from, n)
36
37 #define __copy_to_user_inatomic __copy_to_user
38 #define __copy_from_user_inatomic __copy_from_user
39
40 #define __get_user(x, ptr) \
41 ({ \
42         const __typeof__(ptr) __private_ptr = ptr; \
43         __typeof__(*(__private_ptr)) __private_val; \
44         int __private_ret = -EFAULT; \
45         (x) = 0; \
46         if (__copy_from_user(&__private_val, (__private_ptr), \
47             sizeof(*(__private_ptr))) == 0) {\
48                 (x) = (__typeof__(*(__private_ptr))) __private_val; \
49                 __private_ret = 0; \
50         } \
51         __private_ret; \
52 }) 
53
54 #define get_user(x, ptr) \
55 ({ \
56         const __typeof__((*ptr)) *private_ptr = (ptr); \
57         (access_ok(VERIFY_READ, private_ptr, sizeof(*private_ptr)) ? \
58          __get_user(x, private_ptr) : ((x) = 0, -EFAULT)); \
59 })
60
61 #define __put_user(x, ptr) \
62 ({ \
63         __typeof__(ptr) __private_ptr = ptr; \
64         __typeof__(*(__private_ptr)) __private_val; \
65         int __private_ret = -EFAULT; \
66         __private_val = (__typeof__(*(__private_ptr))) (x); \
67         if (__copy_to_user((__private_ptr), &__private_val, \
68                            sizeof(*(__private_ptr))) == 0) { \
69                 __private_ret = 0; \
70         } \
71         __private_ret; \
72 })
73
74 #define put_user(x, ptr) \
75 ({ \
76         __typeof__(*(ptr)) *private_ptr = (ptr); \
77         (access_ok(VERIFY_WRITE, private_ptr, sizeof(*private_ptr)) ? \
78          __put_user(x, private_ptr) : -EFAULT); \
79 })
80
81 #define strlen_user(str) strnlen_user(str, ~0UL >> 1)
82
83 struct exception_table_entry
84 {
85         unsigned long insn;
86         unsigned long fixup;
87 };
88
89 #endif
90
91 /*
92  * Overrides for Emacs so that we follow Linus's tabbing style.
93  * Emacs will notice this stuff at the end of the file and automatically
94  * adjust the settings for this buffer only.  This must remain at the end
95  * of the file.
96  * ---------------------------------------------------------------------------
97  * Local variables:
98  * c-file-style: "linux"
99  * End:
100  */