Subject: pkg/32722: fixes for smlnj on i386
To: None <pkg-manager@netbsd.org, gnats-admin@netbsd.org,>
From: None <dholland@eecs.harvard.edu>
List: pkgsrc-bugs
Date: 02/03/2006 23:20:00
>Number:         32722
>Category:       pkg
>Synopsis:       lang/smlnj doesn't compile on i386
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Feb 03 23:20:00 +0000 2006
>Originator:     David A. Holland <dholland@eecs.harvard.edu>
>Release:        NetBSD 3.99.10 (-20051026) pkgsrc-20060203
>Organization:
   Harvard EECS
>Environment:
System: NetBSD tanaqui 3.99.10 NetBSD 3.99.10 (TANAQUI) #3: Wed Oct 26 18:52:27 EDT 2005 root@tanaqui:/usr/src/sys/arch/i386/compile/TANAQUI i386
Architecture: i386
Machine: i386
>Description:
	lang/smlnj compile fails in the runtime because of signal issues.
	Some investigation shows that the NetBSD signal handling code is
	a trifle dated; it was using sigvec and other fun stuff and
	refers to a kernel bug in 1.0.

>How-To-Repeat:
	cd lang/smlnj && make

>Fix:

	Update for the century of the fruitbat. Patches follow.

	It builds and seems to work with these changes, although I
	haven't tested it extensively or anything.

	I also haven't tried any of the other targets as I don't have
	the toolchains handy. They are probably still broken.

--- src/runtime/include/ml-unixdep.h.orig	2002-10-11 21:03:50.000000000 -0400
+++ src/runtime/include/ml-unixdep.h	2006-02-03 17:36:51.000000000 -0500
@@ -309,14 +309,14 @@
 #elif defined(OPSYS_NETBSD)
 #  define OS_NAME	"BSD"
 #  define HAS_POSIX_LIBRARIES
-#  define HAS_BSD_SIGS
+#  define HAS_POSIX_SIGS
 #  define HAS_GETRUSAGE
 #  define HAS_SETITIMER
 #  define HAS_MMAP
 #  define HAS_SELECT
 #  define HAS_SCALBN
 #  define HAS_ILOGB
-#  define HAS_SIGCONTEXT
+#  define HAS_UCONTEXT
 #  define HAS_STRERROR
 
 #endif

--- src/runtime/mach-dep/signal-sysdep.h~	2006-02-03 17:22:27.000000000 -0500
+++ src/runtime/mach-dep/signal-sysdep.h	2006-02-03 17:47:14.000000000 -0500
@@ -476,35 +476,18 @@
 
 #  elif defined(OPSYS_NETBSD)
     /** x86, NetBSD **/
-/* NetBSD (including versions 1.0 and 1.1) generates SIGBUS rather
-   than SIGFPE for overflows.  The real fix is a trivial change to
-   kernel sources, which has already been reported (NetBSD internal
-   problem identification "port-i386/1833"). 
-
-   If you want to fix this on your NetBSD system.  Edit machdep.c in
-   directory /sys/arch/i386/i386, and find the line
-
-        setgate(&idt[  4], &IDTVEC(ofl),     0, SDT_SYS386TGT, SEL_KPL);
-
-   Change SEL_KPL to SEL_UPL.  With SEL_KPL, the int overflow trap is
-   not accessible at user level, and a protection fault occurs instead
-   (thus the seg fault).  SEL_UPL will allow user processes to generate
-   this trap.
 
-   For the change to take effect, recompile your kernel, install it
-   and reboot. */
+/* this is partly guesswork but should be ok */
+
 #    define SIG_FAULT1		SIGFPE
-#    define SIG_FAULT2		SIGBUS
-#    define INT_DIVZERO(s, c)	0
-#    define INT_OVFLW(s, c)	(((s) == SIGFPE) || ((s) == SIGBUS))
+#    define INT_DIVZERO(s, c)	((s) == SIGFPE)
+#    define INT_OVFLW(s, c)	((s) == SIGFPE)
 
-#    define SIG_GetCode(info, scp)	(info)
-#    define SIG_GetPC(scp)		((scp)->sc_pc)
-#    define SIG_SetPC(scp, addr)	{ (scp)->sc_pc = (long)(addr); }
+#    define SIG_GetCode(info, scp)	(0)
+#    define SIG_GetPC(scp)		((scp)->uc_mcontext.__gregs[_REG_EIP])
+#    define SIG_SetPC(scp, addr)	{(scp)->uc_mcontext.__gregs[_REG_EIP] = (long)(addr); }
 #    define SIG_ZeroLimitPtr(scp)	{ ML_X86Frame[LIMITPTR_X86OFFSET] = 0; }
 
-     typedef void SigReturn_t;
-
 #  elif defined(OPSYS_SOLARIS)
      /** x86, Solaris */