Porting GHC to Barrelfish: unix.2.patch

File unix.2.patch, 18.5 KB (added by rmcilroy, 4 years ago)

Patch for unix library

  • cbits/execvpe.c

    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 new  
    99#include "Rts.h" 
    1010#endif 
    1111 
    12 #if !(defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32)) /* to the end */ 
     12#if !(defined(_MSC_VER) || defined(__MINGW32__) || defined(_WIN32) || defined(barrelfish_HOST_OS)) /* to the end */ 
    1313 
    1414/* Evidently non-Posix. */ 
    1515/* #include "PosixSource.h" */ 
  • cbits/HsUnix.c

    diff -rN -u old-unix/cbits/HsUnix.c new-unix/cbits/HsUnix.c
    old new  
    88 
    99#include "HsUnix.h" 
    1010 
     11#ifdef barrelfish_HOST_OS 
     12int __hsunix_wifexited   (int stat) {  
     13    printf("NYI __hsunix_wifexited\n"); 
     14    return -1;  
     15} 
     16int __hsunix_wexitstatus (int stat) {  
     17    printf("NYI __hsunix_wexitstatus\n"); 
     18    return -1;  
     19} 
     20int __hsunix_wifsignaled (int stat) {  
     21    printf("NYI __hsunix_wifsignaled\n"); 
     22    return -1;  
     23} 
     24int __hsunix_wtermsig    (int stat) {  
     25    printf("NYI __hsunix_wtermsig\n"); 
     26    return -1;  
     27} 
     28int __hsunix_wifstopped  (int stat) {  
     29    printf("NYI __hsunix_wifstopped\n"); 
     30    return -1;  
     31} 
     32int __hsunix_wstopsig    (int stat) {  
     33    printf("NYI __hsunix_wstopsig\n"); 
     34    return -1;  
     35} 
     36#else 
    1137int __hsunix_wifexited   (int stat) { return WIFEXITED(stat); } 
    1238int __hsunix_wexitstatus (int stat) { return WEXITSTATUS(stat); } 
    1339int __hsunix_wifsignaled (int stat) { return WIFSIGNALED(stat); } 
    1440int __hsunix_wtermsig    (int stat) { return WTERMSIG(stat); } 
    1541int __hsunix_wifstopped  (int stat) { return WIFSTOPPED(stat); } 
    1642int __hsunix_wstopsig    (int stat) { return WSTOPSIG(stat); } 
     43#endif 
    1744 
    1845#ifdef HAVE_RTLDNEXT 
    1946void *__hsunix_rtldNext (void) {return RTLD_NEXT;}  
     
    3057int __hsunix_SIGWINCH() { return SIGWINCH; } 
    3158#endif 
    3259 
     60#ifndef barrelfish_HOST_OS 
    3361// lstat is a macro on some platforms, so we need a wrapper: 
    3462int __hsunix_lstat(const char *path, struct stat *buf)  
    3563{  
     
    4169{  
    4270    return mknod(pathname,mode,dev); 
    4371} 
     72#endif 
    4473 
    4574#ifdef HAVE_GETPWENT 
    4675// getpwent is a macro on some platforms, so we need a wrapper: 
     
    88117    return time(tloc); 
    89118} 
    90119 
     120#ifndef barrelfish_HOST_OS 
    91121// times is a macro on some platforms, so we need a wrapper: 
    92122clock_t __hsunix_times(struct tms *tp) 
    93123{ 
    94124    return times(tp); 
    95125} 
     126#endif 
    96127 
    97128#ifdef HAVE_PTSNAME 
    98129// I cannot figure out how to make the definitions of the following 
     
    128159#endif 
    129160} 
    130161 
    131 #if !defined(__MINGW32__) 
     162#if !defined(__MINGW32__) && !defined(barrrelfish_HOST_OS) 
    132163int __hscore_mkstemp(char *filetemplate) { 
    133164    return (mkstemp(filetemplate)); 
    134165} 
    135166#endif 
    136167 
    137 #if !defined(__MINGW32__) && !defined(irix_HOST_OS) 
     168#if !defined(__MINGW32__) && !defined(irix_HOST_OS) && !defined(barrelfish_HOST_OS) 
    138169int __hscore_getrlimit(int resource, struct rlimit *rlim) { 
    139170    return (getrlimit(resource, rlim)); 
    140171} 
  • config.sub

    diff -rN -u old-unix/config.sub new-unix/config.sub
    old new  
    44#   2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software Foundation, 
    55#   Inc. 
    66 
    7 timestamp='2006-07-02' 
     7timestamp='2010-08-10' 
    88 
    99# This file is (in principle) common to ALL GNU software. 
    1010# The presence of a machine in this file suggests that SOME GNU software 
     
    13441344        -zvmoe) 
    13451345                os=-zvmoe 
    13461346                ;; 
     1347        -barrelfish) 
     1348                os=-barrelfish 
     1349                ;; 
    13471350        -none) 
    13481351                ;; 
    13491352        *) 
  • include/execvpe.h

    diff -rN -u old-unix/include/execvpe.h new-unix/include/execvpe.h
    old new  
    1414 
    1515#include <errno.h> 
    1616#include <sys/types.h> 
    17 #if HAVE_SYS_WAIT_H 
     17#if HAVE_SYS_WAIT_H && !defined(BARRELFISH) 
    1818#include <sys/wait.h> 
    1919#endif 
    2020 
    21 #if !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(_WIN32) 
     21#if !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(_WIN32) && !defined(BARRELFISH) 
    2222extern int execvpe(char *name, char *const argv[], char **envp); 
    2323extern void pPrPr_disableITimers (void); 
    2424#endif 
  • include/HsUnix.h

    diff -rN -u old-unix/include/HsUnix.h new-unix/include/HsUnix.h
    old new  
    121121int __hsunix_SIGWINCH(); 
    122122#endif 
    123123 
     124#ifndef barrelfish_HOST_OS 
    124125// lstat is a macro on some platforms, so we need a wrapper: 
    125126int __hsunix_lstat(const char *path, struct stat *buf); 
    126127 
    127128// lstat is a macro on some platforms, so we need a wrapper: 
    128129int __hsunix_mknod(const char *pathname, mode_t mode, dev_t dev); 
     130#endif  
    129131 
    130132#ifdef HAVE_GETPWENT 
    131133// getpwent is a macro on some platforms, so we need a wrapper: 
     
    155157// time is a macro on some platforms, so we need a wrapper: 
    156158time_t __hsunix_time(time_t *); 
    157159 
     160 
     161#ifndef barrelfish_HOST_OS 
    158162// times is a macro on some platforms, so we need a wrapper: 
    159163clock_t __hsunix_times(struct tms *); 
     164#endif  
    160165 
    161166#ifdef HAVE_PTSNAME 
    162167// I cannot figure out how to make the definitions of the following 
     
    171176// push a SVR4 STREAMS module; do nothing if STREAMS not available 
    172177int __hsunix_push_module(int fd, const char *module); 
    173178 
    174 #if !defined(__MINGW32__) 
     179#if !defined(__MINGW32__) && !defined(barrelfish_HOST_OS) 
    175180int __hscore_mkstemp(char *filetemplate); 
    176181#endif 
    177182 
    178 #if !defined(__MINGW32__) && !defined(irix_HOST_OS) 
     183#if !defined(__MINGW32__) && !defined(irix_HOST_OS) && !defined(barrelfish_HOST_OS) 
    179184int __hscore_getrlimit(int resource, struct rlimit *rlim); 
    180185int __hscore_setrlimit(int resource, struct rlimit *rlim); 
    181186#endif 
  • System/Posix/Files.hsc

    diff -rN -u old-unix/System/Posix/Files.hsc new-unix/System/Posix/Files.hsc
    old new  
    321321  unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_uid) 
    322322fileGroup (FileStatus stat) = 
    323323  unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_gid) 
     324#ifdef barrelfish_HOST_OS 
     325specialDeviceID (FileStatus stat) = 0 
     326#else 
    324327specialDeviceID (FileStatus stat) = 
    325328  unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_rdev) 
     329#endif 
    326330fileSize (FileStatus stat) = 
    327331  unsafePerformIO $ withForeignPtr stat $ (#peek struct stat, st_size) 
    328332accessTime (FileStatus stat) = 
     
    408412-- 
    409413-- Note: calls @mkfifo@. 
    410414createNamedPipe :: FilePath -> FileMode -> IO () 
     415#ifdef barrelfish_HOST_OS 
     416createNamedPipe name mode = do 
     417    return () 
     418#else 
    411419createNamedPipe name mode = do 
    412420  withCString name $ \s ->  
    413421    throwErrnoPathIfMinus1_ "createNamedPipe" name (c_mkfifo s mode) 
     422#endif 
    414423 
    415424-- | @createDevice path mode dev@ creates either a regular or a special file 
    416425-- depending on the value of @mode@ (and @dev@).  @mode@ will normally be either 
     
    436445-- 
    437446-- Note: calls @link@. 
    438447createLink :: FilePath -> FilePath -> IO () 
     448#ifdef barrelfish_HOST_OS 
     449createLink name1 name2 = do 
     450  return () 
     451#else 
    439452createLink name1 name2 = 
    440453  withCString name1 $ \s1 -> 
    441454  withCString name2 $ \s2 -> 
    442455  throwErrnoPathIfMinus1_ "createLink" name1 (c_link s1 s2) 
     456#endif 
    443457 
    444458-- | @removeLink path@ removes the link named @path@. 
    445459-- 
     
    551565 
    552566-- ----------------------------------------------------------------------------- 
    553567-- utime() 
     568#ifdef barrelfish_HOST_OS 
     569setFileTimes :: FilePath -> EpochTime -> EpochTime -> IO () 
     570setFileTimes name atime mtime = do 
     571  return () 
    554572 
     573touchFile :: FilePath -> IO () 
     574touchFile name = do 
     575  return () 
     576 
     577#else 
    555578-- | @setFileTimes path atime mtime@ sets the access and modification times 
    556579-- associated with file @path@ to @atime@ and @mtime@, respectively. 
    557580-- 
     
    573596  withCString name $ \s -> 
    574597   throwErrnoPathIfMinus1_ "touchFile" name (c_utime s nullPtr) 
    575598 
     599#endif 
     600 
    576601-- ----------------------------------------------------------------------------- 
    577602-- Setting file sizes 
    578603 
     
    621646  | SyncIOAvailable               {- _PC_SYNC_IO          -} 
    622647 
    623648pathVarConst :: PathVar -> CInt 
     649#ifdef barrelfish_HOST_OS 
     650pathVarConst v = 0 
     651#else 
    624652pathVarConst v = case v of 
    625653        LinkLimit                       -> (#const _PC_LINK_MAX) 
    626654        InputLineLimit                  -> (#const _PC_MAX_CANON) 
     
    661689#else 
    662690        SymbolicLinkLimit       -> error "_PC_SYMLINK_MAX not available" 
    663691#endif 
     692#endif 
    664693 
    665694 
    666695-- | @getPathVar var path@ obtains the dynamic value of the requested 
  • System/Posix/IO.hsc

    diff -rN -u old-unix/System/Posix/IO.hsc new-unix/System/Posix/IO.hsc
    old new  
    4141    fdSeek, 
    4242 
    4343    -- ** File options 
     44#ifdef HAVE_FCNTL_H 
    4445    FdOption(..), 
    4546    queryFdOption, 
    4647    setFdOption, 
     48#endif 
    4749 
    4850    -- ** Locking 
     51#ifndef barrelfish_HOST_OS 
    4952    FileLock, 
    5053    LockRequest(..), 
    5154    getLock,  setLock, 
    5255    waitToSetLock, 
     56#endif 
    5357 
    5458    -- ** Pipes 
    5559    createPipe, 
     
    271275  -- state as a result.  
    272276  let fd = haFD h_ 
    273277  flushWriteBufferOnly h_ 
     278#ifndef barrelfish_HOST_OS 
    274279  unlockFile (fromIntegral fd) 
     280#endif 
    275281    -- setting the Handle's fd to (-1) as well as its 'type' 
    276282    -- to closed, is enough to disable the finalizer that 
    277283    -- eventually is run on the Handle. 
     
    294300-- ----------------------------------------------------------------------------- 
    295301-- Fd options 
    296302 
     303#ifdef HAVE_FCNTL_H 
     304 
    297305data FdOption = AppendOnWrite     -- ^O_APPEND 
    298306              | CloseOnExec       -- ^FD_CLOEXEC 
    299307              | NonBlockingRead   -- ^O_NONBLOCK 
     
    335343foreign import ccall unsafe "HsBase.h fcntl_write" 
    336344   c_fcntl_write :: CInt -> CInt -> CLong -> IO CInt 
    337345 
     346#endif  
     347 
    338348-- ----------------------------------------------------------------------------- 
    339349-- Seeking  
    340350 
     
    351361-- ----------------------------------------------------------------------------- 
    352362-- Locking 
    353363 
     364#ifndef barrelfish_HOST_OS 
     365 
    354366data LockRequest = ReadLock 
    355367                 | WriteLock 
    356368                 | Unlock 
     
    421433    throwErrnoIfMinus1_ "waitToSetLock"  
    422434        (c_fcntl_lock fd (#const F_SETLKW) p_flock) 
    423435 
     436#endif 
     437 
    424438-- ----------------------------------------------------------------------------- 
    425439-- fd{Read,Write} 
    426440 
  • System/Posix/Process.hsc

    diff -rN -u old-unix/System/Posix/Process.hsc new-unix/System/Posix/Process.hsc
    old new  
    4444    getProcessTimes, 
    4545 
    4646    -- ** Scheduling priority 
     47#ifndef barrelfish_HOST_OS 
    4748    nice, 
    4849    getProcessPriority, 
    4950    getProcessGroupPriority, 
     
    5152    setProcessPriority, 
    5253    setProcessGroupPriority, 
    5354    setUserPriority, 
     55#endif 
    5456 
    5557    -- ** Process status 
    5658    ProcessStatus(..), 
     
    157159-- | 'getProcessTimes' calls @times@ to obtain time-accounting 
    158160--   information for the current process and its children. 
    159161getProcessTimes :: IO ProcessTimes 
     162#ifdef barrelfish_HOST_OS 
     163getProcessTimes = do 
     164     return (ProcessTimes{ elapsedTime     = 0, 
     165                           userTime        = 0, 
     166                           systemTime      = 0, 
     167                           childUserTime   = 0, 
     168                           childSystemTime = 0 
     169                          }) 
     170#else 
    160171getProcessTimes = do 
    161172   allocaBytes (#const sizeof(struct tms)) $ \p_tms -> do 
    162173     elapsed <- throwErrnoIfMinus1 "getProcessTimes" (c_times p_tms) 
     
    170181                           childUserTime   = cut, 
    171182                           childSystemTime = cst 
    172183                          }) 
     184#endif 
    173185 
    174186type CTms = () 
    175187 
     
    179191-- ----------------------------------------------------------------------------- 
    180192-- Process scheduling priority 
    181193 
     194#ifndef barrelfish_HOST_OS 
     195 
    182196nice :: Int -> IO () 
    183197nice prio = do 
    184198  resetErrno 
     
    231245foreign import ccall unsafe "setpriority" 
    232246  c_setpriority :: CInt -> CInt -> CInt -> IO CInt 
    233247 
     248#endif 
     249 
    234250-- ----------------------------------------------------------------------------- 
    235251-- Forking, execution 
    236252 
     
    361377 
    362378waitOptions :: Bool -> Bool -> CInt 
    363379--             block   stopped 
     380#ifdef barrelfish_HOST_OS 
     381waitOptions _ _ = 0 
     382#else 
    364383waitOptions False False = (#const WNOHANG) 
    365384waitOptions False True  = (#const (WNOHANG|WUNTRACED)) 
    366385waitOptions True  False = 0 
    367386waitOptions True  True  = (#const WUNTRACED) 
     387#endif  
    368388 
    369389-- Turn a (ptr to a) wait status into a ProcessStatus 
    370390 
  • System/Posix/Resource.hsc

    diff -rN -u old-unix/System/Posix/Resource.hsc new-unix/System/Posix/Resource.hsc
    old new  
    1919-- 
    2020----------------------------------------------------------------------------- 
    2121 
     22#ifdef barrelfish_HOST_OS 
     23module System.Posix.Resource () where 
     24#else  
     25 
    2226module System.Posix.Resource ( 
    2327    -- * Resource Limits 
    2428    ResourceLimit(..), ResourceLimits(..), Resource(..), 
     
    152156showRLim ResourceLimitUnknown  = "unknown" 
    153157showRLim (ResourceLimit other)  = show other 
    154158-} 
     159 
     160#endif 
     161 No newline at end of file 
  • System/Posix/Semaphore.hsc

    diff -rN -u old-unix/System/Posix/Semaphore.hsc new-unix/System/Posix/Semaphore.hsc
    old new  
    1414-- 
    1515----------------------------------------------------------------------------- 
    1616 
     17#ifdef barrelfish_HOST_OS 
     18module System.Posix.Semaphore () where 
     19#else 
     20 
    1721module System.Posix.Semaphore 
    1822    (OpenSemFlags(..), Semaphore(),  
    1923     semOpen, semUnlink, semWait, semTryWait, semThreadWait,  
     
    126130        sem_post :: Ptr () -> IO CInt 
    127131foreign import ccall safe "sem_getvalue" 
    128132        sem_getvalue :: Ptr () -> Ptr CInt -> IO Int 
     133#endif 
     134 No newline at end of file 
  • System/Posix/SharedMem.hsc

    diff -rN -u old-unix/System/Posix/SharedMem.hsc new-unix/System/Posix/SharedMem.hsc
    old new  
    1515-- 
    1616----------------------------------------------------------------------------- 
    1717 
     18#ifdef barrelfish_HOST_OS 
     19module System.Posix.SharedMem () where 
     20#else 
     21 
    1822module System.Posix.SharedMem 
    1923    (ShmOpenFlags(..), shmOpen, shmUnlink) 
    2024    where 
     
    8488foreign import ccall unsafe "shm_unlink" 
    8589        shm_unlink :: CString -> IO CInt 
    8690#endif 
     91 
     92#endif 
     93 No newline at end of file 
  • System/Posix/Signals.hsc

    diff -rN -u old-unix/System/Posix/Signals.hsc new-unix/System/Posix/Signals.hsc
    old new  
    7171 
    7272  -- * Signal sets 
    7373  SignalSet, 
     74#ifndef barrelfish_HOST_OS 
    7475  emptySignalSet, fullSignalSet,  
    7576  addSignal, deleteSignal, inSignalSet, 
    7677 
     
    8283 
    8384  -- * Waiting for signals 
    8485  getPendingSignals, 
    85 #ifndef cygwin32_HOST_OS 
     86#endif 
     87#if !defined(cygwin32_HOST_OS) && !defined(barrelfish_HOST_OS) 
    8688  awaitSignal, 
    8789#endif 
    8890 
     
    348350               -> Maybe SignalSet       -- ^ other signals to block 
    349351               -> IO Handler            -- ^ old handler 
    350352 
    351 #ifdef __PARALLEL_HASKELL__ 
     353#if defined (__PARALLEL_HASKELL__) || defined(barrelfish_HOST_OS) 
    352354installHandler =  
    353355  error "installHandler: not available for Parallel Haskell" 
    354356#else 
     
    482484 
    483485newtype SignalSet = SignalSet (ForeignPtr CSigset) 
    484486 
     487#ifndef barrelfish_HOST_OS 
    485488emptySignalSet :: SignalSet 
    486489emptySignalSet = unsafePerformIO $ do 
    487490  fp <- mallocForeignPtrBytes sizeof_sigset_t 
     
    558561  withForeignPtr fp $ \p ->  
    559562   throwErrnoIfMinus1_ "getPendingSignals" (c_sigpending p) 
    560563  return (SignalSet fp) 
     564#endif 
    561565 
    562 #ifndef cygwin32_HOST_OS 
     566#if !defined(cygwin32_HOST_OS) && !defined(barrelfish_HOST_OS) 
    563567 
    564568-- | @awaitSignal iset@ suspends execution until an interrupt is received. 
    565569-- If @iset@ is @Just s@, @awaitSignal@ calls @sigsuspend@, installing 
  • System/Posix/Terminal.hsc

    diff -rN -u old-unix/System/Posix/Terminal.hsc new-unix/System/Posix/Terminal.hsc
    old new  
    1414-- 
    1515----------------------------------------------------------------------------- 
    1616 
     17#ifdef barrelfish_HOST_OS 
     18module System.Posix.Terminal () where 
     19#else  
     20 
    1721module System.Posix.Terminal ( 
    1822  -- * Terminal support 
    1923 
     
    6670  -- ** Pseudoterminal operations 
    6771  openPseudoTerminal, 
    6872  getSlaveTerminalName 
     73 
    6974  ) where 
    7075 
    7176#include "HsUnix.h" 
     
    804809    _ <- action p1 
    805810    return () 
    806811  return $ makeTerminalAttributes fp1 
     812 
     813#endif 
     814 No newline at end of file 
  • System/Posix/Unistd.hsc

    diff -rN -u old-unix/System/Posix/Unistd.hsc new-unix/System/Posix/Unistd.hsc
    old new  
    6868           } 
    6969 
    7070getSystemID :: IO SystemID 
     71#ifdef barrelfish_HOST_OS 
     72getSystemID = do 
     73    return (SystemID { systemName = "", 
     74                       nodeName   = "", 
     75                       release    = "", 
     76                       version    = "", 
     77                       machine    = "" 
     78                     }) 
     79#else 
    7180getSystemID = do 
    7281  allocaBytes (#const sizeof(struct utsname)) $ \p_sid -> do 
    7382    throwErrnoIfMinus1_ "getSystemID" (c_uname p_sid) 
     
    8291                       version    = ver, 
    8392                       machine    = mach 
    8493                     }) 
     94#endif 
    8595 
    8696foreign import ccall unsafe "uname" 
    8797   c_uname :: Ptr CUtsname -> IO CInt 
     
    176186        -- ToDo: lots more 
    177187 
    178188getSysVar :: SysVar -> IO Integer 
     189#ifdef barrelfish_HOST_OS 
     190getSysVar v = return (-1) 
     191#else 
    179192getSysVar v = 
    180193    case v of 
    181194      ArgumentLimit -> sysconf (#const _SC_ARG_MAX) 
     
    194207 
    195208foreign import ccall unsafe "sysconf" 
    196209  c_sysconf :: CInt -> IO CLong 
     210#endif 
     211 No newline at end of file 
  • System/Posix/User.hsc

    diff -rN -u old-unix/System/Posix/User.hsc new-unix/System/Posix/User.hsc
    old new  
    1313-- 
    1414----------------------------------------------------------------------------- 
    1515 
     16#ifdef barrelfish_HOST_OS 
     17module System.Posix.User () where 
     18#else 
     19 
    1620module System.Posix.User ( 
    1721    -- * User environment 
    1822    -- ** Querying the user environment 
     
    472476    if rc == nullPtr && errno /= eOK 
    473477       then throwErrno loc 
    474478       else return rc 
     479 
     480#endif 
     481 No newline at end of file