簡體   English   中英

從exec系統調用返回時使用iret

[英]Use of iret when returning from exec system call

我注意到在exec大部分工作完成后調用的start_thread函數的末尾,有一個對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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM