This is the mail archive of the cygwin@cygwin.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Accessing signal context from a handler


On Mon, 15 Jul 2002, Christopher Faylor wrote:

> On Mon, Jul 15, 2002 at 01:00:23PM -0400, Igor Pechtchanski wrote:
> >Does Cygwin allow accessing the context (register state, etc) of the
> >faulted instruction from a signal handler installed by sigaction(),
> >similar to ucontext/mcontext in Linux?  Accessing the Windows CONTEXT
> >object should do.  I've looked through winsup/cygwin/exceptions.cc, and
> >that info doesn't seem to be saved anywhere for later access, nor is it
> >passed into the handler.
>
> It's not available.
> cgf

Thanks.  I was kinda hoping for a "we're working on it, should be
available in the next release", but no such luck, I guess... :-)

Would anyone then be able to suggest a way of installing a user-level
signal handler in Cygwin that would have access to the context?

Basically, I'm trying to port an application that intercepts SIGSEGV and
makes decisions based on the IP of the faulted instruction.  The
application currently uses the sigaction/ucontext mechanism in Linux.
Any suggestions on how to do this in Cygwin (preferably similar to the
Linux code, to maximize reuse) would be appreciated.

A stripped example of the Linux code is included below.
	Igor

#include <signal.h>
#include <asm/ucontext.h>

void handler(int signo, siginfo_t *si, void *context) {
   sigcontext *sc = &((ucontext *) context)->uc_mcontext;
   int ip = sc->eip;
   if (signo == SIGSEGV) {
      if (ip >= start_ip && ip < end_ip) { ... } else { ... }
   }
}

void install_handler() {
   struct sigaction action;
   memset(&action, 0, sizeof action);
   action.sa_sigaction = &handler;
   if (sigfillset(&(action.sa_mask))) { error(); }
   if (sigdelset(&(action.sa_mask), SIGCONT)) { error(); }
   action.sa_flags = SA_SIGINFO | SA_ONSTACK | SA_RESTART;
   if (sigaction (SIGSEGV, &action, 0)) { error(); }
}
-- 
				http://cs.nyu.edu/pechtcha/
      |\      _,,,---,,_		pechtcha@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

It took the computational power of three Commodore 64s to fly to the moon.
It takes a 486 to run Windows 95.  Something is wrong here. -- SC sig file


--
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/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]