From f209e6672fe33235bd1d4c20c87894021cf3bbc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Hamb=C3=BCchen?= Date: Thu, 23 Nov 2017 13:17:24 -0500 Subject: base: fdReady(): Fix timeouts > ~49 days overflowing. Fixes #14262. On 64-bit UNIX and Windows, Haskell `Int` has 64 bits but C `int msecs` has 32 bits, resulting in an overflow. This commit fixes it by switching fdReady() to take int64_t, into which a Haskell `Int` will always fit. (Note we could not switch to `long long` because that is 32 bit on 64-bit Windows machines.) Further, to be able to actually wait longer than ~49 days, we put loops around the waiting syscalls (they all accept only 32-bit integers). Note the timer signal would typically interrupt the syscalls before the ~49 days are over, but you can run Haskell programs without the timer signal, an we want it to be correct in all cases. Reviewers: bgamari, austin, hvr, NicolasT, Phyx Reviewed By: bgamari, Phyx Subscribers: syd, Phyx, rwbarton, thomie GHC Trac Issues: #14262 Differential Revision: https://phabricator.haskell.org/D4011 --- libraries/base/include/HsBase.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libraries/base/include/HsBase.h') diff --git a/libraries/base/include/HsBase.h b/libraries/base/include/HsBase.h index 0fe5805a64..748e3577ce 100644 --- a/libraries/base/include/HsBase.h +++ b/libraries/base/include/HsBase.h @@ -152,7 +152,7 @@ extern HsWord64 getMonotonicUSec(void); #endif /* in inputReady.c */ -extern int fdReady(int fd, int write, int msecs, int isSock); +extern int fdReady(int fd, int write, int64_t msecs, int isSock); /* ----------------------------------------------------------------------------- INLINE functions. -- cgit v1.2.1 From 430d1f6a6ea37dd53887391c060ce53be792336f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niklas=20Hamb=C3=BCchen?= Date: Mon, 11 Dec 2017 13:06:33 -0500 Subject: fdReady: Use C99 bools / CBool in signature Reviewers: bgamari, Phyx, austin, hvr, simonmar Reviewed By: bgamari Subscribers: syd, rwbarton, thomie Differential Revision: https://phabricator.haskell.org/D4041 --- libraries/base/include/HsBase.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'libraries/base/include/HsBase.h') diff --git a/libraries/base/include/HsBase.h b/libraries/base/include/HsBase.h index 748e3577ce..13640c590e 100644 --- a/libraries/base/include/HsBase.h +++ b/libraries/base/include/HsBase.h @@ -24,6 +24,7 @@ #include "HsFFI.h" +#include #include #include #include @@ -152,7 +153,7 @@ extern HsWord64 getMonotonicUSec(void); #endif /* in inputReady.c */ -extern int fdReady(int fd, int write, int64_t msecs, int isSock); +extern int fdReady(int fd, bool write, int64_t msecs, bool isSock); /* ----------------------------------------------------------------------------- INLINE functions. @@ -288,7 +289,7 @@ __hscore_ftruncate( int fd, off_t where ) return _chsize(fd,where); #else // ToDo: we should use _chsize_s() on Windows which allows a 64-bit -// offset, but it doesn't seem to be available from mingw at this time +// offset, but it doesn't seem to be available from mingw at this time // --SDM (01/2008) #error at least ftruncate or _chsize functions are required to build #endif -- cgit v1.2.1 From 4de585a5c1ac3edc2914cebcac1753b514051a89 Mon Sep 17 00:00:00 2001 From: Tamar Christina Date: Thu, 29 Mar 2018 14:22:09 +0100 Subject: Remove MAX_PATH restrictions from RTS, I/O manager and various utilities Summary: This shims out fopen and sopen so that they use modern APIs under the hood along with namespaced paths. This lifts the MAX_PATH restrictions from Haskell programs and makes the new limit ~32k. There are only some slight caveats that have been documented. Some utilities have not been upgraded such as lndir, since all these things are different cabal packages I have been forced to copy the source in different places which is less than ideal. But it's the only way to keep sdist working. Test Plan: ./validate Reviewers: hvr, bgamari, erikd, simonmar Reviewed By: bgamari Subscribers: rwbarton, thomie, carter GHC Trac Issues: #10822 Differential Revision: https://phabricator.haskell.org/D4416 --- libraries/base/include/HsBase.h | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'libraries/base/include/HsBase.h') diff --git a/libraries/base/include/HsBase.h b/libraries/base/include/HsBase.h index 13640c590e..d5884473ca 100644 --- a/libraries/base/include/HsBase.h +++ b/libraries/base/include/HsBase.h @@ -520,13 +520,25 @@ extern void* __hscore_get_saved_termios(int fd); extern void __hscore_set_saved_termios(int fd, void* ts); #if defined(_WIN32) +/* Defined in fs.c. */ +extern int __hs_swopen (const wchar_t* filename, int oflag, int shflag, + int pmode); + INLINE int __hscore_open(wchar_t *file, int how, mode_t mode) { + int result = -1; if ((how & O_WRONLY) || (how & O_RDWR) || (how & O_APPEND)) - return _wsopen(file,how | _O_NOINHERIT,_SH_DENYNO,mode); + result = __hs_swopen(file,how | _O_NOINHERIT,_SH_DENYNO,mode); // _O_NOINHERIT: see #2650 else - return _wsopen(file,how | _O_NOINHERIT,_SH_DENYNO,mode); + result = __hs_swopen(file,how | _O_NOINHERIT,_SH_DENYNO,mode); // _O_NOINHERIT: see #2650 + + /* This call is very important, otherwise the I/O system will not propagate + the correct error for why it failed. */ + if (result == -1) + maperrno (); + + return result; } #else INLINE int __hscore_open(char *file, int how, mode_t mode) { -- cgit v1.2.1