1 /* SPDX-License-Identifier: GPL-2.0 */
3 * __get_user functions.
5 * (C) Copyright 1998 Linus Torvalds
6 * (C) Copyright 2005 Andi Kleen
7 * (C) Copyright 2008 Glauber Costa
9 * These functions have a non-standard call interface
10 * to make them more efficient, especially as they
11 * return an error value in addition to the "real"
18 * Inputs: %[r|e]ax contains the address.
20 * Outputs: %[r|e]ax is error code (0 or -EFAULT)
21 * %[r|e]dx contains zero-extended value
22 * %ecx contains the high half for 32-bit __get_user_8
25 * These functions should not modify any other registers,
26 * as they get called from within inline assembly.
29 #include <linux/linkage.h>
30 #include <asm/page_types.h>
31 #include <asm/errno.h>
32 #include <asm/asm-offsets.h>
33 #include <asm/thread_info.h>
36 #include <asm/export.h>
40 mov PER_CPU_VAR(current_task), %_ASM_DX
41 cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX
43 sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */
44 and %_ASM_DX, %_ASM_AX
46 1: movzbl (%_ASM_AX),%edx
51 EXPORT_SYMBOL(__get_user_1)
56 mov PER_CPU_VAR(current_task), %_ASM_DX
57 cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX
59 sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */
60 and %_ASM_DX, %_ASM_AX
62 2: movzwl -1(%_ASM_AX),%edx
67 EXPORT_SYMBOL(__get_user_2)
72 mov PER_CPU_VAR(current_task), %_ASM_DX
73 cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX
75 sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */
76 and %_ASM_DX, %_ASM_AX
78 3: movl -3(%_ASM_AX),%edx
83 EXPORT_SYMBOL(__get_user_4)
89 mov PER_CPU_VAR(current_task), %_ASM_DX
90 cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX
92 sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */
93 and %_ASM_DX, %_ASM_AX
95 4: movq -7(%_ASM_AX),%rdx
102 mov PER_CPU_VAR(current_task), %_ASM_DX
103 cmp TASK_addr_limit(%_ASM_DX),%_ASM_AX
105 sbb %_ASM_DX, %_ASM_DX /* array_index_mask_nospec() */
106 and %_ASM_DX, %_ASM_AX
108 4: movl -7(%_ASM_AX),%edx
109 5: movl -3(%_ASM_AX),%ecx
114 ENDPROC(__get_user_8)
115 EXPORT_SYMBOL(__get_user_8)
120 mov $(-EFAULT),%_ASM_AX
129 mov $(-EFAULT),%_ASM_AX
135 _ASM_EXTABLE(1b,bad_get_user)
136 _ASM_EXTABLE(2b,bad_get_user)
137 _ASM_EXTABLE(3b,bad_get_user)
139 _ASM_EXTABLE(4b,bad_get_user)
141 _ASM_EXTABLE(4b,bad_get_user_8)
142 _ASM_EXTABLE(5b,bad_get_user_8)