Bug iwith setjmp/longjmp on Vax

jim at ISM780B.UUCP jim at ISM780B.UUCP
Sat Jun 8 08:45:00 AEST 1985


"Forward, into the past!" -- Firesign Theatre

If you longjmp into a routine that has already returned, just where do you
expect to be?  There is such a thing as stack discipline.
The routine that calls setjmp must be an ancestor of (or equal to, which
is broken on some implementations, such as pdp11 SysIII) the routine that
calls longjmp.  foo is not an ancestor of main.

The VAX 4.2BSD version is correct; it backtraces the stack so the register
variables are restored properly.  The Sun version is, technically,
incorrect; it saves the registers and sp in setjmp and simply restores
them in longjmp.  For details of why this is wrong, refer to the archives;
this has been discussed to death.  For details of why a correct implementation
appears too costly (extra overhead on every call), see same.  Also discussed
there was the simple, clever technique used by the Amsterdam Compiler Kit,
namely any routine that calls a routine called "setjmp" doesn't use register
variables; this doesn't work only if you call setjmp indirectly, which is
a rather bizarre and foolish thing to do.

-- Jim Balter, INTERACTIVE Systems (ima!jim)



More information about the Comp.unix.wizards mailing list