Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com X-Authentication-Warning: slinky.cs.nyu.edu: pechtcha owned process doing -bs Date: Thu, 3 Oct 2002 18:27:14 -0400 (EDT) From: Igor Pechtchanski Reply-To: cygwin AT cygwin DOT com To: Allen Leung cc: cygwin AT cygwin DOT com Subject: Re: Bypassing cygwin's signal handling In-Reply-To: Message-ID: Importance: Normal MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Thu, 3 Oct 2002, Igor Pechtchanski wrote: > On Thu, 3 Oct 2002, Allen Leung wrote: > > > Dear List, > > > > In a system I'm writing I need to catch page faults and find out > > the fault address and the fault type (read or write). On most unices > > I can get this information inside a sigaction handler. > > E.g. on Linux, something like this works: > > > > ========================================================== > > void fault_handler(int sig, siginfo_t * info, void * uap) > > { > > vm_addr_t addr; > > VM::access_t access; > > > > /* fault address */ > > addr = (vm_addr_t)info->si_addr; > > /* 1 for write; 0 for read */ > > access = (VM::access_t) > > ((((ucontext_t *)uap)->uc_mcontext.gregs[13] & 0x2) != 0); > > ... > > } > > ========================================================== > > > > However, cygwin's signal handling mechanism doesn't propagate these > > information to the signal handler. On mingw, I can use window's API > > to get the info I need: > > > > ========================================================== > > LONG WINAPI fault_handler(LPEXCEPTION_POINTERS info) > > { > > vm_addr_t addr; > > VM::access_t access; > > > > if (info->ExceptionRecord->ExceptionCode != EXCEPTION_ACCESS_VIOLATION) > > return EXCEPTION_CONTINUE_SEARCH; > > > > access = (VM::access_t)info->ExceptionRecord->ExceptionInformation[0]; > > addr = (vm_addr_t)info->ExceptionRecord->ExceptionInformation[1]; > > > > ... > > } > > > > SetUnhandledExceptionFilter(fault_handler); > > ========================================================== > > > > However, this doesn't work on cygwin because apparently cygwin is > > overriding my own fault handler. So I'm wondering: how can I bypass > > cygwin's signal handling mechanism so that I get hold of the page fault > > information? > > > > Thanks, > > Allen > > Hey, Allen! (Of all places to meet here :-D) > > Cygwin currently does not support SA_SIGINFO signal handling. It's on the > TODO list ( http://cygwin.com//cgi-bin/cygwin-todo.cgi?20020722.130725 ), > but I didn't have the time to work on it yet... > > As far as I know, there is currently no way to retrieve the fault > information from a Unix-style signal handler in Cygwin. You might try to > patch the Cygwin DLL to ignore a particular signal (in > winsup/cygwin/exceptions.cc), and then write your own Windows-style > handler... It'll probably be quite a bit of work. Another idea would be > to include a callback to your own function in handle_exceptions(). In > either case, you'll have to build a custom cygwin1.dll... > Igor Allen, Actually, the first thing to try should probably be #include #include ... exception_list el; cygwin_internal(CW_INIT_EXCEPTIONS, &el); el.handler = your_handler; ... I'm not sure how to clean this up afterwards, but theoretically this should work... Chris Faylor will hopefully correct me if I'm wrong. Igor -- http://cs.nyu.edu/~pechtcha/ |\ _,,,---,,_ pechtcha AT cs DOT nyu DOT edu ZZZzz /,`.-'`' -. ;-;;,_ igor AT watson DOT ibm DOT com |,4- ) )-,_. ,\ ( `'-' Igor Pechtchanski '---''(_/--' `-'\_) fL a.k.a JaguaR-R-R-r-r-r-.-.-. Meow! "Water molecules expand as they grow warmer" (C) Popular Science, Oct'02, p.51 -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/