blob: 5ef311a1a394db18365498340cfec34b2e147c8c [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Jeff Dikeae2587e2007-10-16 01:26:57 -07002 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * Licensed under the GPL
4 */
5
6#ifndef __ARCH_UM_UACCESS_H
7#define __ARCH_UM_UACCESS_H
8
Pekka J Enbergbf001b22005-12-12 00:37:16 -08009#include "asm/fixmap.h"
10
Paolo 'Blaisorblade' Giarrusso7a590612005-11-13 16:07:13 -080011#define __under_task_size(addr, size) \
12 (((unsigned long) (addr) < TASK_SIZE) && \
Jeff Dikeae2587e2007-10-16 01:26:57 -070013 (((unsigned long) (addr) + (size)) < TASK_SIZE))
Paolo 'Blaisorblade' Giarrusso7a590612005-11-13 16:07:13 -080014
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)))
20
21#define __addr_range_nowrap(addr, size) \
22 ((unsigned long) (addr) <= ((unsigned long) (addr) + (size)))
23
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#define access_ok(type, addr, size) \
Paolo 'Blaisorblade' Giarrusso7a590612005-11-13 16:07:13 -080025 (__addr_range_nowrap(addr, size) && \
26 (__under_task_size(addr, size) || \
27 __access_ok_vsyscall(type, addr, size) || \
Jeff Dike6aa802c2007-10-16 01:26:56 -070028 segment_eq(get_fs(), KERNEL_DS)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Jeff Dike6aa802c2007-10-16 01:26:56 -070030extern int copy_from_user(void *to, const void __user *from, int n);
31extern int copy_to_user(void __user *to, const void *from, int n);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33/*
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.
39 *
40 * Copies a NUL-terminated string from userspace to kernel space.
41 *
42 * On success, returns the length of the string (not including the trailing
43 * NUL).
44 *
45 * If access to userspace fails, returns -EFAULT (some data may have been
46 * copied).
47 *
48 * If @count is smaller than the length of the string, copies @count bytes
49 * and returns @count.
50 */
51
Jeff Dike6aa802c2007-10-16 01:26:56 -070052extern int strncpy_from_user(char *dst, const char __user *src, int count);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54/*
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.
58 *
59 * Zero a block of memory in user space. Caller must check
60 * the specified block with access_ok() before calling this function.
61 *
62 * Returns number of bytes that could not be cleared.
63 * On success, this will be zero.
64 */
Jeff Dike6aa802c2007-10-16 01:26:56 -070065extern int __clear_user(void __user *mem, int len);
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67/*
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.
71 *
72 * Zero a block of memory in user space.
73 *
74 * Returns number of bytes that could not be cleared.
75 * On success, this will be zero.
76 */
Jeff Dike6aa802c2007-10-16 01:26:56 -070077extern int clear_user(void __user *mem, int len);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79/*
80 * strlen_user: - Get the size of a string in user space.
81 * @str: The string to measure.
82 * @n: The maximum valid length
83 *
84 * Get the size of a NUL-terminated string in user space.
85 *
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.
89 */
Jeff Dike6aa802c2007-10-16 01:26:56 -070090extern int strnlen_user(const void __user *str, int len);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92#endif