blob: 2b6fc8e0f07137bdec6f6b5fcd166f9e79d4e0d6 [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
Jeff Dike8192ab42008-02-04 22:30:53 -08009#include <asm/elf.h>
10#include <asm/fixmap.h>
11#include "sysdep/archsetjmp.h"
Pekka J Enbergbf001b22005-12-12 00:37:16 -080012
Paolo 'Blaisorblade' Giarrusso7a590612005-11-13 16:07:13 -080013#define __under_task_size(addr, size) \
14 (((unsigned long) (addr) < TASK_SIZE) && \
Jeff Dikeae2587e2007-10-16 01:26:57 -070015 (((unsigned long) (addr) + (size)) < TASK_SIZE))
Paolo 'Blaisorblade' Giarrusso7a590612005-11-13 16:07:13 -080016
17#define __access_ok_vsyscall(type, addr, size) \
18 ((type == VERIFY_READ) && \
19 ((unsigned long) (addr) >= FIXADDR_USER_START) && \
20 ((unsigned long) (addr) + (size) <= FIXADDR_USER_END) && \
21 ((unsigned long) (addr) + (size) >= (unsigned long)(addr)))
22
23#define __addr_range_nowrap(addr, size) \
24 ((unsigned long) (addr) <= ((unsigned long) (addr) + (size)))
25
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#define access_ok(type, addr, size) \
Paolo 'Blaisorblade' Giarrusso7a590612005-11-13 16:07:13 -080027 (__addr_range_nowrap(addr, size) && \
28 (__under_task_size(addr, size) || \
29 __access_ok_vsyscall(type, addr, size) || \
Jeff Dike6aa802c2007-10-16 01:26:56 -070030 segment_eq(get_fs(), KERNEL_DS)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Jeff Dike6aa802c2007-10-16 01:26:56 -070032extern int copy_from_user(void *to, const void __user *from, int n);
33extern int copy_to_user(void __user *to, const void *from, int n);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
Jeff Dikefab95c52007-10-16 01:27:05 -070035extern int __do_copy_to_user(void *to, const void *from, int n,
36 void **fault_addr, jmp_buf **fault_catcher);
37extern void __do_copy(void *to, const void *from, int n);
38
Linus Torvalds1da177e2005-04-16 15:20:36 -070039/*
40 * strncpy_from_user: - Copy a NUL terminated string from userspace.
41 * @dst: Destination address, in kernel space. This buffer must be at
42 * least @count bytes long.
43 * @src: Source address, in user space.
44 * @count: Maximum number of bytes to copy, including the trailing NUL.
45 *
46 * Copies a NUL-terminated string from userspace to kernel space.
47 *
48 * On success, returns the length of the string (not including the trailing
49 * NUL).
50 *
51 * If access to userspace fails, returns -EFAULT (some data may have been
52 * copied).
53 *
54 * If @count is smaller than the length of the string, copies @count bytes
55 * and returns @count.
56 */
57
Jeff Dike6aa802c2007-10-16 01:26:56 -070058extern int strncpy_from_user(char *dst, const char __user *src, int count);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60/*
61 * __clear_user: - Zero a block of memory in user space, with less checking.
62 * @to: Destination address, in user space.
63 * @n: Number of bytes to zero.
64 *
65 * Zero a block of memory in user space. Caller must check
66 * the specified block with access_ok() before calling this function.
67 *
68 * Returns number of bytes that could not be cleared.
69 * On success, this will be zero.
70 */
Jeff Dike6aa802c2007-10-16 01:26:56 -070071extern int __clear_user(void __user *mem, int len);
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
73/*
74 * clear_user: - Zero a block of memory in user space.
75 * @to: Destination address, in user space.
76 * @n: Number of bytes to zero.
77 *
78 * Zero a block of memory in user space.
79 *
80 * Returns number of bytes that could not be cleared.
81 * On success, this will be zero.
82 */
Jeff Dike6aa802c2007-10-16 01:26:56 -070083extern int clear_user(void __user *mem, int len);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85/*
86 * strlen_user: - Get the size of a string in user space.
87 * @str: The string to measure.
88 * @n: The maximum valid length
89 *
90 * Get the size of a NUL-terminated string in user space.
91 *
92 * Returns the size of the string INCLUDING the terminating NUL.
93 * On exception, returns 0.
94 * If the string is too long, returns a value greater than @n.
95 */
Jeff Dike6aa802c2007-10-16 01:26:56 -070096extern int strnlen_user(const void __user *str, int len);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
98#endif