linux-user: Fix syscall instruction usermode emulation on X86_64
PATCH 1/1 linux-user: Fix syscall instruction usermode emulation on X86_64
Currently syscall instruction is buggy on user mode X86_64, the EIP is updated after do_syscall(), that is too late for clone(). Because clone() will create a thread at the env->EIP (the address of syscall insn), and then child thread enters do_syscall() again, that is not expected. Sometimes it is tragic.
User mode syscall insn emulation is not used MSR, so the action should be same to INT 0x80. INT 0x80 will update EIP in do_interrupt(), ditto for syscall() for consistency.
--- linux-user/main.c | 1 - target-i386/seg_helper.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-)
linux-user/main.c +0 -1
@@ -309,7 +309,6 @@ void cpu_loop(CPUX86State *env) env->regs[8 ], env->regs[9 ], 0, 0); - env->eip = env->exception_next_eip;break ;#endif case EXCP0B_NOSEG :
target-i386/seg_helper.c +2 -2
@@ -1127,8 +1127,8 @@ static void do_interrupt_user(CPUX86State *env, int intno, int is_int,/* Since we emulate only user space, we cannot do more than exiting the emulation with the suitable exception and error -code */ -if (is_int) { +code. So update EIP for INT 0x80 and EXCP_SYSCALL. */ +if (is_int || intno ==EXCP_SYSCALL ) { env->eip = next_eip; } }
Signature · 1 line
1.7.1
Quoted 10 lines · Jincheng Miao
Currently syscall instruction is buggy on user mode
X86_64, the EIP is updated afterdo_syscall(), that is too late forclone(). Becauseclone()will create a thread at theenv->EIP(the address of syscall insn), and then child thread entersdo_syscall()again, that is not expected. Sometimes it is tragic.User mode syscall insn emulation is not used MSR, so the action should be same to INT
0x80. INT0x80will update EIP indo_interrupt(), ditto forsyscall()for consistency.
Quoted 5 lines
Signed-off-by Jincheng Miao <[email protected]>--- linux-user/main.c | 1 - target-i386/seg_helper.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-)
r~
Riku Voipio
AppliedQuoted 9 lines · Jincheng Miao
Currently syscall instruction is buggy on user mode
X86_64, the EIP is updated afterdo_syscall(), that is too late forclone(). Becauseclone()will create a thread at theenv->EIP(the address of syscall insn), and then child thread entersdo_syscall()again, that is not expected. Sometimes it is tragic.User mode syscall insn emulation is not used MSR, so the action should be same to INT
0x80. INT0x80will update EIP indo_interrupt(), ditto forsyscall()for consistency.
Thanks applied to linux-user tree for next pull request.
Riku
Quoted 36 lines
Signed-off-by Jincheng Miao <[email protected]>--- linux-user/main.c | 1 - target-i386/seg_helper.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-)linux-user/main.c +0
-1@@ -309,7 +309,6 @@ void cpu_loop(CPUX86State *env) env->regs[8 ], env->regs[9 ], 0, 0); - env->eip = env->exception_next_eip;break ;#endif case EXCP0B_NOSEG :target-i386/seg_helper.c +2
-2@@ -1127,8 +1127,8 @@ static void do_interrupt_user(CPUX86State *env, int intno, int is_int,/* Since we emulate only user space, we cannot do more than exiting the emulation with the suitable exception and error -code */ -if (is_int) { +code. So update EIP for INT 0x80 and EXCP_SYSCALL. */ +if (is_int || intno ==EXCP_SYSCALL ) { env->eip = next_eip; } }Signature · 1 line
1.7.1