diff options
-rw-r--r-- | includes/rts/FileLock.h | 16 | ||||
-rw-r--r-- | libraries/base/GHC/IO/FD.hs | 1 | ||||
-rw-r--r-- | libraries/base/GHC/IO/Windows/Handle.hsc | 1 |
3 files changed, 18 insertions, 0 deletions
diff --git a/includes/rts/FileLock.h b/includes/rts/FileLock.h index 84f1f63881..baf9f680fb 100644 --- a/includes/rts/FileLock.h +++ b/includes/rts/FileLock.h @@ -11,6 +11,22 @@ * * ---------------------------------------------------------------------------*/ +/* Note [RTS File locking] + * ~~~~~~~~~~~~~~~~~~~~~~~ + * + * The Haskell report dictates certain file locking behaviour. + * This is specified in the Haskell98 report under: 21.2.3 File locking + * + * GHC does not rely on the platform it's on to implement this. + * Instead we keep track of locked files in a data structure in + * the RTS. This file provides the interface to this data structure. + * + * In the base librarie we then use this interface to "lock" files. + * This means it's very much still possible for users outside of the + * rts/base library to open the files in question even if they are + * locked. + * */ + #pragma once #include "Stg.h" diff --git a/libraries/base/GHC/IO/FD.hs b/libraries/base/GHC/IO/FD.hs index 9e1a8cf08e..4245bf0b26 100644 --- a/libraries/base/GHC/IO/FD.hs +++ b/libraries/base/GHC/IO/FD.hs @@ -264,6 +264,7 @@ mkFD fd iomode mb_stat is_socket is_nonblock = do RegularFile -> do -- On Windows we need an additional call to get a unique device id -- and inode, since fstat just returns 0 for both. + -- See also Note [RTS File locking] (unique_dev, unique_ino) <- getUniqueFileInfo fd dev ino r <- lockFile (fromIntegral fd) unique_dev unique_ino (fromBool write) diff --git a/libraries/base/GHC/IO/Windows/Handle.hsc b/libraries/base/GHC/IO/Windows/Handle.hsc index 1efabb3dbd..4d7e3e393f 100644 --- a/libraries/base/GHC/IO/Windows/Handle.hsc +++ b/libraries/base/GHC/IO/Windows/Handle.hsc @@ -818,6 +818,7 @@ openFile' filepath iomode non_blocking tmp_opts = case _type of -- Regular files need to be locked. + -- See also Note [RTS File locking] RegularFile -> do optimizeFileAccess h -- Set a few optimization flags on file handles. (unique_dev, unique_ino) <- getUniqueFileInfo hwnd |