Commit | Line | Data |
---|---|---|
7567746e RK |
1 | /* |
2 | * User memory access support for Hexagon | |
3 | * | |
e1858b2a | 4 | * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved. |
7567746e RK |
5 | * |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License version 2 and | |
8 | * only version 2 as published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope that it will be useful, | |
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | * GNU General Public License for more details. | |
14 | * | |
15 | * You should have received a copy of the GNU General Public License | |
16 | * along with this program; if not, write to the Free Software | |
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
18 | * 02110-1301, USA. | |
19 | */ | |
20 | ||
21 | #ifndef _ASM_UACCESS_H | |
22 | #define _ASM_UACCESS_H | |
23 | /* | |
24 | * User space memory access functions | |
25 | */ | |
7567746e RK |
26 | #include <linux/mm.h> |
27 | #include <asm/segment.h> | |
28 | #include <asm/sections.h> | |
29 | ||
30 | /* | |
31 | * access_ok: - Checks if a user space pointer is valid | |
7567746e RK |
32 | * @addr: User space pointer to start of block to check |
33 | * @size: Size of block to check | |
34 | * | |
b3c395ef DH |
35 | * Context: User context only. This function may sleep if pagefaults are |
36 | * enabled. | |
7567746e RK |
37 | * |
38 | * Checks if a pointer to a block of memory in user space is valid. | |
39 | * | |
40 | * Returns true (nonzero) if the memory block *may* be valid, false (zero) | |
41 | * if it is definitely invalid. | |
42 | * | |
43 | * User address space in Hexagon, like x86, goes to 0xbfffffff, so the | |
44 | * simple MSB-based tests used by MIPS won't work. Some further | |
45 | * optimization is probably possible here, but for now, keep it | |
46 | * reasonably simple and not *too* slow. After all, we've got the | |
47 | * MMU for backup. | |
48 | */ | |
7567746e RK |
49 | |
50 | #define __access_ok(addr, size) \ | |
51 | ((get_fs().seg == KERNEL_DS.seg) || \ | |
52 | (((unsigned long)addr < get_fs().seg) && \ | |
53 | (unsigned long)size < (get_fs().seg - (unsigned long)addr))) | |
54 | ||
55 | /* | |
56 | * When a kernel-mode page fault is taken, the faulting instruction | |
57 | * address is checked against a table of exception_table_entries. | |
58 | * Each entry is a tuple of the address of an instruction that may | |
59 | * be authorized to fault, and the address at which execution should | |
60 | * be resumed instead of the faulting instruction, so as to effect | |
61 | * a workaround. | |
62 | */ | |
63 | ||
64 | /* Assembly somewhat optimized copy routines */ | |
ac4691fa | 65 | unsigned long raw_copy_from_user(void *to, const void __user *from, |
7567746e | 66 | unsigned long n); |
ac4691fa | 67 | unsigned long raw_copy_to_user(void __user *to, const void *from, |
7567746e | 68 | unsigned long n); |
ac4691fa AV |
69 | #define INLINE_COPY_FROM_USER |
70 | #define INLINE_COPY_TO_USER | |
7567746e RK |
71 | |
72 | __kernel_size_t __clear_user_hexagon(void __user *dest, unsigned long count); | |
73 | #define __clear_user(a, s) __clear_user_hexagon((a), (s)) | |
74 | ||
75 | #define __strncpy_from_user(dst, src, n) hexagon_strncpy_from_user(dst, src, n) | |
76 | ||
77 | /* get around the ifndef in asm-generic/uaccess.h */ | |
78 | #define __strnlen_user __strnlen_user | |
79 | ||
80 | extern long __strnlen_user(const char __user *src, long n); | |
81 | ||
82 | static inline long hexagon_strncpy_from_user(char *dst, const char __user *src, | |
83 | long n); | |
84 | ||
85 | #include <asm-generic/uaccess.h> | |
86 | ||
87 | /* Todo: an actual accelerated version of this. */ | |
88 | static inline long hexagon_strncpy_from_user(char *dst, const char __user *src, | |
89 | long n) | |
90 | { | |
91 | long res = __strnlen_user(src, n); | |
92 | ||
f35c1e06 AV |
93 | if (unlikely(!res)) |
94 | return -EFAULT; | |
7567746e RK |
95 | |
96 | if (res > n) { | |
ac4691fa AV |
97 | long left = raw_copy_from_user(dst, src, n); |
98 | if (unlikely(left)) | |
99 | memset(dst + (n - left), 0, left); | |
7567746e RK |
100 | return n; |
101 | } else { | |
ac4691fa AV |
102 | long left = raw_copy_from_user(dst, src, res); |
103 | if (unlikely(left)) | |
104 | memset(dst + (res - left), 0, left); | |
7567746e RK |
105 | return res-1; |
106 | } | |
107 | } | |
108 | ||
109 | #endif |