blob: f8760a3f43b0f0f6e0402f21089d87e56ba62c29 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Paolo 'Blaisorblade' Giarrusso7a590612005-11-13 16:07:13 -080020#define __under_task_size(addr, size) \
21 (((unsigned long) (addr) < TASK_SIZE) && \
22 (((unsigned long) (addr) + (size)) < TASK_SIZE))
23
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)))
29
30#define __addr_range_nowrap(addr, size) \
31 ((unsigned long) (addr) <= ((unsigned long) (addr) + (size)))
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#define access_ok(type, addr, size) \
Paolo 'Blaisorblade' Giarrusso7a590612005-11-13 16:07:13 -080034 (__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)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Linus Torvalds1da177e2005-04-16 15:20:36 -070040static inline int copy_from_user(void *to, const void __user *from, int n)
41{
42 return(CHOOSE_MODE_PROC(copy_from_user_tt, copy_from_user_skas, to,
43 from, n));
44}
45
46static inline int copy_to_user(void __user *to, const void *from, int n)
47{
48 return(CHOOSE_MODE_PROC(copy_to_user_tt, copy_to_user_skas, to,
49 from, n));
50}
51
52/*
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.
58 *
59 * Copies a NUL-terminated string from userspace to kernel space.
60 *
61 * On success, returns the length of the string (not including the trailing
62 * NUL).
63 *
64 * If access to userspace fails, returns -EFAULT (some data may have been
65 * copied).
66 *
67 * If @count is smaller than the length of the string, copies @count bytes
68 * and returns @count.
69 */
70
71static inline int strncpy_from_user(char *dst, const char __user *src, int count)
72{
73 return(CHOOSE_MODE_PROC(strncpy_from_user_tt, strncpy_from_user_skas,
74 dst, src, count));
75}
76
77/*
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.
81 *
82 * Zero a block of memory in user space. Caller must check
83 * the specified block with access_ok() before calling this function.
84 *
85 * Returns number of bytes that could not be cleared.
86 * On success, this will be zero.
87 */
88static inline int __clear_user(void *mem, int len)
89{
90 return(CHOOSE_MODE_PROC(__clear_user_tt, __clear_user_skas, mem, len));
91}
92
93/*
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.
97 *
98 * Zero a block of memory in user space.
99 *
100 * Returns number of bytes that could not be cleared.
101 * On success, this will be zero.
102 */
103static inline int clear_user(void __user *mem, int len)
104{
105 return(CHOOSE_MODE_PROC(clear_user_tt, clear_user_skas, mem, len));
106}
107
108/*
109 * strlen_user: - Get the size of a string in user space.
110 * @str: The string to measure.
111 * @n: The maximum valid length
112 *
113 * Get the size of a NUL-terminated string in user space.
114 *
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.
118 */
119static inline int strnlen_user(const void __user *str, long len)
120{
121 return(CHOOSE_MODE_PROC(strnlen_user_tt, strnlen_user_skas, str, len));
122}
123
124#endif
125
126/*
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:
135 */