我正在研究linux中的系统调用处理过程。
我发现当用户进程运行syscall指令来调用系统调用时,会调用entry_SYSCALL_64函数。
该函数保存中断帧。
但是,当它推送 ip 到中断帧时,它读取的不是 rip 而是 rcx。
此代码已在下面。
ENTRY(entry_SYSCALL_64)
UNWIND_HINT_EMPTY
/*
* Interrupts are off on entry.
* We do not frame this tiny irq-off block with TRACE_IRQS_OFF/ON,
* it is too small to ever cause noticeable irq latency.
*/
swapgs
/*
* This path is only taken when PAGE_TABLE_ISOLATION is disabled so it
* is not required to switch CR3.
*/
movq %rsp, PER_CPU_VAR(rsp_scratch)
movq PER_CPU_VAR(cpu_current_top_of_stack), %rsp
/* Construct struct pt_regs on stack */
pushq $__USER_DS /* pt_regs->ss */
pushq PER_CPU_VAR(rsp_scratch) /* pt_regs->sp */
pushq %r11 /* pt_regs->flags */
pushq $__USER_CS /* pt_regs->cs */
pushq %rcx /* pt_regs->ip ********************************** */
GLOBAL(entry_SYSCALL_64_after_hwframe)
pushq %rax /* pt_regs->orig_ax */
PUSH_AND_CLEAR_REGS rax=$-ENOSYS
TRACE_IRQS_OFF
/* IRQs are off. */
movq %rsp, %rdi
call do_syscall_64 /* returns with IRQs disabled */
....
我在重要的一行中输入了这么多“*”。
在注释中,它说它保存了ip寄存器,并且这个偏移量是正确的ip偏移量。
但是,它读取了 rcx...
有谁知道为什么吗?
最佳答案
因为the syscall
instruction在进入内核之前将syscall
后面的指令的地址存储到RCX中。
关于assembly - 为什么linux在entry_SYSCALL_64函数中从rcx寄存器读取ip寄存器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49358425/