From owner-freebsd-hackers Thu Jan 15 18:09:45 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id SAA11005 for hackers-outgoing; Thu, 15 Jan 1998 18:09:45 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from allegro.lemis.com (allegro.lemis.com [192.109.197.134]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id SAA10980 for ; Thu, 15 Jan 1998 18:09:14 -0800 (PST) (envelope-from grog@lemis.com) Received: from freebie.lemis.com (freebie.lemis.com [192.109.197.137]) by allegro.lemis.com (8.8.7/8.8.5) with ESMTP id MAA00931; Fri, 16 Jan 1998 12:39:05 +1030 (CST) Received: (from grog@localhost) by freebie.lemis.com (8.8.8/8.8.7) id MAA05296; Fri, 16 Jan 1998 12:39:04 +1030 (CST) (envelope-from grog) Message-ID: <19980116123904.45753@lemis.com> Date: Fri, 16 Jan 1998 12:39:04 +1030 From: Greg Lehey To: Terry Lambert Cc: hackers@FreeBSD.ORG Subject: Re: Why no sys/setjmp.h? References: <19980115144234.52624@lemis.com> <199801152211.PAA26217@usr01.primenet.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.84e In-Reply-To: <199801152211.PAA26217@usr01.primenet.com>; from Terry Lambert on Thu, Jan 15, 1998 at 10:11:53PM +0000 Organization: LEMIS, PO Box 460, Echunga SA 5153, Australia Phone: +61-8-8388-8286 Fax: +61-8-8388-8725 Mobile: +61-41-739-7062 WWW-Home-Page: http://www.lemis.com/~grog Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk On Thu, Jan 15, 1998 at 10:11:53PM +0000, Terry Lambert wrote: >> 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 fact, there's setjmp and longjmp too. They're there, alright. > In general, setjmp()/longjmp() prevent all sorts of optimizations > from being used. In the kernel? > 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. I can't see a way of using them in this environment. I'm in the top half of a driver, where things are more like in user space. > Finally, the purpose of these functions is to allow the throwing of > exceptions, and the kernel has it's own exception mechanisms. Which are? That was my question. > 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. So what are kernel setjmp and longjmp there for? Greg