Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include "choose-mode.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include "uaccess-skas.h" |
Pekka J Enberg | bf001b2 | 2005-12-12 00:37:16 -0800 | [diff] [blame] | 11 | #include "asm/fixmap.h" |
| 12 | |
Paolo 'Blaisorblade' Giarrusso | 7a59061 | 2005-11-13 16:07:13 -0800 | [diff] [blame] | 13 | #define __under_task_size(addr, size) \ |
| 14 | (((unsigned long) (addr) < TASK_SIZE) && \ |
| 15 | (((unsigned long) (addr) + (size)) < TASK_SIZE)) |
| 16 | |
| 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #define access_ok(type, addr, size) \ |
Paolo 'Blaisorblade' Giarrusso | 7a59061 | 2005-11-13 16:07:13 -0800 | [diff] [blame] | 27 | (__addr_range_nowrap(addr, size) && \ |
| 28 | (__under_task_size(addr, size) || \ |
| 29 | __access_ok_vsyscall(type, addr, size) || \ |
| 30 | segment_eq(get_fs(), KERNEL_DS) || \ |
| 31 | CHOOSE_MODE_PROC(access_ok_tt, access_ok_skas, type, addr, size))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | static inline int copy_from_user(void *to, const void __user *from, int n) |
| 34 | { |
| 35 | return(CHOOSE_MODE_PROC(copy_from_user_tt, copy_from_user_skas, to, |
| 36 | from, n)); |
| 37 | } |
| 38 | |
| 39 | static inline int copy_to_user(void __user *to, const void *from, int n) |
| 40 | { |
| 41 | return(CHOOSE_MODE_PROC(copy_to_user_tt, copy_to_user_skas, to, |
| 42 | from, n)); |
| 43 | } |
| 44 | |
| 45 | /* |
| 46 | * strncpy_from_user: - Copy a NUL terminated string from userspace. |
| 47 | * @dst: Destination address, in kernel space. This buffer must be at |
| 48 | * least @count bytes long. |
| 49 | * @src: Source address, in user space. |
| 50 | * @count: Maximum number of bytes to copy, including the trailing NUL. |
| 51 | * |
| 52 | * Copies a NUL-terminated string from userspace to kernel space. |
| 53 | * |
| 54 | * On success, returns the length of the string (not including the trailing |
| 55 | * NUL). |
| 56 | * |
| 57 | * If access to userspace fails, returns -EFAULT (some data may have been |
| 58 | * copied). |
| 59 | * |
| 60 | * If @count is smaller than the length of the string, copies @count bytes |
| 61 | * and returns @count. |
| 62 | */ |
| 63 | |
| 64 | static inline int strncpy_from_user(char *dst, const char __user *src, int count) |
| 65 | { |
| 66 | return(CHOOSE_MODE_PROC(strncpy_from_user_tt, strncpy_from_user_skas, |
| 67 | dst, src, count)); |
| 68 | } |
| 69 | |
| 70 | /* |
| 71 | * __clear_user: - Zero a block of memory in user space, with less checking. |
| 72 | * @to: Destination address, in user space. |
| 73 | * @n: Number of bytes to zero. |
| 74 | * |
| 75 | * Zero a block of memory in user space. Caller must check |
| 76 | * the specified block with access_ok() before calling this function. |
| 77 | * |
| 78 | * Returns number of bytes that could not be cleared. |
| 79 | * On success, this will be zero. |
| 80 | */ |
| 81 | static inline int __clear_user(void *mem, int len) |
| 82 | { |
| 83 | return(CHOOSE_MODE_PROC(__clear_user_tt, __clear_user_skas, mem, len)); |
| 84 | } |
| 85 | |
| 86 | /* |
| 87 | * clear_user: - Zero a block of memory in user space. |
| 88 | * @to: Destination address, in user space. |
| 89 | * @n: Number of bytes to zero. |
| 90 | * |
| 91 | * Zero a block of memory in user space. |
| 92 | * |
| 93 | * Returns number of bytes that could not be cleared. |
| 94 | * On success, this will be zero. |
| 95 | */ |
| 96 | static inline int clear_user(void __user *mem, int len) |
| 97 | { |
| 98 | return(CHOOSE_MODE_PROC(clear_user_tt, clear_user_skas, mem, len)); |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | * strlen_user: - Get the size of a string in user space. |
| 103 | * @str: The string to measure. |
| 104 | * @n: The maximum valid length |
| 105 | * |
| 106 | * Get the size of a NUL-terminated string in user space. |
| 107 | * |
| 108 | * Returns the size of the string INCLUDING the terminating NUL. |
| 109 | * On exception, returns 0. |
| 110 | * If the string is too long, returns a value greater than @n. |
| 111 | */ |
| 112 | static inline int strnlen_user(const void __user *str, long len) |
| 113 | { |
| 114 | return(CHOOSE_MODE_PROC(strnlen_user_tt, strnlen_user_skas, str, len)); |
| 115 | } |
| 116 | |
| 117 | #endif |
| 118 | |
| 119 | /* |
| 120 | * Overrides for Emacs so that we follow Linus's tabbing style. |
| 121 | * Emacs will notice this stuff at the end of the file and automatically |
| 122 | * adjust the settings for this buffer only. This must remain at the end |
| 123 | * of the file. |
| 124 | * --------------------------------------------------------------------------- |
| 125 | * Local variables: |
| 126 | * c-file-style: "linux" |
| 127 | * End: |
| 128 | */ |