Subject: RE: SML-NJ for CygWin32
From: [email-masked] (Sergey Okhapkin)

30 Aug 1997 20:43:04 -0700
Approved: [email-masked]
Distribution: cygnus
Message-ID: <01BCB077.8501DD60.cygnus.gnu-win32@sos>
Original-To: "[email-masked]'" <[email-masked]>,
        "'Gary Fuehrer'"
	 <[email-masked]>
Original-Cc: "'Geoffrey Noer'" <[email-masked]>
Encoding: 88 TEXT
Original-Sender: [email-masked]

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.
> I have a patch for exception.cc in winsup to add this functionality and
> fix a related bug.

I hope you made modifications in call_handler() and wrap assembly code? 
Current sources  contains all you need to implement this functionality:

  res = SuspendThread (OurhThread);
  debug_printf ("suspend said %d error %d\n", res, GetLastError());
  orig.ContextFlags = CONTEXT_CONTROL | CONTEXT_INTEGER;
  res = GetThreadContext (OurhThread, &orig);

  unsigned int *sp = (unsigned int *) orig.Esp;
  *(--sp) = orig.Eip;	/*  rethere = orig.Eip;*/
  orig.Eip = (unsigned) &&wrap;

  *(--sp) = oldmask;
  *(--sp) = n;
  *(--sp) = (DWORD) pfunc;
  orig.Esp = (DWORD) sp;
  SetThreadContext (OurhThread, &orig); /* Restart the thread */
  ResumeThread (OurhThread);
  /* It looks like a bug in Windows NT, but several waiting threads are not
     always released on SetEvent() without this sleep...
  */
  Sleep(1);
  PulseEvent (signal_arrived);
  WSACancelBlockingCall();
  return;
  /* This code is run in the standard thread space */
  /* Commented out instructions are emulated already */
 wrap:
  asm ("orl	$0x0,(%esp)\n"  /* probe out enough room to play */
      "orl	$0x0,-0x800(%esp)\n"
      "orl	$0x0,-0x1000(%esp)\n"
//      "pushl	_rethere\n"
//      "pushl 	_oldmask\n"
//      "pushl 	_sigarg\n"
//      "pushl 	_sigfunc\n");
      "pusha\n"
      "pushf\n"
      "pushl 	%ebp\n"
      "movl 	%esp,%ebp\n"
      "pushl	0xb*4(%ebp)\n"		// sigarg
      "movl	0xa*4(%ebp),%eax\n"	// sigfunc
      "call 	*%eax\n"
      "pushl	0xc*4(%ebp)\n"		// oldmask
      "call	_set_process_mask\n"
      "leave\n"
      "popf\n"
      "popa\n"
      "popl	_rethere\n"
      "popl	_rethere\n"
      "popl	_rethere\n"
      "ret");

The saved integer registers are accessible from signal handler. Save float 
context just near pusha/pushf and modify sigarg/sigfunc/oldmask offsets.

> > > 3.	There is no SIGVTALRM signal.
> SML-NJ doesn't seem to need this in order to function.  For now, I'm
> providing a dummy #define.

I don't know how to implement virtual timer on win32.

> > > 4.	"L_ctermid" is not defined (but "L_cuserid" is).
> I don't remember why SML-NJ needs this.  For now, I'm providing a dummy
> #define.  It's not critical.

L_ctermid define should be added to stdio.h, and ctermid() call should be 
added to winsup sources for POSIX conformance.

> > > 5.	The following definitions are not in the Posix sockets include
> > > files (only the Windows socket stuff)

The missing defines already added to headers.

--
Sergey Okhapkin, http://www.lexa.ru/sos
Moscow, Russia
Looking for a job

-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".