delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2002/07/15/14:08:32

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/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
X-Authentication-Warning: slinky.cs.nyu.edu: pechtcha owned process doing -bs
Date: Mon, 15 Jul 2002 14:08:23 -0400 (EDT)
From: Igor Pechtchanski <pechtcha AT cs DOT nyu DOT edu>
To: cygwin AT cygwin DOT com
Subject: Re: Accessing signal context from a handler
In-Reply-To: <20020715171545.GC28190@redhat.com>
Message-ID: <Pine.GSO.4.44.0207151331220.24745-100000@slinky.cs.nyu.edu>
MIME-Version: 1.0

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

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/

- Raw text -


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