Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 21 Dec 2001 13:41:08 -0500 (EST)
From:      Daniel Eischen <eischen@pcnet1.pcnet.com>
To:        Bernd Walter <ticso@cicely9.cicely.de>
Cc:        Dan Eischen <eischen@vigrid.com>, Andrew Gallatin <gallatin@cs.duke.edu>, freebsd-alpha@FreeBSD.ORG
Subject:   Re: Munging jmp_bufs on alpha
Message-ID:  <Pine.SUN.3.91.1011221130251.12980B-100000@pcnet1.pcnet.com>
In-Reply-To: <20011221164636.GC97006@cicely9.cicely.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On Fri, 21 Dec 2001, Bernd Walter wrote:
> On Fri, Dec 21, 2001 at 10:47:25AM -0500, Dan Eischen wrote:
> > Bernd Walter wrote:
> > > 
> > > My first explanation was a bit wrong but nevertheless here are the
> > > patches for libc and Daniels testprogramm.
> > 
> > Hmm, as long as we're going to restore T12 with the return
> > address, shouldn't we just save and restore T12 in _setjmp
> > and _longjmp respectively?  And then let the threads library
> > put the return address in T12 like it already does?
> 
> _setjmp and _longjmp are functions and the caller should not expect
> any temporary register to keep it's contents after calling any function.
> There is no need to save/restore them.
> The point is with overwriting the return address to a function address
> _longjmp does not return but call a function without knowing it and
> a function caller needs to initialise t12 first.

OK, but by the same token, making _setjmp/_longjmp account for
libc_r's jmp_buf munging seems wrong too.  Playing the devil's
advocate, why should _longjmp stuff the return address into
a temporary register?  It seems more general to just save and
restore any necessary register, whether it's temporary or not.
T12 seems like it fits that category.

What is T12 suppose to contain in a normal function call?  Is
it always the return address?  Is that dependent on our compiler?

> > There's still something I don't understand.  With my patch,
> > why does R_RA (return address) need to be set in the jmp_buf?
> > In _longjmp, ra is loaded from where sc_pc is stored (jb[2]),
> > not from where ra is stored (jb[R_RA + 4]).  If you modify
> > the jmp_buf munging macro to zero jb[R_RA + 4] (like it
> > has done before), it doesn't work:
> > 
> >   #define SET_RETURN_ADDR_JB(jb, ra) do {       \
> >         (jb)[0]._jb[2] = (long)(ra);            \
> >         (jb)[0]._jb[R_RA + 4] = 0;              \
> >         (jb)[0]._jb[R_T12 + 4] = (long)(ra);    \
> > 
> > It seems like it should because jb[R_RA + 4] is not used
> > by _longjmp.
> 
> It works for me with my patch.
> You can even remove the RA and T12 line because they are never used.
> It should work with your patch too - I have no idea why it does not.

Yeah, I'm missing something too.

-- 
Dan Eischen

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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.SUN.3.91.1011221130251.12980B-100000>