2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
6 #ifndef __ARCH_UM_UACCESS_H
7 #define __ARCH_UM_UACCESS_H
9 #include "asm/fixmap.h"
11 #define __under_task_size(addr, size) \
12 (((unsigned long) (addr) < TASK_SIZE) && \
13 (((unsigned long) (addr) + (size)) < TASK_SIZE))
15 #define __access_ok_vsyscall(type, addr, size) \
16 ((type == VERIFY_READ) && \
17 ((unsigned long) (addr) >= FIXADDR_USER_START) && \
18 ((unsigned long) (addr) + (size) <= FIXADDR_USER_END) && \
19 ((unsigned long) (addr) + (size) >= (unsigned long)(addr)))
21 #define __addr_range_nowrap(addr, size) \
22 ((unsigned long) (addr) <= ((unsigned long) (addr) + (size)))
24 #define access_ok(type, addr, size) \
25 (__addr_range_nowrap(addr, size) && \
26 (__under_task_size(addr, size) || \
27 __access_ok_vsyscall(type, addr, size) || \
28 segment_eq(get_fs(), KERNEL_DS)))
30 extern int copy_from_user(void *to, const void __user *from, int n);
31 extern int copy_to_user(void __user *to, const void *from, int n);
34 * strncpy_from_user: - Copy a NUL terminated string from userspace.
35 * @dst: Destination address, in kernel space. This buffer must be at
36 * least @count bytes long.
37 * @src: Source address, in user space.
38 * @count: Maximum number of bytes to copy, including the trailing NUL.
40 * Copies a NUL-terminated string from userspace to kernel space.
42 * On success, returns the length of the string (not including the trailing
45 * If access to userspace fails, returns -EFAULT (some data may have been
48 * If @count is smaller than the length of the string, copies @count bytes
52 extern int strncpy_from_user(char *dst, const char __user *src, int count);
55 * __clear_user: - Zero a block of memory in user space, with less checking.
56 * @to: Destination address, in user space.
57 * @n: Number of bytes to zero.
59 * Zero a block of memory in user space. Caller must check
60 * the specified block with access_ok() before calling this function.
62 * Returns number of bytes that could not be cleared.
63 * On success, this will be zero.
65 extern int __clear_user(void __user *mem, int len);
68 * clear_user: - Zero a block of memory in user space.
69 * @to: Destination address, in user space.
70 * @n: Number of bytes to zero.
72 * Zero a block of memory in user space.
74 * Returns number of bytes that could not be cleared.
75 * On success, this will be zero.
77 extern int clear_user(void __user *mem, int len);
80 * strlen_user: - Get the size of a string in user space.
81 * @str: The string to measure.
82 * @n: The maximum valid length
84 * Get the size of a NUL-terminated string in user space.
86 * Returns the size of the string INCLUDING the terminating NUL.
87 * On exception, returns 0.
88 * If the string is too long, returns a value greater than @n.
90 extern int strnlen_user(const void __user *str, int len);
95 * Overrides for Emacs so that we follow Linus's tabbing style.
96 * Emacs will notice this stuff at the end of the file and automatically
97 * adjust the settings for this buffer only. This must remain at the end
99 * ---------------------------------------------------------------------------
101 * c-file-style: "linux"