Subject: SML-NJ for CygWin32 Bugs/Problems
From: [email-masked] (Fergus Henderson)

17 Jun 1997 14:43:32 -0700
Approved: [email-masked]
Distribution: cygnus
Message-ID: <[email-masked]>
Original-To: [email-masked]
Original-Sender: [email-masked]

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 <[email-masked]>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger [email-masked]         |     -- the last words of T. S. Garp.
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".