diff options
author | Ben Gamari <ben@smart-cactus.org> | 2020-01-24 11:17:55 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2020-02-14 10:16:36 -0500 |
commit | 97497baeb70c443030e9e0c59abf4930679b4f82 (patch) | |
tree | f035b6562221523e49733e659a5f45457d55142f | |
parent | 6060003e4f95101adaef0b2c7f26154c59f2e83a (diff) | |
download | haskell-97497baeb70c443030e9e0c59abf4930679b4f82.tar.gz |
base: Always clamp reads/writes to 2GB in length
Previously we did this only on Darwin due to #17414. However, even on
other platforms >2GB writes are on shaky ground. POSIX explicitly says
that the result is implementation-specified and Linux will write at most
0x7ffff000, even on 64-bit platforms. Moreover, getting the sign
of the syscall result correct is tricky, as demonstrated by the fact
that T17414 currently fails on FreeBSD.
For simplicity we now just uniformly clamp to 0x7ffff000 on all
platforms.
-rw-r--r-- | libraries/base/GHC/IO/FD.hs | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/libraries/base/GHC/IO/FD.hs b/libraries/base/GHC/IO/FD.hs index a889601be9..ad9b11564a 100644 --- a/libraries/base/GHC/IO/FD.hs +++ b/libraries/base/GHC/IO/FD.hs @@ -67,16 +67,13 @@ import System.Posix.Types c_DEBUG_DUMP :: Bool c_DEBUG_DUMP = False --- Darwin limits the length of writes to 2GB. See --- #17414. +-- Darwin limits the length of writes to 2GB. See #17414. +-- Moreover, Linux will only transfer up to 0x7ffff000 and interpreting the +-- result of write/read is tricky above 2GB due to its signed type. For +-- simplicity we therefore clamp on all platforms. clampWriteSize, clampReadSize :: Int -> Int -#if defined(darwin_HOST_OS) -clampWriteSize = min 0x7fffffff -clampReadSize = min 0x7fffffff -#else -clampWriteSize = id -clampReadSize = id -#endif +clampWriteSize = min 0x7ffff000 +clampReadSize = min 0x7ffff000 -- ----------------------------------------------------------------------------- -- The file-descriptor IO device |