ia32entry.s
来自「h内核」· S 代码 · 共 603 行 · 第 1/2 页
S
603 行
/* * Compatibility mode system call entry point for x86-64. * * Copyright 2000-2002 Andi Kleen, SuSE Labs. */ #include <asm/dwarf2.h>#include <asm/calling.h>#include <asm/offset.h>#include <asm/current.h>#include <asm/errno.h>#include <asm/ia32_unistd.h> #include <asm/thread_info.h> #include <asm/segment.h>#include <asm/vsyscall32.h>#include <linux/linkage.h> .macro IA32_ARG_FIXUP noebp=0 movl %edi,%r8d .if \noebp .else movl %ebp,%r9d .endif xchg %ecx,%esi movl %ebx,%edi movl %edx,%edx /* zero extension */ .endm /* clobbers %eax */ .macro CLEAR_RREGS xorl %eax,%eax movq %rax,R11(%rsp) movq %rax,R10(%rsp) movq %rax,R9(%rsp) movq %rax,R8(%rsp) .endm/* * 32bit SYSENTER instruction entry. * * Arguments: * %eax System call number. * %ebx Arg1 * %ecx Arg2 * %edx Arg3 * %esi Arg4 * %edi Arg5 * %ebp user stack * 0(%ebp) Arg6 * * Interrupts off. * * This is purely a fast path. For anything complicated we use the int 0x80 * path below. Set up a complete hardware stack frame to share code * with the int 0x80 path. */ ENTRY(ia32_sysenter_target) CFI_STARTPROC swapgs movq %gs:pda_kernelstack, %rsp addq $(PDA_STACKOFFSET),%rsp sti movl %ebp,%ebp /* zero extension */ pushq $__USER32_DS pushq %rbp pushfq movl $VSYSCALL32_SYSEXIT, %r10d pushq $__USER32_CS movl %eax, %eax pushq %r10 pushq %rax cld SAVE_ARGS 0,0,1 /* no need to do an access_ok check here because rbp has been 32bit zero extended */ 1: movl (%rbp),%r9d .section __ex_table,"a" .quad 1b,ia32_badarg .previous GET_THREAD_INFO(%r10) testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT),threadinfo_flags(%r10) jnz sysenter_tracesyssysenter_do_call: cmpl $(IA32_NR_syscalls),%eax jae ia32_badsys IA32_ARG_FIXUP 1 call *ia32_sys_call_table(,%rax,8) movq %rax,RAX-ARGOFFSET(%rsp) GET_THREAD_INFO(%r10) cli testl $_TIF_ALLWORK_MASK,threadinfo_flags(%r10) jnz int_ret_from_sys_call /* clear IF, that popfq doesn't enable interrupts early */ andl $~0x200,EFLAGS-R11(%rsp) RESTORE_ARGS 1,24,1,1,1,1 popfq popq %rcx /* User %esp */ movl $VSYSCALL32_SYSEXIT,%edx /* User %eip */ swapgs sti /* sti only takes effect after the next instruction */ /* sysexit */ .byte 0xf, 0x35sysenter_tracesys: SAVE_REST CLEAR_RREGS movq $-ENOSYS,RAX(%rsp) /* really needed? */ movq %rsp,%rdi /* &pt_regs -> arg1 */ call syscall_trace_enter LOAD_ARGS ARGOFFSET /* reload args from stack in case ptrace changed it */ RESTORE_REST movl %ebp, %ebp /* no need to do an access_ok check here because rbp has been 32bit zero extended */ 1: movl (%rbp),%r9d .section __ex_table,"a" .quad 1b,ia32_badarg .previous jmp sysenter_do_call CFI_ENDPROC/* * 32bit SYSCALL instruction entry. * * Arguments: * %eax System call number. * %ebx Arg1 * %ecx return EIP * %edx Arg3 * %esi Arg4 * %edi Arg5 * %ebp Arg2 [note: not saved in the stack frame, should not be touched] * %esp user stack * 0(%esp) Arg6 * * Interrupts off. * * This is purely a fast path. For anything complicated we use the int 0x80 * path below. Set up a complete hardware stack frame to share code * with the int 0x80 path. */ ENTRY(ia32_cstar_target) CFI_STARTPROC swapgs movl %esp,%r8d movq %gs:pda_kernelstack,%rsp sti SAVE_ARGS 8,1,1 movl %eax,%eax /* zero extension */ movq %rax,ORIG_RAX-ARGOFFSET(%rsp) movq %rcx,RIP-ARGOFFSET(%rsp) movq %rbp,RCX-ARGOFFSET(%rsp) /* this lies slightly to ptrace */ movl %ebp,%ecx movq $__USER32_CS,CS-ARGOFFSET(%rsp) movq $__USER32_DS,SS-ARGOFFSET(%rsp) movq %r11,EFLAGS-ARGOFFSET(%rsp) movq %r8,RSP-ARGOFFSET(%rsp) /* no need to do an access_ok check here because r8 has been 32bit zero extended */ /* hardware stack frame is complete now */ 1: movl (%r8),%r9d .section __ex_table,"a" .quad 1b,ia32_badarg .previous GET_THREAD_INFO(%r10) testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT),threadinfo_flags(%r10) jnz cstar_tracesyscstar_do_call: cmpl $IA32_NR_syscalls,%eax jae ia32_badsys IA32_ARG_FIXUP 1 call *ia32_sys_call_table(,%rax,8) movq %rax,RAX-ARGOFFSET(%rsp) GET_THREAD_INFO(%r10) cli testl $_TIF_ALLWORK_MASK,threadinfo_flags(%r10) jnz int_ret_from_sys_call RESTORE_ARGS 1,-ARG_SKIP,1,1,1 movl RIP-ARGOFFSET(%rsp),%ecx movl EFLAGS-ARGOFFSET(%rsp),%r11d movl RSP-ARGOFFSET(%rsp),%esp swapgs sysretl cstar_tracesys: SAVE_REST CLEAR_RREGS movq $-ENOSYS,RAX(%rsp) /* really needed? */ movq %rsp,%rdi /* &pt_regs -> arg1 */ call syscall_trace_enter LOAD_ARGS ARGOFFSET /* reload args from stack in case ptrace changed it */ RESTORE_REST movl RSP-ARGOFFSET(%rsp), %r8d /* no need to do an access_ok check here because r8 has been 32bit zero extended */ 1: movl (%r8),%r9d .section __ex_table,"a" .quad 1b,ia32_badarg .previous jmp cstar_do_call ia32_badarg: movq $-EFAULT,%rax jmp ia32_sysret CFI_ENDPROC/* * Emulated IA32 system calls via int 0x80. * * Arguments: * %eax System call number. * %ebx Arg1 * %ecx Arg2 * %edx Arg3 * %esi Arg4 * %edi Arg5 * %ebp Arg6 [note: not saved in the stack frame, should not be touched] * * Notes: * Uses the same stack frame as the x86-64 version. * All registers except %eax must be saved (but ptrace may violate that) * Arguments are zero extended. For system calls that want sign extension and * take long arguments a wrapper is needed. Most calls can just be called * directly. * Assumes it is only called from user space and entered with interrupts off. */ ENTRY(ia32_syscall) CFI_STARTPROC swapgs sti movl %eax,%eax pushq %rax cld /* note the registers are not zero extended to the sf. this could be a problem. */ SAVE_ARGS 0,0,1 GET_THREAD_INFO(%r10) testl $(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT),threadinfo_flags(%r10) jnz ia32_tracesysia32_do_syscall: cmpl $(IA32_NR_syscalls),%eax jae ia32_badsys IA32_ARG_FIXUP call *ia32_sys_call_table(,%rax,8) # xxx: rip relativeia32_sysret: movq %rax,RAX-ARGOFFSET(%rsp) jmp int_ret_from_sys_call ia32_tracesys: SAVE_REST movq $-ENOSYS,RAX(%rsp) /* really needed? */ movq %rsp,%rdi /* &pt_regs -> arg1 */ call syscall_trace_enter LOAD_ARGS ARGOFFSET /* reload args from stack in case ptrace changed it */ RESTORE_REST jmp ia32_do_syscallia32_badsys: movq $0,ORIG_RAX-ARGOFFSET(%rsp) movq $-ENOSYS,RAX-ARGOFFSET(%rsp) jmp int_ret_from_sys_callni_syscall: movq %rax,%rdi jmp sys32_ni_syscall quiet_ni_syscall: movq $-ENOSYS,%rax ret CFI_ENDPROC .macro PTREGSCALL label, func, arg .globl \label\label: leaq \func(%rip),%rax leaq -ARGOFFSET+8(%rsp),\arg /* 8 for return address */ jmp ia32_ptregs_common .endm PTREGSCALL stub32_rt_sigreturn, sys32_rt_sigreturn, %rdi PTREGSCALL stub32_sigreturn, sys32_sigreturn, %rdi PTREGSCALL stub32_sigaltstack, sys32_sigaltstack, %rdx PTREGSCALL stub32_sigsuspend, sys32_sigsuspend, %rcx PTREGSCALL stub32_execve, sys32_execve, %rcx PTREGSCALL stub32_fork, sys_fork, %rdi PTREGSCALL stub32_clone, sys32_clone, %rdx PTREGSCALL stub32_vfork, sys_vfork, %rdi PTREGSCALL stub32_iopl, sys_iopl, %rsi PTREGSCALL stub32_rt_sigsuspend, sys_rt_sigsuspend, %rdxENTRY(ia32_ptregs_common) CFI_STARTPROC popq %r11 SAVE_REST call *%rax RESTORE_REST jmp ia32_sysret /* misbalances the return cache */ CFI_ENDPROC .data .align 8
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?