02e918824e98f10aa61fc7f632401402749e9acf
[linux-flexiantxendom0-3.2.10.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 #include "linux/sched.h"
10
11 #define VERIFY_READ 0
12 #define VERIFY_WRITE 1
13
14 /*
15  * The fs value determines whether argument validity checking should be
16  * performed or not.  If get_fs() == USER_DS, checking is performed, with
17  * get_fs() == KERNEL_DS, checking is bypassed.
18  *
19  * For historical reasons, these macros are grossly misnamed.
20  */
21
22 #define MAKE_MM_SEG(s)  ((mm_segment_t) { (s) })
23
24 #define KERNEL_DS       MAKE_MM_SEG(0xFFFFFFFF)
25 #define USER_DS         MAKE_MM_SEG(TASK_SIZE)
26
27 #define get_ds()        (KERNEL_DS)
28 #define get_fs()        (current_thread_info()->addr_limit)
29 #define set_fs(x)       (current_thread_info()->addr_limit = (x))
30
31 #define segment_eq(a, b) ((a).seg == (b).seg)
32
33 #include "um_uaccess.h"
34
35 #define __copy_from_user(to, from, n) copy_from_user(to, from, n)
36
37 #define __copy_to_user(to, from, n) copy_to_user(to, from, n)
38
39 #define __get_user(x, ptr) \
40 ({ \
41         const __typeof__(ptr) __private_ptr = ptr; \
42         __typeof__(*(__private_ptr)) __private_val; \
43         int __private_ret = -EFAULT; \
44         (x) = 0; \
45         if (__copy_from_user(&__private_val, (__private_ptr), \
46             sizeof(*(__private_ptr))) == 0) {\
47                 (x) = (__typeof__(*(__private_ptr))) __private_val; \
48                 __private_ret = 0; \
49         } \
50         __private_ret; \
51 }) 
52
53 #define get_user(x, ptr) \
54 ({ \
55         const __typeof__((*ptr)) *private_ptr = (ptr); \
56         (access_ok(VERIFY_READ, private_ptr, sizeof(*private_ptr)) ? \
57          __get_user(x, private_ptr) : ((x) = 0, -EFAULT)); \
58 })
59
60 #define __put_user(x, ptr) \
61 ({ \
62         __typeof__(ptr) __private_ptr = ptr; \
63         __typeof__(*(__private_ptr)) __private_val; \
64         int __private_ret = -EFAULT; \
65         __private_val = (__typeof__(*(__private_ptr))) (x); \
66         if (__copy_to_user((__private_ptr), &__private_val, \
67                            sizeof(*(__private_ptr))) == 0) { \
68                 __private_ret = 0; \
69         } \
70         __private_ret; \
71 })
72
73 #define put_user(x, ptr) \
74 ({ \
75         __typeof__(*(ptr)) *private_ptr = (ptr); \
76         (access_ok(VERIFY_WRITE, private_ptr, sizeof(*private_ptr)) ? \
77          __put_user(x, private_ptr) : -EFAULT); \
78 })
79
80 #define strlen_user(str) strnlen_user(str, ~0UL >> 1)
81
82 struct exception_table_entry
83 {
84         unsigned long insn;
85         unsigned long fixup;
86 };
87
88 #endif
89
90 /*
91  * Overrides for Emacs so that we follow Linus's tabbing style.
92  * Emacs will notice this stuff at the end of the file and automatically
93  * adjust the settings for this buffer only.  This must remain at the end
94  * of the file.
95  * ---------------------------------------------------------------------------
96  * Local variables:
97  * c-file-style: "linux"
98  * End:
99  */