Loading...
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
4 * Copyright (C) 2015 Richard Weinberger (richard@nod.at)
5 */
6
7#ifndef __UM_UACCESS_H
8#define __UM_UACCESS_H
9
10#include <asm/elf.h>
11#include <asm/unaligned.h>
12
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(addr, size) \
18 (((unsigned long) (addr) >= FIXADDR_USER_START) && \
19 ((unsigned long) (addr) + (size) <= FIXADDR_USER_END) && \
20 ((unsigned long) (addr) + (size) >= (unsigned long)(addr)))
21
22#define __addr_range_nowrap(addr, size) \
23 ((unsigned long) (addr) <= ((unsigned long) (addr) + (size)))
24
25extern unsigned long raw_copy_from_user(void *to, const void __user *from, unsigned long n);
26extern unsigned long raw_copy_to_user(void __user *to, const void *from, unsigned long n);
27extern unsigned long __clear_user(void __user *mem, unsigned long len);
28static inline int __access_ok(const void __user *ptr, unsigned long size);
29
30/* Teach asm-generic/uaccess.h that we have C functions for these. */
31#define __access_ok __access_ok
32#define __clear_user __clear_user
33
34#define INLINE_COPY_FROM_USER
35#define INLINE_COPY_TO_USER
36
37#include <asm-generic/uaccess.h>
38
39static inline int __access_ok(const void __user *ptr, unsigned long size)
40{
41 unsigned long addr = (unsigned long)ptr;
42 return __addr_range_nowrap(addr, size) &&
43 (__under_task_size(addr, size) ||
44 __access_ok_vsyscall(addr, size));
45}
46
47/* no pagefaults for kernel addresses in um */
48#define __get_kernel_nofault(dst, src, type, err_label) \
49do { \
50 *((type *)dst) = get_unaligned((type *)(src)); \
51 if (0) /* make sure the label looks used to the compiler */ \
52 goto err_label; \
53} while (0)
54
55#define __put_kernel_nofault(dst, src, type, err_label) \
56do { \
57 put_unaligned(*((type *)src), (type *)(dst)); \
58 if (0) /* make sure the label looks used to the compiler */ \
59 goto err_label; \
60} while (0)
61
62#endif
1/*
2 * Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
5
6#ifndef __UM_UACCESS_H
7#define __UM_UACCESS_H
8
9#include <asm/errno.h>
10#include <asm/processor.h>
11
12/* thread_info has a mm_segment_t in it, so put the definition up here */
13typedef struct {
14 unsigned long seg;
15} mm_segment_t;
16
17#include "linux/thread_info.h"
18
19#define VERIFY_READ 0
20#define VERIFY_WRITE 1
21
22/*
23 * The fs value determines whether argument validity checking should be
24 * performed or not. If get_fs() == USER_DS, checking is performed, with
25 * get_fs() == KERNEL_DS, checking is bypassed.
26 *
27 * For historical reasons, these macros are grossly misnamed.
28 */
29
30#define MAKE_MM_SEG(s) ((mm_segment_t) { (s) })
31
32#define KERNEL_DS MAKE_MM_SEG(0xFFFFFFFF)
33#define USER_DS MAKE_MM_SEG(TASK_SIZE)
34
35#define get_ds() (KERNEL_DS)
36#define get_fs() (current_thread_info()->addr_limit)
37#define set_fs(x) (current_thread_info()->addr_limit = (x))
38
39#define segment_eq(a, b) ((a).seg == (b).seg)
40
41#include "um_uaccess.h"
42
43#define __copy_from_user(to, from, n) copy_from_user(to, from, n)
44
45#define __copy_to_user(to, from, n) copy_to_user(to, from, n)
46
47#define __copy_to_user_inatomic __copy_to_user
48#define __copy_from_user_inatomic __copy_from_user
49
50#define __get_user(x, ptr) \
51({ \
52 const __typeof__(*(ptr)) __user *__private_ptr = (ptr); \
53 __typeof__(x) __private_val; \
54 int __private_ret = -EFAULT; \
55 (x) = (__typeof__(*(__private_ptr)))0; \
56 if (__copy_from_user((__force void *)&__private_val, (__private_ptr),\
57 sizeof(*(__private_ptr))) == 0) { \
58 (x) = (__typeof__(*(__private_ptr))) __private_val; \
59 __private_ret = 0; \
60 } \
61 __private_ret; \
62})
63
64#define get_user(x, ptr) \
65({ \
66 const __typeof__((*(ptr))) __user *private_ptr = (ptr); \
67 (access_ok(VERIFY_READ, private_ptr, sizeof(*private_ptr)) ? \
68 __get_user(x, private_ptr) : ((x) = (__typeof__(*ptr))0, -EFAULT)); \
69})
70
71#define __put_user(x, ptr) \
72({ \
73 __typeof__(*(ptr)) __user *__private_ptr = ptr; \
74 __typeof__(*(__private_ptr)) __private_val; \
75 int __private_ret = -EFAULT; \
76 __private_val = (__typeof__(*(__private_ptr))) (x); \
77 if (__copy_to_user((__private_ptr), &__private_val, \
78 sizeof(*(__private_ptr))) == 0) { \
79 __private_ret = 0; \
80 } \
81 __private_ret; \
82})
83
84#define put_user(x, ptr) \
85({ \
86 __typeof__(*(ptr)) __user *private_ptr = (ptr); \
87 (access_ok(VERIFY_WRITE, private_ptr, sizeof(*private_ptr)) ? \
88 __put_user(x, private_ptr) : -EFAULT); \
89})
90
91#define strlen_user(str) strnlen_user(str, ~0U >> 1)
92
93struct exception_table_entry
94{
95 unsigned long insn;
96 unsigned long fixup;
97};
98
99#endif