[project @ 2002-09-06 14:34:13 by simonmar]
authorsimonmar <unknown>
Fri, 6 Sep 2002 14:34:15 +0000 (14:34 +0000)
committersimonmar <unknown>
Fri, 6 Sep 2002 14:34:15 +0000 (14:34 +0000)
Partial rewrite of the POSIX library.

The main purpose of this sweep is to remove the last dependencies of
the compiler on hslibs.  When I've committed the associated compiler
changes, only the 'base' package will be required to bootstrap the
compiler.  Additionally to build GHCi, the 'readline' and 'unix'
packages will be required.

The new POSIX library lives mostly in libraries/unix, with a few bits
required for compiler bootstrapping in libraries/base.  The 'base'
package is mostly free of hsc2hs code to make bootstrapping from HC
files easier, but the 'unix' package will use hsc2hs liberally.

The old POSIX library continues to provide more-or-less the same
interface as before, although some of the types are more correct now
(previously lots of POSIX types were just mapped to Int).  The new
interface is largely the same as the old, except that some new
functionality from the latest POSIX spec has been added (eg. symbolic
links).

So far, the new POSIX library has signal support, directory/file
operations and lots of stuff from unistd.h.  The module names are:

  System.Posix
The main dude, exports everything

  System.Posix.Types
All the POSIX types, using the same naming scheme as
        Foreign.C.Types, Eg. CUid, COff, etc.  Many of these types
        were previously exported by GHC.Posix.

        Additionally exports the "nicer" names used by the old POSIX
library for compatibility (eg. ProcessID == CPid, FileMode ==
CMode, etc.)

All reasonable instances are derived for these types.

  System.Posix.Signals
Signal support, contains most of which was in PosixProcPrim before.
The RTS interface to the signal handling support has been
rationalised slightly.

  System.Posix.Directory
  Directory support, most were in PosixFiles before.

  System.Posix.Files
File operations, most were in PosixFiles before.

  System.Posix.Unistd
(for want of a better name) Miscellaneous bits that mostly come
from the unistd.h header file.  PosixProcEnv before.

The rest of the library should pan out like so:

  System.Posix.IO
  System.Posix.Error   (maybe)
  System.Posix.Process
  System.Posix.Terminal

(I've no doubt broken Win32 support, but I'm checking the build at the moment).

ghc/includes/PrimOps.h
ghc/includes/Signals.h [new file with mode: 0644]
ghc/includes/Stg.h
ghc/rts/Signals.c

index 61dcf84..ce4917d 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: PrimOps.h,v 1.96 2002/07/17 09:21:48 simonmar Exp $
+ * $Id: PrimOps.h,v 1.97 2002/09/06 14:34:14 simonmar Exp $
  *
  * (c) The GHC Team, 1998-2000
  *
@@ -316,21 +316,6 @@ EXTFUN_RTS(mkForeignObjzh_fast);
 EXTFUN_RTS(newBCOzh_fast);
 EXTFUN_RTS(mkApUpd0zh_fast);
 
-
-/* -----------------------------------------------------------------------------
-   Signal handling.  Not really primops, but called directly from Haskell. 
-   -------------------------------------------------------------------------- */
-
-#define STG_SIG_DFL  (-1)
-#define STG_SIG_IGN  (-2)
-#define STG_SIG_ERR  (-3)
-#define STG_SIG_HAN  (-4)
-
-extern StgInt stg_sig_install (StgInt, StgInt, StgStablePtr, void *);
-#define stg_sig_default(sig,mask) stg_sig_install(sig,STG_SIG_DFL,0,(void *)mask)
-#define stg_sig_ignore(sig,mask) stg_sig_install(sig,STG_SIG_IGN,0,(void *)mask)
-#define stg_sig_catch(sig,ptr,mask) stg_sig_install(sig,STG_SIG_HAN,ptr,(void *)mask)
-
 /* ------------------------------------------------------------------------
    Parallel PrimOps
 
diff --git a/ghc/includes/Signals.h b/ghc/includes/Signals.h
new file mode 100644 (file)
index 0000000..b2b588b
--- /dev/null
@@ -0,0 +1,21 @@
+/* -----------------------------------------------------------------------------
+ * $Id: Signals.h,v 1.1 2002/09/06 14:34:14 simonmar Exp $
+ *
+ * (c) The GHC Team, 1998-2002
+ *
+ * RTS signal handling 
+ *
+ * ---------------------------------------------------------------------------*/
+
+#ifndef SIGNALS_H
+#define SIGNALS_H
+
+#define STG_SIG_DFL  (-1)
+#define STG_SIG_IGN  (-2)
+#define STG_SIG_ERR  (-3)
+#define STG_SIG_HAN  (-4)
+
+extern int stg_sig_install (int, int, StgStablePtr *, void *);
+
+#endif // SIGNALS_H
+
index f553ff1..43ce31a 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: Stg.h,v 1.48 2002/07/22 10:02:13 simonmar Exp $
+ * $Id: Stg.h,v 1.49 2002/09/06 14:34:14 simonmar Exp $
  *
  * (c) The GHC Team, 1998-1999
  *
@@ -217,6 +217,8 @@ typedef StgWord64       LW_;
 /* Runtime-system hooks */
 #include "Hooks.h"
 
+#include "Signals.h"
+
 #include "HsFFI.h"
 
 /* Misc stuff without a home */
index 0685a2b..d2a61e3 100644 (file)
@@ -1,5 +1,5 @@
 /* -----------------------------------------------------------------------------
- * $Id: Signals.c,v 1.27 2002/09/03 14:07:03 simonmar Exp $
+ * $Id: Signals.c,v 1.28 2002/09/06 14:34:13 simonmar Exp $
  *
  * (c) The GHC Team, 1998-1999
  *
@@ -196,8 +196,8 @@ awaitUserSignals(void)
  * Install a Haskell signal handler.
  * -------------------------------------------------------------------------- */
 
-StgInt 
-stg_sig_install(StgInt sig, StgInt spi, StgStablePtr handler, void *mask)
+int
+stg_sig_install(int sig, int spi, StgStablePtr *handler, void *mask)
 {
     sigset_t signals, osignals;
     struct sigaction action;
@@ -228,7 +228,7 @@ stg_sig_install(StgInt sig, StgInt spi, StgStablePtr handler, void *mask)
        break;
 
     case STG_SIG_HAN:
-       handlers[sig] = (StgInt)handler;
+       handlers[sig] = (StgInt)*handler;
        sigaddset(&userSignals, sig);
        action.sa_handler = generic_handler;
        n_haskell_handlers++;
@@ -257,7 +257,13 @@ stg_sig_install(StgInt sig, StgInt spi, StgStablePtr handler, void *mask)
        return STG_SIG_ERR;
     }
     
-    return previous_spi;
+    if (previous_spi == STG_SIG_DFL || previous_spi == STG_SIG_IGN
+       || previous_spi == STG_SIG_ERR) {
+       return previous_spi;
+    } else {
+       *handler = (StgStablePtr)previous_spi;
+       return STG_SIG_HAN;
+    }
 }
 
 /* -----------------------------------------------------------------------------