delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2006/03/16/14:41:29

X-Spam-Check-By: sourceware.org
From: ericblake AT comcast DOT net (Eric Blake)
To: Norton Allen <allen AT huarp DOT harvard DOT edu>, cygwin list <cygwin AT cygwin DOT com>
Subject: RE: Bug in dlopen() (or following) code in Cygwin1.dll v 1.5.19-4
Date: Thu, 16 Mar 2006 19:41:18 +0000
Message-Id: <031620061941.903.4419BF5E000BEFE80000038722007456720A050E040D0C079D0A@comcast.net>
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

Top-posting reformatted - cygwin.com/acronyms/#TOFU

> >>> The "efault.faulted()" two lines above your change is supposed to catch
> >>> NULL dereferences.
> >> 
> > 
> >   Take a /look/ at the source for myfault::faulted in cygtls.h, it calls out
> > to _cygtls::setup_fault, which calls _sjfault, which appears to be a q'n'd
> > hacked-up version of setjmp in a context where it's going to get called back
> > by an SEH handler.  So IIUIC, calling 'efault.faulted' will catch any
> > exception that happens from the point of the call until the point where the
> > efault object goes out of scope and gets destructed and will cause execution
> > to jump back to the if... clause.

> Ah, got it--it behaves like exception handling, but it
> doesn't *look* like exception handling. Seems like a
> good place to add some comments! ;-) (Offer to submit
> a patch, but seeing as I had to ask, I doubt I'm the
> right person to do so.) Thanks for clearing this up
> for me!

The only logical place for such a comment would be at the source
for myfault::faulted, as the idiom of efault.faulted() appears
throughout cygwin.

One more thing to be aware of - the reason cygwin uses
this (IMHO very slick) feature of C++ is that it is more efficient
to assume that code will not fault, and blindly deference
pointers with the minimal overhead of setting up the
setjmp buffer with a pre-installed exception handler already
prepared for this usage, than it is to use a syscall to Window's
routines to validate every pointer before dereferencing it.  On
the exceptional case that the code actually did get passed a
bad pointer, the overhead of the exception handling and longjmp
are slower, but that is okay since it is the exception.

So maybe it looks weird.  C++ is like that!

-- 
Eric Blake

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019