Index: sys/amd64/amd64/machdep.c =================================================================== --- sys/amd64/amd64/machdep.c +++ sys/amd64/amd64/machdep.c @@ -604,7 +604,6 @@ regs->tf_fs = _ufssel; regs->tf_gs = _ugssel; regs->tf_flags = TF_HASSEGS; - td->td_retval[1] = 0; /* * Reset the hardware debug registers if they were in use. Index: sys/amd64/ia32/ia32_signal.c =================================================================== --- sys/amd64/ia32/ia32_signal.c +++ sys/amd64/ia32/ia32_signal.c @@ -967,5 +967,4 @@ /* Return via doreti so that we can change to a different %cs */ set_pcb_flags(pcb, PCB_32BIT | PCB_FULL_IRET); - td->td_retval[1] = 0; } Index: sys/arm/cloudabi32/cloudabi32_sysvec.c =================================================================== --- sys/arm/cloudabi32/cloudabi32_sysvec.c +++ sys/arm/cloudabi32/cloudabi32_sysvec.c @@ -61,7 +61,7 @@ * tpidrurw to the TCB. */ regs = td->td_frame; - regs->tf_r0 = td->td_retval[0] = + regs->tf_r0 = stack + roundup(sizeof(cloudabi32_tcb_t), sizeof(register_t)); (void)cpu_set_user_tls(td, (void *)stack); } Index: sys/arm64/arm64/machdep.c =================================================================== --- sys/arm64/arm64/machdep.c +++ sys/arm64/arm64/machdep.c @@ -310,12 +310,7 @@ memset(tf, 0, sizeof(struct trapframe)); - /* - * We need to set x0 for init as it doesn't call - * cpu_set_syscall_retval to copy the value. We also - * need to set td_retval for the cases where we do. - */ - tf->tf_x[0] = td->td_retval[0] = stack; + tf->tf_x[0] = stack; tf->tf_sp = STACKALIGN(stack); tf->tf_lr = imgp->entry_addr; tf->tf_elr = imgp->entry_addr; Index: sys/arm64/cloudabi64/cloudabi64_sysvec.c =================================================================== --- sys/arm64/cloudabi64/cloudabi64_sysvec.c +++ sys/arm64/cloudabi64/cloudabi64_sysvec.c @@ -61,7 +61,7 @@ * tpidr_el0 to the TCB. */ regs = td->td_frame; - regs->tf_x[0] = td->td_retval[0] = + regs->tf_x[0] = stack + roundup(sizeof(cloudabi64_tcb_t), sizeof(register_t)); (void)cpu_set_user_tls(td, (void *)stack); } Index: sys/compat/linux/linux_emul.c =================================================================== --- sys/compat/linux/linux_emul.c +++ sys/compat/linux/linux_emul.c @@ -186,7 +186,7 @@ error = kern_execve(td, eargs, NULL); post_execve(td, error, oldvmspace); - if (error != 0) + if (error != EJUSTRETURN) return (error); /* @@ -213,7 +213,7 @@ free(em, M_TEMP); free(pem, M_LINUX); } - return (0); + return (EJUSTRETURN); } void Index: sys/i386/i386/machdep.c =================================================================== --- sys/i386/i386/machdep.c +++ sys/i386/i386/machdep.c @@ -1126,6 +1126,7 @@ set_fsbase(td, 0); set_gsbase(td, 0); + /* Make sure edx is 0x0 on entry. Linux binaries depend on it. */ bzero((char *)regs, sizeof(struct trapframe)); regs->tf_eip = imgp->entry_addr; regs->tf_esp = stack; @@ -1168,13 +1169,6 @@ * clean FP state if it uses the FPU again. */ fpstate_drop(td); - - /* - * XXX - Linux emulator - * Make sure sure edx is 0x0 on entry. Linux binaries depend - * on it. - */ - td->td_retval[1] = 0; } void Index: sys/kern/init_main.c =================================================================== --- sys/kern/init_main.c +++ sys/kern/init_main.c @@ -797,7 +797,7 @@ * Otherwise, return via fork_trampoline() all the way * to user mode as init! */ - if ((error = sys_execve(td, &args)) == 0) { + if ((error = sys_execve(td, &args)) == EJUSTRETURN) { mtx_unlock(&Giant); return; } Index: sys/kern/kern_exec.c =================================================================== --- sys/kern/kern_exec.c +++ sys/kern/kern_exec.c @@ -318,7 +318,7 @@ * If success, we upgrade to SINGLE_EXIT state to * force other threads to suicide. */ - if (error == 0) + if (error == EJUSTRETURN) thread_single(p, SINGLE_EXIT); else thread_single_end(p, SINGLE_BOUNDARY); @@ -962,7 +962,7 @@ ktrprocctor(p); #endif - return (error); + return (error == 0 ? EJUSTRETURN : error); } int Index: sys/powerpc/powerpc/exec_machdep.c =================================================================== --- sys/powerpc/powerpc/exec_machdep.c +++ sys/powerpc/powerpc/exec_machdep.c @@ -520,22 +520,11 @@ * - ps_strings is a NetBSD extention, and will be * ignored by executables which are strictly * compliant with the SVR4 ABI. - * - * XXX We have to set both regs and retval here due to different - * XXX calling convention in trap.c and init_main.c. */ /* Collect argc from the user stack */ argc = fuword((void *)stack); - /* - * XXX PG: these get overwritten in the syscall return code. - * execve() should return EJUSTRETURN, like it does on NetBSD. - * Emulate by setting the syscall return value cells. The - * registers still have to be set for init's fork trampoline. - */ - td->td_retval[0] = argc; - td->td_retval[1] = stack + sizeof(register_t); tf->fixreg[3] = argc; tf->fixreg[4] = stack + sizeof(register_t); tf->fixreg[5] = stack + (2 + argc)*sizeof(register_t); @@ -572,8 +561,6 @@ argc = fuword32((void *)stack); - td->td_retval[0] = argc; - td->td_retval[1] = stack + sizeof(uint32_t); tf->fixreg[3] = argc; tf->fixreg[4] = stack + sizeof(uint32_t); tf->fixreg[5] = stack + (2 + argc)*sizeof(uint32_t); Index: sys/riscv/riscv/machdep.c =================================================================== --- sys/riscv/riscv/machdep.c +++ sys/riscv/riscv/machdep.c @@ -279,12 +279,7 @@ memset(tf, 0, sizeof(struct trapframe)); - /* - * We need to set a0 for init as it doesn't call - * cpu_set_syscall_retval to copy the value. We also - * need to set td_retval for the cases where we do. - */ - tf->tf_a[0] = td->td_retval[0] = stack; + tf->tf_a[0] = stack; tf->tf_sp = STACKALIGN(stack); tf->tf_ra = imgp->entry_addr; tf->tf_sepc = imgp->entry_addr;