Commit 97497bae authored by Ben Gamari's avatar Ben Gamari 🐢

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.
parent 6060003e
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment