From owner-freebsd-hackers Thu Jan 15 14:13:24 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id OAA16650 for hackers-outgoing; Thu, 15 Jan 1998 14:13:24 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from smtp01.primenet.com (smtp01.primenet.com [206.165.6.131]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id OAA16495 for ; Thu, 15 Jan 1998 14:12:00 -0800 (PST) (envelope-from tlambert@usr01.primenet.com) Received: (from daemon@localhost) by smtp01.primenet.com (8.8.8/8.8.8) id PAA19578; Thu, 15 Jan 1998 15:12:02 -0700 (MST) Received: from usr01.primenet.com(206.165.6.201) via SMTP by smtp01.primenet.com, id smtpd019554; Thu Jan 15 15:11:59 1998 Received: (from tlambert@localhost) by usr01.primenet.com (8.8.5/8.8.5) id PAA26217; Thu, 15 Jan 1998 15:11:53 -0700 (MST) From: Terry Lambert Message-Id: <199801152211.PAA26217@usr01.primenet.com> Subject: Re: Why no sys/setjmp.h? To: grog@lemis.com (Greg Lehey) Date: Thu, 15 Jan 1998 22:11:53 +0000 (GMT) Cc: hackers@FreeBSD.ORG In-Reply-To: <19980115144234.52624@lemis.com> from "Greg Lehey" at Jan 15, 98 02:42:34 pm X-Mailer: ELM [version 2.4 PL25] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk > 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.