4567f1eeb4a7d25f8d079aa846a752514e7d6340
[linux-drm-fsl-dcu.git] / arch / um / include / um_uaccess.h
1 /* 
2  * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3  * Licensed under the GPL
4  */
5
6 #ifndef __ARCH_UM_UACCESS_H
7 #define __ARCH_UM_UACCESS_H
8
9 #include "linux/config.h"
10 #include "choose-mode.h"
11
12 #ifdef CONFIG_MODE_TT
13 #include "uaccess-tt.h"
14 #endif
15
16 #ifdef CONFIG_MODE_SKAS
17 #include "uaccess-skas.h"
18 #endif
19
20 #include "asm/fixmap.h"
21
22 #define __under_task_size(addr, size) \
23         (((unsigned long) (addr) < TASK_SIZE) && \
24          (((unsigned long) (addr) + (size)) < TASK_SIZE))
25
26 #define __access_ok_vsyscall(type, addr, size) \
27          ((type == VERIFY_READ) && \
28           ((unsigned long) (addr) >= FIXADDR_USER_START) && \
29           ((unsigned long) (addr) + (size) <= FIXADDR_USER_END) && \
30           ((unsigned long) (addr) + (size) >= (unsigned long)(addr)))
31
32 #define __addr_range_nowrap(addr, size) \
33         ((unsigned long) (addr) <= ((unsigned long) (addr) + (size)))
34
35 #define access_ok(type, addr, size) \
36         (__addr_range_nowrap(addr, size) && \
37          (__under_task_size(addr, size) || \
38           __access_ok_vsyscall(type, addr, size) || \
39           segment_eq(get_fs(), KERNEL_DS) || \
40           CHOOSE_MODE_PROC(access_ok_tt, access_ok_skas, type, addr, size)))
41
42 static inline int copy_from_user(void *to, const void __user *from, int n)
43 {
44         return(CHOOSE_MODE_PROC(copy_from_user_tt, copy_from_user_skas, to,
45                                 from, n));
46 }
47
48 static inline int copy_to_user(void __user *to, const void *from, int n)
49 {
50         return(CHOOSE_MODE_PROC(copy_to_user_tt, copy_to_user_skas, to, 
51                                 from, n));
52 }
53
54 /*
55  * strncpy_from_user: - Copy a NUL terminated string from userspace.
56  * @dst:   Destination address, in kernel space.  This buffer must be at
57  *         least @count bytes long.
58  * @src:   Source address, in user space.
59  * @count: Maximum number of bytes to copy, including the trailing NUL.
60  *
61  * Copies a NUL-terminated string from userspace to kernel space.
62  *
63  * On success, returns the length of the string (not including the trailing
64  * NUL).
65  *
66  * If access to userspace fails, returns -EFAULT (some data may have been
67  * copied).
68  *
69  * If @count is smaller than the length of the string, copies @count bytes
70  * and returns @count.
71  */
72
73 static inline int strncpy_from_user(char *dst, const char __user *src, int count)
74 {
75         return(CHOOSE_MODE_PROC(strncpy_from_user_tt, strncpy_from_user_skas,
76                                 dst, src, count));
77 }
78
79 /*
80  * __clear_user: - Zero a block of memory in user space, with less checking.
81  * @to:   Destination address, in user space.
82  * @n:    Number of bytes to zero.
83  *
84  * Zero a block of memory in user space.  Caller must check
85  * the specified block with access_ok() before calling this function.
86  *
87  * Returns number of bytes that could not be cleared.
88  * On success, this will be zero.
89  */
90 static inline int __clear_user(void *mem, int len)
91 {
92         return(CHOOSE_MODE_PROC(__clear_user_tt, __clear_user_skas, mem, len));
93 }
94
95 /*
96  * clear_user: - Zero a block of memory in user space.
97  * @to:   Destination address, in user space.
98  * @n:    Number of bytes to zero.
99  *
100  * Zero a block of memory in user space.
101  *
102  * Returns number of bytes that could not be cleared.
103  * On success, this will be zero.
104  */
105 static inline int clear_user(void __user *mem, int len)
106 {
107         return(CHOOSE_MODE_PROC(clear_user_tt, clear_user_skas, mem, len));
108 }
109
110 /*
111  * strlen_user: - Get the size of a string in user space.
112  * @str: The string to measure.
113  * @n:   The maximum valid length
114  *
115  * Get the size of a NUL-terminated string in user space.
116  *
117  * Returns the size of the string INCLUDING the terminating NUL.
118  * On exception, returns 0.
119  * If the string is too long, returns a value greater than @n.
120  */
121 static inline int strnlen_user(const void __user *str, long len)
122 {
123         return(CHOOSE_MODE_PROC(strnlen_user_tt, strnlen_user_skas, str, len));
124 }
125
126 #endif
127
128 /*
129  * Overrides for Emacs so that we follow Linus's tabbing style.
130  * Emacs will notice this stuff at the end of the file and automatically
131  * adjust the settings for this buffer only.  This must remain at the end
132  * of the file.
133  * ---------------------------------------------------------------------------
134  * Local variables:
135  * c-file-style: "linux"
136  * End:
137  */