我注意到,在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
不用于返回用户空间。那么,为什么从iret
返回时必须使用exec
? 最佳答案
此函数用于修改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/