This is the mail archive of the cygwin@sourceware.cygnus.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]

SML-NJ for CygWin32 Bugs/Problems


Sergey Okhapkin wrote:
> Gary Fuehrer wrote:
> > 2.	The signal handling in CygWin32 doesn't let me do the following:
> > a.	Get and Set the "eip" register (or any register) of the
> > excepting thread.
> > b.	Ascertain the kind of floating point exception that occurred.
> > The need is for "siginfo_t" and "sigcontext" parameters that can be
> > optionally received and modified by signal handlers.
> 
> What unix analogs do you speak about?

Here's a program that works on some Unix systems.

	#include <signal.h>
	#include <stdlib.h>

	#define FAULT_ADDRESS ((int *)112)

	extern void handler(int signum, siginfo_t *info, void *context);

	int main() {
		struct sigaction act;
		act.sa_flags = SA_SIGINFO | SA_RESTART;
		act.sa_sigaction = handler;
		if (sigemptyset(&act.sa_mask) != 0)
			exit(1);
		if (sigaction(SIGSEGV, &act, NULL) != 0)
			exit(1);
		/* provoke a SIGSEGV */
		(*FAULT_ADDRESS)++;
		exit(1);
	}

	void handler(int signum, siginfo_t *info, void *context) {
		if (signum == SIGSEGV &&
		    info->si_signo == SIGSEGV &&
		    info->si_code > 0 &&
		    (int *)info->si_addr == FAULT_ADDRESS)
		{
			exit(0);
		} else {
			exit(1);
		}
	}

Here's another one that works on Linux (you may need to #define
HAVE_ASM_SIGCONTEXT, depending on the exact Linux version).

	#define sigcontext_struct sigcontext

	#define __KERNEL__
	#include <signal.h>
	#undef __KERNEL__

	#ifdef HAVE_ASM_SIGCONTEXT
	#include <asm/sigcontext.h>
	#endif

	#include <stdio.h>

	extern void handler(int signum, struct sigcontext_struct info);

	#define FAULT_ADDRESS ((int *)112)

	int main() {
		signal(SIGSEGV, (void (*)(int))handler);

		/* provoke a SIGSEGV */
		(*FAULT_ADDRESS)++;

		exit(1);
	}

	void handler(int signum, struct sigcontext_struct context) {
		if (signum == SIGSEGV && (int *) context.cr2 == FAULT_ADDRESS) {
			exit(0);
		} else {
			exit(1);
		}
	}

--
Fergus Henderson <fjh@cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh@128.250.37.3         |     -- the last words of T. S. Garp.
-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


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