Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 295286a8 authored by Jan Beulich's avatar Jan Beulich Committed by Ingo Molnar
Browse files

x86-64: slightly stream-line 32-bit syscall entry code



Avoid updating registers or memory twice as well as needlessly loading
or copying registers.

Signed-off-by: default avatarJan Beulich <jbeulich@novell.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
parent 9f8305fe
Loading
Loading
Loading
Loading
+10 −16
Original line number Original line Diff line number Diff line
@@ -39,11 +39,11 @@
	.endm 
	.endm 


	/* clobbers %eax */	
	/* clobbers %eax */	
	.macro  CLEAR_RREGS
	.macro  CLEAR_RREGS _r9=rax
	xorl 	%eax,%eax
	xorl 	%eax,%eax
	movq	%rax,R11(%rsp)
	movq	%rax,R11(%rsp)
	movq	%rax,R10(%rsp)
	movq	%rax,R10(%rsp)
	movq	%rax,R9(%rsp)
	movq	%\_r9,R9(%rsp)
	movq	%rax,R8(%rsp)
	movq	%rax,R8(%rsp)
	.endm
	.endm


@@ -52,11 +52,10 @@
	 * We don't reload %eax because syscall_trace_enter() returned
	 * We don't reload %eax because syscall_trace_enter() returned
	 * the value it wants us to use in the table lookup.
	 * the value it wants us to use in the table lookup.
	 */
	 */
	.macro LOAD_ARGS32 offset
	.macro LOAD_ARGS32 offset, _r9=0
	movl \offset(%rsp),%r11d
	.if \_r9
	movl \offset+8(%rsp),%r10d
	movl \offset+16(%rsp),%r9d
	movl \offset+16(%rsp),%r9d
	movl \offset+24(%rsp),%r8d
	.endif
	movl \offset+40(%rsp),%ecx
	movl \offset+40(%rsp),%ecx
	movl \offset+48(%rsp),%edx
	movl \offset+48(%rsp),%edx
	movl \offset+56(%rsp),%esi
	movl \offset+56(%rsp),%esi
@@ -145,7 +144,7 @@ ENTRY(ia32_sysenter_target)
	SAVE_ARGS 0,0,1
	SAVE_ARGS 0,0,1
 	/* no need to do an access_ok check here because rbp has been
 	/* no need to do an access_ok check here because rbp has been
 	   32bit zero extended */ 
 	   32bit zero extended */ 
1:	movl	(%rbp),%r9d
1:	movl	(%rbp),%ebp
 	.section __ex_table,"a"
 	.section __ex_table,"a"
 	.quad 1b,ia32_badarg
 	.quad 1b,ia32_badarg
 	.previous	
 	.previous	
@@ -157,7 +156,7 @@ ENTRY(ia32_sysenter_target)
	cmpl	$(IA32_NR_syscalls-1),%eax
	cmpl	$(IA32_NR_syscalls-1),%eax
	ja	ia32_badsys
	ja	ia32_badsys
sysenter_do_call:
sysenter_do_call:
	IA32_ARG_FIXUP 1
	IA32_ARG_FIXUP
sysenter_dispatch:
sysenter_dispatch:
	call	*ia32_sys_call_table(,%rax,8)
	call	*ia32_sys_call_table(,%rax,8)
	movq	%rax,RAX-ARGOFFSET(%rsp)
	movq	%rax,RAX-ARGOFFSET(%rsp)
@@ -234,20 +233,17 @@ sysexit_audit:
#endif
#endif


sysenter_tracesys:
sysenter_tracesys:
	xchgl	%r9d,%ebp
#ifdef CONFIG_AUDITSYSCALL
#ifdef CONFIG_AUDITSYSCALL
	testl	$(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
	testl	$(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r10)
	jz	sysenter_auditsys
	jz	sysenter_auditsys
#endif
#endif
	SAVE_REST
	SAVE_REST
	CLEAR_RREGS
	CLEAR_RREGS
	movq	%r9,R9(%rsp)
	movq	$-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
	movq	$-ENOSYS,RAX(%rsp)/* ptrace can change this for a bad syscall */
	movq	%rsp,%rdi        /* &pt_regs -> arg1 */
	movq	%rsp,%rdi        /* &pt_regs -> arg1 */
	call	syscall_trace_enter
	call	syscall_trace_enter
	LOAD_ARGS32 ARGOFFSET  /* reload args from stack in case ptrace changed it */
	LOAD_ARGS32 ARGOFFSET  /* reload args from stack in case ptrace changed it */
	RESTORE_REST
	RESTORE_REST
	xchgl	%ebp,%r9d
	cmpl	$(IA32_NR_syscalls-1),%eax
	cmpl	$(IA32_NR_syscalls-1),%eax
	ja	int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
	ja	int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
	jmp	sysenter_do_call
	jmp	sysenter_do_call
@@ -314,9 +310,9 @@ ENTRY(ia32_cstar_target)
	testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
	testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r10)
	CFI_REMEMBER_STATE
	CFI_REMEMBER_STATE
	jnz   cstar_tracesys
	jnz   cstar_tracesys
cstar_do_call:	
	cmpl $IA32_NR_syscalls-1,%eax
	cmpl $IA32_NR_syscalls-1,%eax
	ja  ia32_badsys
	ja  ia32_badsys
cstar_do_call:
	IA32_ARG_FIXUP 1
	IA32_ARG_FIXUP 1
cstar_dispatch:
cstar_dispatch:
	call *ia32_sys_call_table(,%rax,8)
	call *ia32_sys_call_table(,%rax,8)
@@ -357,15 +353,13 @@ cstar_tracesys:
#endif
#endif
	xchgl %r9d,%ebp
	xchgl %r9d,%ebp
	SAVE_REST
	SAVE_REST
	CLEAR_RREGS
	CLEAR_RREGS r9
	movq %r9,R9(%rsp)
	movq $-ENOSYS,RAX(%rsp)	/* ptrace can change this for a bad syscall */
	movq $-ENOSYS,RAX(%rsp)	/* ptrace can change this for a bad syscall */
	movq %rsp,%rdi        /* &pt_regs -> arg1 */
	movq %rsp,%rdi        /* &pt_regs -> arg1 */
	call syscall_trace_enter
	call syscall_trace_enter
	LOAD_ARGS32 ARGOFFSET  /* reload args from stack in case ptrace changed it */
	LOAD_ARGS32 ARGOFFSET, 1  /* reload args from stack in case ptrace changed it */
	RESTORE_REST
	RESTORE_REST
	xchgl %ebp,%r9d
	xchgl %ebp,%r9d
	movl RSP-ARGOFFSET(%rsp), %r8d
	cmpl $(IA32_NR_syscalls-1),%eax
	cmpl $(IA32_NR_syscalls-1),%eax
	ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
	ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
	jmp cstar_do_call
	jmp cstar_do_call