1/* SPDX-License-Identifier: GPL-2.0 */ 2/* 3 * __put_user functions. 4 * 5 * (C) Copyright 2005 Linus Torvalds 6 * (C) Copyright 2005 Andi Kleen 7 * (C) Copyright 2008 Glauber Costa 8 * 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" 12 * return value. 13 */ 14#include <linux/linkage.h> 15#include <asm/thread_info.h> 16#include <asm/errno.h> 17#include <asm/asm.h> 18#include <asm/smap.h> 19#include <asm/export.h> 20 21 22/* 23 * __put_user_X 24 * 25 * Inputs: %eax[:%edx] contains the data 26 * %ecx contains the address 27 * 28 * Outputs: %eax is error code (0 or -EFAULT) 29 * 30 * These functions should not modify any other registers, 31 * as they get called from within inline assembly. 32 */ 33 34#define ENTER mov PER_CPU_VAR(current_task), %_ASM_BX 35#define EXIT ASM_CLAC ; \ 36 ret 37 38.text 39ENTRY(__put_user_1) 40 ENTER 41 cmp TASK_addr_limit(%_ASM_BX),%_ASM_CX 42 jae bad_put_user 43 ASM_STAC 441: movb %al,(%_ASM_CX) 45 xor %eax,%eax 46 EXIT 47ENDPROC(__put_user_1) 48EXPORT_SYMBOL(__put_user_1) 49 50ENTRY(__put_user_2) 51 ENTER 52 mov TASK_addr_limit(%_ASM_BX),%_ASM_BX 53 sub $1,%_ASM_BX 54 cmp %_ASM_BX,%_ASM_CX 55 jae bad_put_user 56 ASM_STAC 572: movw %ax,(%_ASM_CX) 58 xor %eax,%eax 59 EXIT 60ENDPROC(__put_user_2) 61EXPORT_SYMBOL(__put_user_2) 62 63ENTRY(__put_user_4) 64 ENTER 65 mov TASK_addr_limit(%_ASM_BX),%_ASM_BX 66 sub $3,%_ASM_BX 67 cmp %_ASM_BX,%_ASM_CX 68 jae bad_put_user 69 ASM_STAC 703: movl %eax,(%_ASM_CX) 71 xor %eax,%eax 72 EXIT 73ENDPROC(__put_user_4) 74EXPORT_SYMBOL(__put_user_4) 75 76ENTRY(__put_user_8) 77 ENTER 78 mov TASK_addr_limit(%_ASM_BX),%_ASM_BX 79 sub $7,%_ASM_BX 80 cmp %_ASM_BX,%_ASM_CX 81 jae bad_put_user 82 ASM_STAC 834: mov %_ASM_AX,(%_ASM_CX) 84#ifdef CONFIG_X86_32 855: movl %edx,4(%_ASM_CX) 86#endif 87 xor %eax,%eax 88 EXIT 89ENDPROC(__put_user_8) 90EXPORT_SYMBOL(__put_user_8) 91 92bad_put_user: 93 movl $-EFAULT,%eax 94 EXIT 95END(bad_put_user) 96 97 _ASM_EXTABLE(1b,bad_put_user) 98 _ASM_EXTABLE(2b,bad_put_user) 99 _ASM_EXTABLE(3b,bad_put_user) 100 _ASM_EXTABLE(4b,bad_put_user) 101#ifdef CONFIG_X86_32 102 _ASM_EXTABLE(5b,bad_put_user) 103#endif 104