uaccess_32.h 1.54 KB
Newer Older
1
/* SPDX-License-Identifier: GPL-2.0 */
2
3
#ifndef _ASM_X86_UACCESS_32_H
#define _ASM_X86_UACCESS_32_H
Linus Torvalds's avatar
Linus Torvalds committed
4
5
6
7
8

/*
 * User space memory access functions
 */
#include <linux/string.h>
9
#include <asm/asm.h>
Linus Torvalds's avatar
Linus Torvalds committed
10
11
#include <asm/page.h>

Al Viro's avatar
Al Viro committed
12
13
unsigned long __must_check __copy_user_ll
		(void *to, const void *from, unsigned long n);
14
15
unsigned long __must_check __copy_from_user_ll_nocache_nozero
		(void *to, const void __user *from, unsigned long n);
Linus Torvalds's avatar
Linus Torvalds committed
16

17
static __always_inline unsigned long __must_check
Al Viro's avatar
Al Viro committed
18
raw_copy_to_user(void __user *to, const void *from, unsigned long n)
Linus Torvalds's avatar
Linus Torvalds committed
19
{
Al Viro's avatar
Al Viro committed
20
	return __copy_user_ll((__force void *)to, from, n);
Linus Torvalds's avatar
Linus Torvalds committed
21
22
}

23
static __always_inline unsigned long
Al Viro's avatar
Al Viro committed
24
raw_copy_from_user(void *to, const void __user *from, unsigned long n)
25
{
Linus Torvalds's avatar
Linus Torvalds committed
26
27
28
29
30
	if (__builtin_constant_p(n)) {
		unsigned long ret;

		switch (n) {
		case 1:
Al Viro's avatar
Al Viro committed
31
			ret = 0;
32
			__uaccess_begin_nospec();
Al Viro's avatar
Al Viro committed
33
34
			__get_user_asm_nozero(*(u8 *)to, from, ret,
					      "b", "b", "=q", 1);
35
			__uaccess_end();
Linus Torvalds's avatar
Linus Torvalds committed
36
37
			return ret;
		case 2:
Al Viro's avatar
Al Viro committed
38
			ret = 0;
39
			__uaccess_begin_nospec();
Al Viro's avatar
Al Viro committed
40
41
			__get_user_asm_nozero(*(u16 *)to, from, ret,
					      "w", "w", "=r", 2);
42
			__uaccess_end();
Linus Torvalds's avatar
Linus Torvalds committed
43
44
			return ret;
		case 4:
Al Viro's avatar
Al Viro committed
45
			ret = 0;
46
			__uaccess_begin_nospec();
Al Viro's avatar
Al Viro committed
47
48
			__get_user_asm_nozero(*(u32 *)to, from, ret,
					      "l", "k", "=r", 4);
49
			__uaccess_end();
Linus Torvalds's avatar
Linus Torvalds committed
50
51
52
			return ret;
		}
	}
Al Viro's avatar
Al Viro committed
53
	return __copy_user_ll(to, (__force const void *)from, n);
Linus Torvalds's avatar
Linus Torvalds committed
54
55
}

56
static __always_inline unsigned long
57
58
__copy_from_user_inatomic_nocache(void *to, const void __user *from,
				  unsigned long n)
Linus Torvalds's avatar
Linus Torvalds committed
59
{
60
       return __copy_from_user_ll_nocache_nozero(to, from, n);
61
62
}

63
#endif /* _ASM_X86_UACCESS_32_H */