]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - arch/um/include/um_uaccess.h
uml: move um_virt_to_phys
[mirror_ubuntu-artful-kernel.git] / arch / um / include / um_uaccess.h
CommitLineData
1da177e4 1/*
ae2587e4 2 * Copyright (C) 2002 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
1da177e4
LT
3 * Licensed under the GPL
4 */
5
6#ifndef __ARCH_UM_UACCESS_H
7#define __ARCH_UM_UACCESS_H
8
bf001b26
PE
9#include "asm/fixmap.h"
10
7a590611
PBG
11#define __under_task_size(addr, size) \
12 (((unsigned long) (addr) < TASK_SIZE) && \
ae2587e4 13 (((unsigned long) (addr) + (size)) < TASK_SIZE))
7a590611
PBG
14
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
1da177e4 24#define access_ok(type, addr, size) \
7a590611
PBG
25 (__addr_range_nowrap(addr, size) && \
26 (__under_task_size(addr, size) || \
27 __access_ok_vsyscall(type, addr, size) || \
6aa802ce 28 segment_eq(get_fs(), KERNEL_DS)))
1da177e4 29
6aa802ce
JD
30extern 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);
1da177e4 32
fab95c55
JD
33extern int __do_copy_to_user(void *to, const void *from, int n,
34 void **fault_addr, jmp_buf **fault_catcher);
35extern void __do_copy(void *to, const void *from, int n);
36
1da177e4
LT
37/*
38 * strncpy_from_user: - Copy a NUL terminated string from userspace.
39 * @dst: Destination address, in kernel space. This buffer must be at
40 * least @count bytes long.
41 * @src: Source address, in user space.
42 * @count: Maximum number of bytes to copy, including the trailing NUL.
43 *
44 * Copies a NUL-terminated string from userspace to kernel space.
45 *
46 * On success, returns the length of the string (not including the trailing
47 * NUL).
48 *
49 * If access to userspace fails, returns -EFAULT (some data may have been
50 * copied).
51 *
52 * If @count is smaller than the length of the string, copies @count bytes
53 * and returns @count.
54 */
55
6aa802ce 56extern int strncpy_from_user(char *dst, const char __user *src, int count);
1da177e4
LT
57
58/*
59 * __clear_user: - Zero a block of memory in user space, with less checking.
60 * @to: Destination address, in user space.
61 * @n: Number of bytes to zero.
62 *
63 * Zero a block of memory in user space. Caller must check
64 * the specified block with access_ok() before calling this function.
65 *
66 * Returns number of bytes that could not be cleared.
67 * On success, this will be zero.
68 */
6aa802ce 69extern int __clear_user(void __user *mem, int len);
1da177e4
LT
70
71/*
72 * clear_user: - Zero a block of memory in user space.
73 * @to: Destination address, in user space.
74 * @n: Number of bytes to zero.
75 *
76 * Zero a block of memory in user space.
77 *
78 * Returns number of bytes that could not be cleared.
79 * On success, this will be zero.
80 */
6aa802ce 81extern int clear_user(void __user *mem, int len);
1da177e4
LT
82
83/*
84 * strlen_user: - Get the size of a string in user space.
85 * @str: The string to measure.
86 * @n: The maximum valid length
87 *
88 * Get the size of a NUL-terminated string in user space.
89 *
90 * Returns the size of the string INCLUDING the terminating NUL.
91 * On exception, returns 0.
92 * If the string is too long, returns a value greater than @n.
93 */
6aa802ce 94extern int strnlen_user(const void __user *str, int len);
1da177e4
LT
95
96#endif