gpt4 book ai didi

c - 从 exec 系统调用返回时使用 iret

转载 作者:太空宇宙 更新时间:2023-11-04 10:11:19 25 4
gpt4 key购买 nike

我注意到在 start_thread 函数的末尾,它是在 exec 的大部分工作完成后调用的,调用了 force_iret :

    static void
start_thread_common(struct pt_regs *regs, unsigned long new_ip,
unsigned long new_sp,
unsigned int _cs, unsigned int _ss, unsigned int _ds)
{
loadsegment(fs, 0);
loadsegment(es, _ds);
loadsegment(ds, _ds);
load_gs_index(0);
regs->ip = new_ip;
regs->sp = new_sp;
regs->cs = _cs;
regs->ss = _ss;
regs->flags = X86_EFLAGS_IF;
force_iret();
}

我认为这样做是为了确保 sysexit 不会被用来返回到用户空间。那么为什么从exec返回时必须使用iret呢?

最佳答案

此函数修改 sysret/sysexit 不会恢复的寄存器。

这是arch/x86/include/asm/thread_info.h:

/*
* Force syscall return via IRET by making it look as if there was
* some work pending. IRET is our most capable (but slowest) syscall
* return path, which is able to restore modified SS, CS and certain
* EFLAGS values that other (fast) syscall return instructions
* are not able to restore properly.
*/
#define force_iret() set_thread_flag(TIF_NOTIFY_RESUME)

关于c - 从 exec 系统调用返回时使用 iret,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48934120/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com