为什么 linux 在 entry_SYSCALL_64 函数中从 rcx 寄存器读取 ip 寄存器?
Why the linux read ip register from rcx register in the entry_SYSCALL_64 function?
我正在研究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寄存器,这个offset是ip的正确偏移量
但是,它读取 rcx....
有人知道为什么吗?
因为the syscall
instruction在进入内核前将syscall
后面的指令地址存入RCX
我正在研究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寄存器,这个offset是ip的正确偏移量
但是,它读取 rcx....
有人知道为什么吗?
因为the syscall
instruction在进入内核前将syscall
后面的指令地址存入RCX