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