Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 15 Jan 1998 22:11:53 +0000 (GMT)
From:      Terry Lambert <tlambert@primenet.com>
To:        grog@lemis.com (Greg Lehey)
Cc:        hackers@FreeBSD.ORG
Subject:   Re: Why no sys/setjmp.h?
Message-ID:  <199801152211.PAA26217@usr01.primenet.com>
In-Reply-To: <19980115144234.52624@lemis.com> from "Greg Lehey" at Jan 15, 98 02:42:34 pm

next in thread | previous in thread | raw e-mail | index | archive | help
> I'm just writing kernel code which uses setjmp and longjmp, and I
> discover that there are no header files with declarations of these
> functions.  How come?  Are they deprecated in the kernel?  Should I be
> using something else instead?

The setjmp() call says "save my stack, reigster set, and signal mask
at this point" and the longjmp() rewinds the information, except that
the return value of the setjmp() is expected to be zero when it
returns, and the longjmp() is non-zero when it returns for setjmp().

Forget that there's no signal mask in the kernel.  8-).  There's always
_setjmp()/_longjmp()...

In general, setjmp()/longjmp() prevent all sorts of optimizations
from being used.

There are also problems because of kernel stacks.  If I tsleep()
in a driver, I'm not guaranteed to be on the same stack un some
particular situations, etc..  It would be easy to introduce
errors if you do a lot of stack unwinding.

Finally, the purpose of these functions is to allow the throwing of
exceptions, and the kernel has it's own exception mechanisms.

Technically, you could write your own setjmp/longjmp, use them, and
if you were careful, not screw up.  But it makes debugging and other
tasks so difficult for so little gain (in an already difficult place,
unless you have two machines and use a source debugger) that it's
probably better to use a different approach.


					Terry Lambert
					terry@lambert.org
---
Any opinions in this posting are my own and not those of my present
or previous employers.



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