Article View: comp.std.c
Article #4466Re: Can longjmp modify errno?
From: Chris Torek
Date: Thu, 14 Dec 1995 07:48
Date: Thu, 14 Dec 1995 07:48
41 lines
2350 bytes
2350 bytes
I think it is fairly clear that longjmp cannot modify the object that contains the value that was most recently observed (or set) through the `errno' accessor (identifier, function call with indirection, or whatever). Unfortunately, it is possible, and maybe even ever-so-slightly sensible, for `errno' to refer to a *different* object on return from longjmp. For instance, suppose a compiler elects to put an `errno' in each activation record (function call stack frame) and to define `errno' as `the current frame's errno', e.g., #define errno (__builtin_upframe(0)->__errno) C library functions that set errno would use a different define, such as: #define callers_errno (__builtin_upframe(1)->__errno) or similar magic to make errors they set visible to their caller. A compiler that did this would automatically provide `thread-safe' errno's, because each thread runs on a different stack; moreover, signal handlers that clobber errno would not destroy the signalled function's copy. (I believe this particular excuse for doing something so complicated is not a good one, but merely present it as a possiblity.) Now, in such an implementation, when longjmp unwinds the stack to the corresponding setjmp, one side effect is that errno will again refer to the __errno in the frame of the function that called setjmp, rather than that in the one of the function that called longjmp. I never would have thought of this on my own, but it does seem as though one must copy `errno' to a static-duration variable of one's own before calling longjmp, if one wishes to preserve it. (One is sometimes fascinated by the way English sentences turn out when one is avoiding the second person, or in this case, the first person. :-) ) -- In-Real-Life: Chris Torek, Berkeley Software Design Inc El Cerrito, CA Domain: torek@bsdi.com +1 510 234 3167
Technical Details
Message-ID:
<4aokt2$14j@elf.bsdi.com>Path:
arc1-ca.pugleaf.net!cs.umd.edu!not-for-mailReferences:
<DJEADH.HwC@nntpa.cb.att.com> <4alnjh$r8l@usenet.pa.dec.com> <4ampmf$4td@rdsunx.crd.ge.com> <30cf690b.6742464@nntp.ix.netcom.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!cs.umd.edu!not-for-mail From: torek@elf.bsdi.com (Chris Torek) Newsgroups: comp.std.c Subject: Re: Can longjmp modify errno? Date: 13 Dec 1995 23:48:50 -0800 Organization: Berkeley Software Design, Inc. Message-ID: <4aokt2$14j@elf.bsdi.com> References: <DJEADH.HwC@nntpa.cb.att.com> <4alnjh$r8l@usenet.pa.dec.com> <4ampmf$4td@rdsunx.crd.ge.com> <30cf690b.6742464@nntp.ix.netcom.com> Reply-To: torek@bsdi.com NNTP-Posting-Host: elf.bsdi.com