Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 29 Oct 2001 11:50:58 -0800 (PST)
From:      John Baldwin <jhb@FreeBSD.org>
To:        Jake Burkholder <jake@locore.ca>
Cc:        arch@FreeBSD.ORG
Subject:   Re: syscall() ABI questions
Message-ID:  <XFMail.011029115058.jhb@FreeBSD.org>
In-Reply-To: <20011029143153.B14748@locore.ca>

next in thread | previous in thread | raw e-mail | index | archive | help

On 29-Oct-01 Jake Burkholder wrote:
> Apparently, On Mon, Oct 29, 2001 at 02:16:37AM -0800,
>       John Baldwin said words to the effect of;
> 
>> I've got some questions about td->td_retval[1] and our syscall ABI.  On some
>> archs (ia64, alpha) we preinitialie this value to 0.  On other archs (i386,
>> sparc64, ppc) we set it to the value of the register it will be set to so
>> that
>> effectively this register's value is preserved across the syscall.  My
>> question
>> is do our syscall ABI's actually assume that for syscalls with only one
>> return
>> value that register isn't written to?  NetBSD recently changed their i386
>> syscall code to preinitialize to 0 rather than %edx.  Anyone have the
>> history
>> on this?
>> 
>> Speaking of i386, I have another question.  For the fork, vfork, and rfork
>> syscalls, we have custom handlers that call the syscall normally and then
>> explicitly zero the return value if %edx is 1 (i.e., the child).  However,
>> in
>> vm_fork(), we already explicitly set the value in %eax to 0 for child
>> processes, so is this extra setting of that value in libc really needed?  If
>> not, we can safely get rid of rfork.S, vfork.S, and fork.S in libc I think.
> 
> The thing to watch for is that the system call wrappers don't follow
> the same conventions for call-safe registers.  At least on i386 vfork
> stashes the return address in %ecx and expects it not to be clobbered
> by the kernel.  I think all the warppers that do this use %ecx (not %edx)
> and its the same on sparc64, %o0 and %o1 are assumed to be clobbered
> but other otherwise non-call safe registers are assumed to be preserved.
> So it should be ok to always clobber retval[1] by setting it to zero.
> 
> I think you're right about fork and rfork being able to use the MIASM
> code.  rfork with RFMEM is special but it can';t be safely called from
> C anyway.  The vfork wrapper needs to stay on x86 at least because both
> processes return to the same stack; if the retunr address is not saved in
> a register the child may clobber the parent's when it "rets" and pops
> the stack.

Same kernel stack?  The register is set in the trapframe which means it is
saved on the kernel stack.   Is that shared in the vfork case?

-- 

John Baldwin <jhb@FreeBSD.org> -- http://www.FreeBSD.org/~jhb/
PGP Key: http://www.baldwin.cx/~john/pgpkey.asc
"Power Users Use the Power to Serve!"  -  http://www.FreeBSD.org/

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-arch" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?XFMail.011029115058.jhb>