vserver 1.9.3
[linux-2.6.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 "../kernel/tt/include/uaccess.h"
14 #endif
15
16 #ifdef CONFIG_MODE_SKAS
17 #include "../kernel/skas/include/uaccess.h"
18 #endif
19
20 #define access_ok(type, addr, size) \
21         CHOOSE_MODE_PROC(access_ok_tt, access_ok_skas, type, addr, size)
22
23 static inline int verify_area(int type, const void * addr, unsigned long size)
24 {
25         return(CHOOSE_MODE_PROC(verify_area_tt, verify_area_skas, type, addr,
26                                 size));
27 }
28
29 static inline int copy_from_user(void *to, const void *from, int n)
30 {
31         return(CHOOSE_MODE_PROC(copy_from_user_tt, copy_from_user_skas, to,
32                                 from, n));
33 }
34
35 static inline int copy_to_user(void *to, const void *from, int n)
36 {
37         return(CHOOSE_MODE_PROC(copy_to_user_tt, copy_to_user_skas, to, 
38                                 from, n));
39 }
40
41 /*
42  * strncpy_from_user: - Copy a NUL terminated string from userspace.
43  * @dst:   Destination address, in kernel space.  This buffer must be at
44  *         least @count bytes long.
45  * @src:   Source address, in user space.
46  * @count: Maximum number of bytes to copy, including the trailing NUL.
47  *
48  * Copies a NUL-terminated string from userspace to kernel space.
49  *
50  * On success, returns the length of the string (not including the trailing
51  * NUL).
52  *
53  * If access to userspace fails, returns -EFAULT (some data may have been
54  * copied).
55  *
56  * If @count is smaller than the length of the string, copies @count bytes
57  * and returns @count.
58  */
59
60 static inline int strncpy_from_user(char *dst, const char *src, int count)
61 {
62         return(CHOOSE_MODE_PROC(strncpy_from_user_tt, strncpy_from_user_skas,
63                                 dst, src, count));
64 }
65
66 /*
67  * __clear_user: - Zero a block of memory in user space, with less checking.
68  * @to:   Destination address, in user space.
69  * @n:    Number of bytes to zero.
70  *
71  * Zero a block of memory in user space.  Caller must check
72  * the specified block with access_ok() before calling this function.
73  *
74  * Returns number of bytes that could not be cleared.
75  * On success, this will be zero.
76  */
77 static inline int __clear_user(void *mem, int len)
78 {
79         return(CHOOSE_MODE_PROC(__clear_user_tt, __clear_user_skas, mem, len));
80 }
81
82 /*
83  * clear_user: - Zero a block of memory in user space.
84  * @to:   Destination address, in user space.
85  * @n:    Number of bytes to zero.
86  *
87  * Zero a block of memory in user space.
88  *
89  * Returns number of bytes that could not be cleared.
90  * On success, this will be zero.
91  */
92 static inline int clear_user(void *mem, int len)
93 {
94         return(CHOOSE_MODE_PROC(clear_user_tt, clear_user_skas, mem, len));
95 }
96
97 /*
98  * strlen_user: - Get the size of a string in user space.
99  * @str: The string to measure.
100  * @n:   The maximum valid length
101  *
102  * Get the size of a NUL-terminated string in user space.
103  *
104  * Returns the size of the string INCLUDING the terminating NUL.
105  * On exception, returns 0.
106  * If the string is too long, returns a value greater than @n.
107  */
108 static inline int strnlen_user(const void *str, int len)
109 {
110         return(CHOOSE_MODE_PROC(strnlen_user_tt, strnlen_user_skas, str, len));
111 }
112
113 #endif
114
115 /*
116  * Overrides for Emacs so that we follow Linus's tabbing style.
117  * Emacs will notice this stuff at the end of the file and automatically
118  * adjust the settings for this buffer only.  This must remain at the end
119  * of the file.
120  * ---------------------------------------------------------------------------
121  * Local variables:
122  * c-file-style: "linux"
123  * End:
124  */