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 <exceptions.h> #include <sys/cygwin.h> ... 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/ |\ _,,,---,,_ [EMAIL PROTECTED] ZZZzz /,`.-'`' -. ;-;;,_ [EMAIL PROTECTED] |,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/