Wed Aug 11 10:58:27 BST 2010  rmcilroy@microsoft.com
  * Checkpoint GHC on Barrelfish work
  
  Now at the stage where we can build and run a helloword Haskell application on Barrelfish.
  
Mon Aug  9 10:50:19 BST 2010  rmcilroy@microsoft.com
  * Checkpoint barrelfish compatability changes
Thu Jul 29 14:57:30 BST 2010  rmcilroy@microsoft.com
  * Changes to get ghc building against Barrelfish
diff -rN -u old-unix/cbits/execvpe.c new-unix/cbits/execvpe.c
--- old-unix/cbits/execvpe.c	2010-08-11 16:02:31.000000000 +0100
+++ new-unix/cbits/execvpe.c	2010-08-11 16:02:31.000000000 +0100
@@ -9,7 +9,7 @@
 #include "Rts.h"
 #endif
 
-#if !(defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32)) /* to the end */
+#if !(defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32) || defined(barrelfish_HOST_OS)) /* to the end */
 
 /* Evidently non-Posix. */
 /* #include "PosixSource.h" */
diff -rN -u old-unix/cbits/HsUnix.c new-unix/cbits/HsUnix.c
--- old-unix/cbits/HsUnix.c	2010-08-11 16:02:31.000000000 +0100
+++ new-unix/cbits/HsUnix.c	2010-08-11 16:02:31.000000000 +0100
@@ -8,12 +8,39 @@
 
 #include "HsUnix.h"
 
+#ifdef barrelfish_HOST_OS
+int __hsunix_wifexited   (int stat) { 
+    printf("NYI __hsunix_wifexited\n");
+    return -1; 
+}
+int __hsunix_wexitstatus (int stat) { 
+    printf("NYI __hsunix_wexitstatus\n");
+    return -1; 
+}
+int __hsunix_wifsignaled (int stat) { 
+    printf("NYI __hsunix_wifsignaled\n");
+    return -1; 
+}
+int __hsunix_wtermsig    (int stat) { 
+    printf("NYI __hsunix_wtermsig\n");
+    return -1; 
+}
+int __hsunix_wifstopped  (int stat) { 
+    printf("NYI __hsunix_wifstopped\n");
+    return -1; 
+}
+int __hsunix_wstopsig    (int stat) { 
+    printf("NYI __hsunix_wstopsig\n");
+    return -1; 
+}
+#else
 int __hsunix_wifexited   (int stat) { return WIFEXITED(stat); }
 int __hsunix_wexitstatus (int stat) { return WEXITSTATUS(stat); }
 int __hsunix_wifsignaled (int stat) { return WIFSIGNALED(stat); }
 int __hsunix_wtermsig    (int stat) { return WTERMSIG(stat); }
 int __hsunix_wifstopped  (int stat) { return WIFSTOPPED(stat); }
 int __hsunix_wstopsig    (int stat) { return WSTOPSIG(stat); }
+#endif
 
 #ifdef HAVE_RTLDNEXT
 void *__hsunix_rtldNext (void) {return RTLD_NEXT;} 
@@ -30,6 +57,7 @@
 int __hsunix_SIGWINCH()	{ return SIGWINCH; }
 #endif
 
+#ifndef barrelfish_HOST_OS
 // lstat is a macro on some platforms, so we need a wrapper:
 int __hsunix_lstat(const char *path, struct stat *buf) 
 { 
@@ -41,6 +69,7 @@
 { 
     return mknod(pathname,mode,dev);
 }
+#endif
 
 #ifdef HAVE_GETPWENT
 // getpwent is a macro on some platforms, so we need a wrapper:
@@ -88,11 +117,13 @@
     return time(tloc);
 }
 
+#ifndef barrelfish_HOST_OS
 // times is a macro on some platforms, so we need a wrapper:
 clock_t __hsunix_times(struct tms *tp)
 {
     return times(tp);
 }
+#endif
 
 #ifdef HAVE_PTSNAME
 // I cannot figure out how to make the definitions of the following
@@ -128,13 +159,13 @@
 #endif
 }
 
-#if !defined(__MINGW32__)
+#if !defined(__MINGW32__) && !defined(barrrelfish_HOST_OS)
 int __hscore_mkstemp(char *filetemplate) {
     return (mkstemp(filetemplate));
 }
 #endif
 
-#if !defined(__MINGW32__) && !defined(irix_HOST_OS)
+#if !defined(__MINGW32__) && !defined(irix_HOST_OS) && !defined(barrelfish_HOST_OS)
 int __hscore_getrlimit(int resource, struct rlimit *rlim) {
     return (getrlimit(resource, rlim));
 }
diff -rN -u old-unix/config.sub new-unix/config.sub
--- old-unix/config.sub	2010-08-11 16:02:31.000000000 +0100
+++ new-unix/config.sub	2010-08-11 16:02:31.000000000 +0100
@@ -4,7 +4,7 @@
 #   2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation,
 #   Inc.
 
-timestamp='2006-07-02'
+timestamp='2010-08-10'
 
 # This file is (in principle) common to ALL GNU software.
 # The presence of a machine in this file suggests that SOME GNU software
@@ -1344,6 +1344,9 @@
 	-zvmoe)
 		os=-zvmoe
 		;;
+	-barrelfish)
+		os=-barrelfish
+		;;
 	-none)
 		;;
 	*)
diff -rN -u old-unix/include/execvpe.h new-unix/include/execvpe.h
--- old-unix/include/execvpe.h	2010-08-11 16:02:31.000000000 +0100
+++ new-unix/include/execvpe.h	2010-08-11 16:02:31.000000000 +0100
@@ -14,11 +14,11 @@
 
 #include <errno.h>
 #include <sys/types.h>
-#if HAVE_SYS_WAIT_H
+#if HAVE_SYS_WAIT_H && !defined(BARRELFISH)
 #include <sys/wait.h>
 #endif
 
-#if !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(_WIN32)
+#if !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(_WIN32) && !defined(BARRELFISH)
 extern int execvpe(char *name, char *const argv[], char **envp);
 extern void pPrPr_disableITimers (void);
 #endif
diff -rN -u old-unix/include/HsUnix.h new-unix/include/HsUnix.h
--- old-unix/include/HsUnix.h	2010-08-11 16:02:31.000000000 +0100
+++ new-unix/include/HsUnix.h	2010-08-11 16:02:31.000000000 +0100
@@ -121,11 +121,13 @@
 int __hsunix_SIGWINCH();
 #endif
 
+#ifndef barrelfish_HOST_OS
 // lstat is a macro on some platforms, so we need a wrapper:
 int __hsunix_lstat(const char *path, struct stat *buf);
 
 // lstat is a macro on some platforms, so we need a wrapper:
 int __hsunix_mknod(const char *pathname, mode_t mode, dev_t dev);
+#endif 
 
 #ifdef HAVE_GETPWENT
 // getpwent is a macro on some platforms, so we need a wrapper:
@@ -155,8 +157,11 @@
 // time is a macro on some platforms, so we need a wrapper:
 time_t __hsunix_time(time_t *);
 
+
+#ifndef barrelfish_HOST_OS
 // times is a macro on some platforms, so we need a wrapper:
 clock_t __hsunix_times(struct tms *);
+#endif 
 
 #ifdef HAVE_PTSNAME
 // I cannot figure out how to make the definitions of the following
@@ -171,11 +176,11 @@
 // push a SVR4 STREAMS module; do nothing if STREAMS not available
 int __hsunix_push_module(int fd, const char *module);
 
-#if !defined(__MINGW32__)
+#if !defined(__MINGW32__) && !defined(barrelfish_HOST_OS)
 int __hscore_mkstemp(char *filetemplate);
 #endif
 
-#if !defined(__MINGW32__) && !defined(irix_HOST_OS)
+#if !defined(__MINGW32__) && !defined(irix_HOST_OS) && !defined(barrelfish_HOST_OS)
 int __hscore_getrlimit(int resource, struct rlimit *rlim);
 int __hscore_setrlimit(int resource, struct rlimit *rlim);
 #endif
diff -rN -u old-unix/System/Posix/Files.hsc new-unix/System/Posix/Files.hsc
--- old-unix/System/Posix/Files.hsc	2010-08-11 16:02:31.000000000 +0100
+++ new-unix/System/Posix/Files.hsc	2010-08-11 16:02:31.000000000 +0100
@@ -321,8 +321,12 @@
   unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_uid)
 fileGroup (FileStatus stat) =
   unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_gid)
+#ifdef barrelfish_HOST_OS
+specialDeviceID (FileStatus stat) = 0
+#else
 specialDeviceID (FileStatus stat) =
   unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_rdev)
+#endif
 fileSize (FileStatus stat) =
   unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_size)
 accessTime (FileStatus stat) =
@@ -408,9 +412,14 @@
 --
 -- Note: calls @mkfifo@.
 createNamedPipe :: FilePath -> FileMode -> IO ()
+#ifdef barrelfish_HOST_OS
+createNamedPipe name mode = do
+    return ()
+#else
 createNamedPipe name mode = do
   withCString name $ \s -> 
     throwErrnoPathIfMinus1_ "createNamedPipe" name (c_mkfifo s mode)
+#endif
 
 -- | @createDevice path mode dev@ creates either a regular or a special file
 -- depending on the value of @mode@ (and @dev@).  @mode@ will normally be either
@@ -436,10 +445,15 @@
 --
 -- Note: calls @link@.
 createLink :: FilePath -> FilePath -> IO ()
+#ifdef barrelfish_HOST_OS
+createLink name1 name2 = do
+  return ()
+#else
 createLink name1 name2 =
   withCString name1 $ \s1 ->
   withCString name2 $ \s2 ->
   throwErrnoPathIfMinus1_ "createLink" name1 (c_link s1 s2)
+#endif
 
 -- | @removeLink path@ removes the link named @path@.
 --
@@ -551,7 +565,16 @@
 
 -- -----------------------------------------------------------------------------
 -- utime()
+#ifdef barrelfish_HOST_OS
+setFileTimes :: FilePath -> EpochTime -> EpochTime -> IO ()
+setFileTimes name atime mtime = do
+  return ()
 
+touchFile :: FilePath -> IO ()
+touchFile name = do
+  return ()
+
+#else
 -- | @setFileTimes path atime mtime@ sets the access and modification times
 -- associated with file @path@ to @atime@ and @mtime@, respectively.
 --
@@ -573,6 +596,8 @@
   withCString name $ \s ->
    throwErrnoPathIfMinus1_ "touchFile" name (c_utime s nullPtr)
 
+#endif
+
 -- -----------------------------------------------------------------------------
 -- Setting file sizes
 
@@ -621,6 +646,9 @@
   | SyncIOAvailable		  {- _PC_SYNC_IO          -}
 
 pathVarConst :: PathVar -> CInt
+#ifdef barrelfish_HOST_OS
+pathVarConst v = 0
+#else
 pathVarConst v = case v of
 	LinkLimit     			-> (#const _PC_LINK_MAX)
 	InputLineLimit			-> (#const _PC_MAX_CANON)
@@ -661,6 +689,7 @@
 #else
 	SymbolicLinkLimit	-> error "_PC_SYMLINK_MAX not available"
 #endif
+#endif
 
 
 -- | @getPathVar var path@ obtains the dynamic value of the requested
diff -rN -u old-unix/System/Posix/IO.hsc new-unix/System/Posix/IO.hsc
--- old-unix/System/Posix/IO.hsc	2010-08-11 16:02:31.000000000 +0100
+++ new-unix/System/Posix/IO.hsc	2010-08-11 16:02:31.000000000 +0100
@@ -41,15 +41,19 @@
     fdSeek,
 
     -- ** File options
+#ifdef HAVE_FCNTL_H
     FdOption(..),
     queryFdOption,
     setFdOption,
+#endif
 
     -- ** Locking
+#ifndef barrelfish_HOST_OS
     FileLock,
     LockRequest(..),
     getLock,  setLock,
     waitToSetLock,
+#endif
 
     -- ** Pipes
     createPipe,
@@ -271,7 +275,9 @@
   -- state as a result. 
   let fd = haFD h_
   flushWriteBufferOnly h_
+#ifndef barrelfish_HOST_OS
   unlockFile (fromIntegral fd)
+#endif
     -- setting the Handle's fd to (-1) as well as its 'type'
     -- to closed, is enough to disable the finalizer that
     -- eventually is run on the Handle.
@@ -294,6 +300,8 @@
 -- -----------------------------------------------------------------------------
 -- Fd options
 
+#ifdef HAVE_FCNTL_H
+
 data FdOption = AppendOnWrite     -- ^O_APPEND
 	      | CloseOnExec       -- ^FD_CLOEXEC
 	      | NonBlockingRead   -- ^O_NONBLOCK
@@ -335,6 +343,8 @@
 foreign import ccall unsafe "HsBase.h fcntl_write"
    c_fcntl_write :: CInt -> CInt -> CLong -> IO CInt
 
+#endif 
+
 -- -----------------------------------------------------------------------------
 -- Seeking 
 
@@ -351,6 +361,8 @@
 -- -----------------------------------------------------------------------------
 -- Locking
 
+#ifndef barrelfish_HOST_OS
+
 data LockRequest = ReadLock
                  | WriteLock
                  | Unlock
@@ -421,6 +433,8 @@
     throwErrnoIfMinus1_ "waitToSetLock" 
 	(c_fcntl_lock fd (#const F_SETLKW) p_flock)
 
+#endif
+
 -- -----------------------------------------------------------------------------
 -- fd{Read,Write}
 
diff -rN -u old-unix/System/Posix/Process.hsc new-unix/System/Posix/Process.hsc
--- old-unix/System/Posix/Process.hsc	2010-08-11 16:02:31.000000000 +0100
+++ new-unix/System/Posix/Process.hsc	2010-08-11 16:02:31.000000000 +0100
@@ -44,6 +44,7 @@
     getProcessTimes,
 
     -- ** Scheduling priority
+#ifndef barrelfish_HOST_OS
     nice,
     getProcessPriority,
     getProcessGroupPriority,
@@ -51,6 +52,7 @@
     setProcessPriority,
     setProcessGroupPriority,
     setUserPriority,
+#endif
 
     -- ** Process status
     ProcessStatus(..),
@@ -157,6 +159,15 @@
 -- | 'getProcessTimes' calls @times@ to obtain time-accounting
 --   information for the current process and its children.
 getProcessTimes :: IO ProcessTimes
+#ifdef barrelfish_HOST_OS
+getProcessTimes = do
+     return (ProcessTimes{ elapsedTime     = 0,
+	 		   userTime        = 0,
+	 		   systemTime      = 0,
+	 		   childUserTime   = 0,
+	 		   childSystemTime = 0
+			  })
+#else
 getProcessTimes = do
    allocaBytes (#const sizeof(struct tms)) $ \p_tms -> do
      elapsed <- throwErrnoIfMinus1 "getProcessTimes" (c_times p_tms)
@@ -170,6 +181,7 @@
 	 		   childUserTime   = cut,
 	 		   childSystemTime = cst
 			  })
+#endif
 
 type CTms = ()
 
@@ -179,6 +191,8 @@
 -- -----------------------------------------------------------------------------
 -- Process scheduling priority
 
+#ifndef barrelfish_HOST_OS
+
 nice :: Int -> IO ()
 nice prio = do
   resetErrno
@@ -231,6 +245,8 @@
 foreign import ccall unsafe "setpriority"
   c_setpriority :: CInt -> CInt -> CInt -> IO CInt
 
+#endif
+
 -- -----------------------------------------------------------------------------
 -- Forking, execution
 
@@ -361,10 +377,14 @@
 
 waitOptions :: Bool -> Bool -> CInt
 --             block   stopped
+#ifdef barrelfish_HOST_OS
+waitOptions _ _ = 0
+#else
 waitOptions False False = (#const WNOHANG)
 waitOptions False True  = (#const (WNOHANG|WUNTRACED))
 waitOptions True  False = 0
 waitOptions True  True  = (#const WUNTRACED)
+#endif 
 
 -- Turn a (ptr to a) wait status into a ProcessStatus
 
diff -rN -u old-unix/System/Posix/Resource.hsc new-unix/System/Posix/Resource.hsc
--- old-unix/System/Posix/Resource.hsc	2010-08-11 16:02:31.000000000 +0100
+++ new-unix/System/Posix/Resource.hsc	2010-08-11 16:02:31.000000000 +0100
@@ -19,6 +19,10 @@
 --
 -----------------------------------------------------------------------------
 
+#ifdef barrelfish_HOST_OS
+module System.Posix.Resource () where
+#else 
+
 module System.Posix.Resource (
     -- * Resource Limits
     ResourceLimit(..), ResourceLimits(..), Resource(..),
@@ -152,3 +156,5 @@
 showRLim ResourceLimitUnknown  = "unknown"
 showRLim (ResourceLimit other)  = show other
 -}
+
+#endif
\ No newline at end of file
diff -rN -u old-unix/System/Posix/Semaphore.hsc new-unix/System/Posix/Semaphore.hsc
--- old-unix/System/Posix/Semaphore.hsc	2010-08-11 16:02:31.000000000 +0100
+++ new-unix/System/Posix/Semaphore.hsc	2010-08-11 16:02:31.000000000 +0100
@@ -14,6 +14,10 @@
 --
 -----------------------------------------------------------------------------
 
+#ifdef barrelfish_HOST_OS
+module System.Posix.Semaphore () where
+#else
+
 module System.Posix.Semaphore
     (OpenSemFlags(..), Semaphore(), 
      semOpen, semUnlink, semWait, semTryWait, semThreadWait, 
@@ -126,3 +130,4 @@
         sem_post :: Ptr () -> IO CInt
 foreign import ccall safe "sem_getvalue"
         sem_getvalue :: Ptr () -> Ptr CInt -> IO Int
+#endif
\ No newline at end of file
diff -rN -u old-unix/System/Posix/SharedMem.hsc new-unix/System/Posix/SharedMem.hsc
--- old-unix/System/Posix/SharedMem.hsc	2010-08-11 16:02:31.000000000 +0100
+++ new-unix/System/Posix/SharedMem.hsc	2010-08-11 16:02:31.000000000 +0100
@@ -15,6 +15,10 @@
 --
 -----------------------------------------------------------------------------
 
+#ifdef barrelfish_HOST_OS
+module System.Posix.SharedMem () where
+#else
+
 module System.Posix.SharedMem
     (ShmOpenFlags(..), shmOpen, shmUnlink)
     where
@@ -84,3 +88,5 @@
 foreign import ccall unsafe "shm_unlink"
         shm_unlink :: CString -> IO CInt
 #endif
+
+#endif
\ No newline at end of file
diff -rN -u old-unix/System/Posix/Signals.hsc new-unix/System/Posix/Signals.hsc
--- old-unix/System/Posix/Signals.hsc	2010-08-11 16:02:31.000000000 +0100
+++ new-unix/System/Posix/Signals.hsc	2010-08-11 16:02:31.000000000 +0100
@@ -71,6 +71,7 @@
 
   -- * Signal sets
   SignalSet,
+#ifndef barrelfish_HOST_OS
   emptySignalSet, fullSignalSet, 
   addSignal, deleteSignal, inSignalSet,
 
@@ -82,7 +83,8 @@
 
   -- * Waiting for signals
   getPendingSignals,
-#ifndef cygwin32_HOST_OS
+#endif
+#if !defined(cygwin32_HOST_OS) && !defined(barrelfish_HOST_OS)
   awaitSignal,
 #endif
 
@@ -348,7 +350,7 @@
                -> Maybe SignalSet	-- ^ other signals to block
                -> IO Handler		-- ^ old handler
 
-#ifdef __PARALLEL_HASKELL__
+#if defined (__PARALLEL_HASKELL__) || defined(barrelfish_HOST_OS)
 installHandler = 
   error "installHandler: not available for Parallel Haskell"
 #else
@@ -482,6 +484,7 @@
 
 newtype SignalSet = SignalSet (ForeignPtr CSigset)
 
+#ifndef barrelfish_HOST_OS
 emptySignalSet :: SignalSet
 emptySignalSet = unsafePerformIO $ do
   fp <- mallocForeignPtrBytes sizeof_sigset_t
@@ -558,8 +561,9 @@
   withForeignPtr fp $ \p -> 
    throwErrnoIfMinus1_ "getPendingSignals" (c_sigpending p)
   return (SignalSet fp)
+#endif
 
-#ifndef cygwin32_HOST_OS
+#if !defined(cygwin32_HOST_OS) && !defined(barrelfish_HOST_OS)
 
 -- | @awaitSignal iset@ suspends execution until an interrupt is received.
 -- If @iset@ is @Just s@, @awaitSignal@ calls @sigsuspend@, installing
diff -rN -u old-unix/System/Posix/Terminal.hsc new-unix/System/Posix/Terminal.hsc
--- old-unix/System/Posix/Terminal.hsc	2010-08-11 16:02:31.000000000 +0100
+++ new-unix/System/Posix/Terminal.hsc	2010-08-11 16:02:31.000000000 +0100
@@ -14,6 +14,10 @@
 --
 -----------------------------------------------------------------------------
 
+#ifdef barrelfish_HOST_OS
+module System.Posix.Terminal () where
+#else 
+
 module System.Posix.Terminal (
   -- * Terminal support
 
@@ -66,6 +70,7 @@
   -- ** Pseudoterminal operations
   openPseudoTerminal,
   getSlaveTerminalName
+
   ) where
 
 #include "HsUnix.h"
@@ -804,3 +809,5 @@
     _ <- action p1
     return ()
   return $ makeTerminalAttributes fp1
+
+#endif
\ No newline at end of file
diff -rN -u old-unix/System/Posix/Unistd.hsc new-unix/System/Posix/Unistd.hsc
--- old-unix/System/Posix/Unistd.hsc	2010-08-11 16:02:31.000000000 +0100
+++ new-unix/System/Posix/Unistd.hsc	2010-08-11 16:02:31.000000000 +0100
@@ -68,6 +68,15 @@
 	   }
 
 getSystemID :: IO SystemID
+#ifdef barrelfish_HOST_OS
+getSystemID = do
+    return (SystemID { systemName = "",
+		       nodeName   = "",
+		       release    = "",
+		       version    = "",
+		       machine    = ""
+		     })
+#else
 getSystemID = do
   allocaBytes (#const sizeof(struct utsname)) $ \p_sid -> do
     throwErrnoIfMinus1_ "getSystemID" (c_uname p_sid)
@@ -82,6 +91,7 @@
 		       version    = ver,
 		       machine    = mach
 		     })
+#endif
 
 foreign import ccall unsafe "uname"
    c_uname :: Ptr CUtsname -> IO CInt
@@ -176,6 +186,9 @@
 	-- ToDo: lots more
 
 getSysVar :: SysVar -> IO Integer
+#ifdef barrelfish_HOST_OS
+getSysVar v = return (-1)
+#else
 getSysVar v =
     case v of
       ArgumentLimit -> sysconf (#const _SC_ARG_MAX)
@@ -194,3 +207,4 @@
 
 foreign import ccall unsafe "sysconf"
   c_sysconf :: CInt -> IO CLong
+#endif
\ No newline at end of file
diff -rN -u old-unix/System/Posix/User.hsc new-unix/System/Posix/User.hsc
--- old-unix/System/Posix/User.hsc	2010-08-11 16:02:31.000000000 +0100
+++ new-unix/System/Posix/User.hsc	2010-08-11 16:02:31.000000000 +0100
@@ -13,6 +13,10 @@
 --
 -----------------------------------------------------------------------------
 
+#ifdef barrelfish_HOST_OS
+module System.Posix.User () where
+#else
+
 module System.Posix.User (
     -- * User environment
     -- ** Querying the user environment
@@ -472,3 +476,5 @@
     if rc == nullPtr && errno /= eOK
        then throwErrno loc
        else return rc
+
+#endif
\ No newline at end of file
