Linux Audio

Check our new training course

Loading...
v4.10.11
 
  1/*
  2 * __put_user functions.
  3 *
  4 * (C) Copyright 2005 Linus Torvalds
  5 * (C) Copyright 2005 Andi Kleen
  6 * (C) Copyright 2008 Glauber Costa
  7 *
  8 * These functions have a non-standard call interface
  9 * to make them more efficient, especially as they
 10 * return an error value in addition to the "real"
 11 * return value.
 12 */
 13#include <linux/linkage.h>
 14#include <asm/thread_info.h>
 15#include <asm/errno.h>
 16#include <asm/asm.h>
 17#include <asm/smap.h>
 18#include <asm/export.h>
 19
 20
 21/*
 22 * __put_user_X
 23 *
 24 * Inputs:	%eax[:%edx] contains the data
 25 *		%ecx contains the address
 26 *
 27 * Outputs:	%eax is error code (0 or -EFAULT)
 
 
 28 *
 29 * These functions should not modify any other registers,
 30 * as they get called from within inline assembly.
 31 */
 32
 33#define ENTER	mov PER_CPU_VAR(current_task), %_ASM_BX
 34#define EXIT	ASM_CLAC ;	\
 35		ret
 
 
 
 
 
 36
 37.text
 38ENTRY(__put_user_1)
 39	ENTER
 40	cmp TASK_addr_limit(%_ASM_BX),%_ASM_CX
 41	jae bad_put_user
 
 42	ASM_STAC
 431:	movb %al,(%_ASM_CX)
 44	xor %eax,%eax
 45	EXIT
 46ENDPROC(__put_user_1)
 
 47EXPORT_SYMBOL(__put_user_1)
 
 48
 49ENTRY(__put_user_2)
 50	ENTER
 51	mov TASK_addr_limit(%_ASM_BX),%_ASM_BX
 52	sub $1,%_ASM_BX
 53	cmp %_ASM_BX,%_ASM_CX
 54	jae bad_put_user
 
 55	ASM_STAC
 562:	movw %ax,(%_ASM_CX)
 57	xor %eax,%eax
 58	EXIT
 59ENDPROC(__put_user_2)
 
 60EXPORT_SYMBOL(__put_user_2)
 
 61
 62ENTRY(__put_user_4)
 63	ENTER
 64	mov TASK_addr_limit(%_ASM_BX),%_ASM_BX
 65	sub $3,%_ASM_BX
 66	cmp %_ASM_BX,%_ASM_CX
 67	jae bad_put_user
 
 68	ASM_STAC
 693:	movl %eax,(%_ASM_CX)
 70	xor %eax,%eax
 71	EXIT
 72ENDPROC(__put_user_4)
 
 73EXPORT_SYMBOL(__put_user_4)
 
 74
 75ENTRY(__put_user_8)
 76	ENTER
 77	mov TASK_addr_limit(%_ASM_BX),%_ASM_BX
 78	sub $7,%_ASM_BX
 79	cmp %_ASM_BX,%_ASM_CX
 80	jae bad_put_user
 
 81	ASM_STAC
 824:	mov %_ASM_AX,(%_ASM_CX)
 83#ifdef CONFIG_X86_32
 845:	movl %edx,4(%_ASM_CX)
 85#endif
 86	xor %eax,%eax
 87	EXIT
 88ENDPROC(__put_user_8)
 
 89EXPORT_SYMBOL(__put_user_8)
 
 90
 91bad_put_user:
 92	movl $-EFAULT,%eax
 93	EXIT
 94END(bad_put_user)
 95
 96	_ASM_EXTABLE(1b,bad_put_user)
 97	_ASM_EXTABLE(2b,bad_put_user)
 98	_ASM_EXTABLE(3b,bad_put_user)
 99	_ASM_EXTABLE(4b,bad_put_user)
 
 
100#ifdef CONFIG_X86_32
101	_ASM_EXTABLE(5b,bad_put_user)
102#endif
v5.14.15
  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:	%ecx is error code (0 or -EFAULT)
 29 *
 30 * Clobbers:	%ebx needed for task pointer
 31 *
 32 * These functions should not modify any other registers,
 33 * as they get called from within inline assembly.
 34 */
 35
 36#ifdef CONFIG_X86_5LEVEL
 37#define LOAD_TASK_SIZE_MINUS_N(n) \
 38	ALTERNATIVE __stringify(mov $((1 << 47) - 4096 - (n)),%rbx), \
 39		    __stringify(mov $((1 << 56) - 4096 - (n)),%rbx), X86_FEATURE_LA57
 40#else
 41#define LOAD_TASK_SIZE_MINUS_N(n) \
 42	mov $(TASK_SIZE_MAX - (n)),%_ASM_BX
 43#endif
 44
 45.text
 46SYM_FUNC_START(__put_user_1)
 47	LOAD_TASK_SIZE_MINUS_N(0)
 48	cmp %_ASM_BX,%_ASM_CX
 49	jae .Lbad_put_user
 50SYM_INNER_LABEL(__put_user_nocheck_1, SYM_L_GLOBAL)
 51	ASM_STAC
 521:	movb %al,(%_ASM_CX)
 53	xor %ecx,%ecx
 54	ASM_CLAC
 55	ret
 56SYM_FUNC_END(__put_user_1)
 57EXPORT_SYMBOL(__put_user_1)
 58EXPORT_SYMBOL(__put_user_nocheck_1)
 59
 60SYM_FUNC_START(__put_user_2)
 61	LOAD_TASK_SIZE_MINUS_N(1)
 
 
 62	cmp %_ASM_BX,%_ASM_CX
 63	jae .Lbad_put_user
 64SYM_INNER_LABEL(__put_user_nocheck_2, SYM_L_GLOBAL)
 65	ASM_STAC
 662:	movw %ax,(%_ASM_CX)
 67	xor %ecx,%ecx
 68	ASM_CLAC
 69	ret
 70SYM_FUNC_END(__put_user_2)
 71EXPORT_SYMBOL(__put_user_2)
 72EXPORT_SYMBOL(__put_user_nocheck_2)
 73
 74SYM_FUNC_START(__put_user_4)
 75	LOAD_TASK_SIZE_MINUS_N(3)
 
 
 76	cmp %_ASM_BX,%_ASM_CX
 77	jae .Lbad_put_user
 78SYM_INNER_LABEL(__put_user_nocheck_4, SYM_L_GLOBAL)
 79	ASM_STAC
 803:	movl %eax,(%_ASM_CX)
 81	xor %ecx,%ecx
 82	ASM_CLAC
 83	ret
 84SYM_FUNC_END(__put_user_4)
 85EXPORT_SYMBOL(__put_user_4)
 86EXPORT_SYMBOL(__put_user_nocheck_4)
 87
 88SYM_FUNC_START(__put_user_8)
 89	LOAD_TASK_SIZE_MINUS_N(7)
 
 
 90	cmp %_ASM_BX,%_ASM_CX
 91	jae .Lbad_put_user
 92SYM_INNER_LABEL(__put_user_nocheck_8, SYM_L_GLOBAL)
 93	ASM_STAC
 944:	mov %_ASM_AX,(%_ASM_CX)
 95#ifdef CONFIG_X86_32
 965:	movl %edx,4(%_ASM_CX)
 97#endif
 98	xor %ecx,%ecx
 99	ASM_CLAC
100	RET
101SYM_FUNC_END(__put_user_8)
102EXPORT_SYMBOL(__put_user_8)
103EXPORT_SYMBOL(__put_user_nocheck_8)
104
105SYM_CODE_START_LOCAL(.Lbad_put_user_clac)
106	ASM_CLAC
107.Lbad_put_user:
108	movl $-EFAULT,%ecx
109	RET
110SYM_CODE_END(.Lbad_put_user_clac)
111
112	_ASM_EXTABLE_UA(1b, .Lbad_put_user_clac)
113	_ASM_EXTABLE_UA(2b, .Lbad_put_user_clac)
114	_ASM_EXTABLE_UA(3b, .Lbad_put_user_clac)
115	_ASM_EXTABLE_UA(4b, .Lbad_put_user_clac)
116#ifdef CONFIG_X86_32
117	_ASM_EXTABLE_UA(5b, .Lbad_put_user_clac)
118#endif