diff options
author | Ben Gamari <bgamari.foss@gmail.com> | 2016-12-17 18:08:00 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2016-12-17 18:09:40 -0500 |
commit | 2d1beb1ec84c2d22c6be83944ef4ea8626abd76a (patch) | |
tree | 2a722f9d0e9abf2dc40c35e387c3df0fd82729c5 /rts/win32 | |
parent | 3dbd2b097aeb9217f4a7fc87e610e6983ebbce7b (diff) | |
download | haskell-2d1beb1ec84c2d22c6be83944ef4ea8626abd76a.tar.gz |
rts/win32/IOManager: Fix integer types
This code has been broken on 64-bit systems for some time: the length
and timeout arguments of `addIORequest` and `addDelayRequest`,
respectively, were declared as `int`. However, they were passed Haskell
integers from their respective primops. Integer overflow and madness
ensued. This resulted in #7325 and who knows what else.
Also, there were a few left-over `BOOL`s in here which were not passed
to Windows system calls; these were changed to C99 `bool`s.
However, there is still a bit of signedness inconsistency within the
`delay#` call-chain,
* `GHC.Conc.IO.threadDelay` and the `delay#` primop accept `Int`
arguments
* The `delay#` implementation in `PrimOps.cmm` expects the timeout as
a `W_`
* `AsyncIO.c:addDelayRequest` expects an `HsInt` (was `int` prior to
this patch)
* `IOManager.c:AddDelayRequest` expects an `HsInt`` (was `int`)
* The Windows `Sleep` function expects a `DWORD` (which is unsigned)
Test Plan: Validate on Windows
Reviewers: erikd, austin, simonmar, Phyx
Reviewed By: Phyx
Subscribers: thomie
Differential Revision: https://phabricator.haskell.org/D2861
GHC Trac Issues: #7325
Diffstat (limited to 'rts/win32')
-rw-r--r-- | rts/win32/AsyncIO.c | 16 | ||||
-rw-r--r-- | rts/win32/AsyncIO.h | 8 | ||||
-rw-r--r-- | rts/win32/IOManager.c | 12 | ||||
-rw-r--r-- | rts/win32/IOManager.h | 18 |
4 files changed, 27 insertions, 27 deletions
diff --git a/rts/win32/AsyncIO.c b/rts/win32/AsyncIO.c index 6a05f680db..9e6594f601 100644 --- a/rts/win32/AsyncIO.c +++ b/rts/win32/AsyncIO.c @@ -40,8 +40,8 @@ typedef struct CompletedReq { unsigned int reqID; - int len; - int errCode; + HsInt len; + HsInt errCode; } CompletedReq; #define MAX_REQUESTS 200 @@ -58,9 +58,9 @@ static int issued_reqs; static void onIOComplete(unsigned int reqID, int fd STG_UNUSED, - int len, + HsInt len, void* buf STG_UNUSED, - int errCode) + HsInt errCode) { DWORD dwRes; /* Deposit result of request in queue/table..when there's room. */ @@ -106,9 +106,9 @@ onIOComplete(unsigned int reqID, unsigned int addIORequest(int fd, - int forWriting, - int isSock, - int len, + bool forWriting, + bool isSock, + HsInt len, char* buf) { EnterCriticalSection(&queue_lock); @@ -122,7 +122,7 @@ addIORequest(int fd, } unsigned int -addDelayRequest(int usecs) +addDelayRequest(HsInt usecs) { EnterCriticalSection(&queue_lock); issued_reqs++; diff --git a/rts/win32/AsyncIO.h b/rts/win32/AsyncIO.h index bedbf5b67b..3737db087a 100644 --- a/rts/win32/AsyncIO.h +++ b/rts/win32/AsyncIO.h @@ -10,11 +10,11 @@ extern unsigned int addIORequest(int fd, - int forWriting, - int isSock, - int len, + bool forWriting, + bool isSock, + HsInt len, char* buf); -extern unsigned int addDelayRequest(int usecs); +extern unsigned int addDelayRequest(HsInt usecs); extern unsigned int addDoProcRequest(void* proc, void* param); extern int startupAsyncIO(void); extern void shutdownAsyncIO(bool wait_threads); diff --git a/rts/win32/IOManager.c b/rts/win32/IOManager.c index f25b006c4d..c5cae75366 100644 --- a/rts/win32/IOManager.c +++ b/rts/win32/IOManager.c @@ -284,7 +284,7 @@ IOWorkerProc(PVOID param) } static -BOOL +bool NewIOWorkerThread(IOManagerState* iom) { unsigned threadId; @@ -296,7 +296,7 @@ NewIOWorkerThread(IOManagerState* iom) &threadId) ); } -BOOL +bool StartIOManager(void) { HANDLE hExit; @@ -429,9 +429,9 @@ depositWorkItem( unsigned int reqID, */ int AddIORequest ( int fd, - BOOL forWriting, - BOOL isSocket, - int len, + bool forWriting, + bool isSocket, + HsInt len, char* buffer, CompletionProc onCompletion) { @@ -461,7 +461,7 @@ AddIORequest ( int fd, * the request queue. */ BOOL -AddDelayRequest ( unsigned int usecs, +AddDelayRequest ( HsInt usecs, CompletionProc onCompletion) { WorkItem* wItem = (WorkItem*)malloc(sizeof(WorkItem)); diff --git a/rts/win32/IOManager.h b/rts/win32/IOManager.h index 94821a8475..01521ca8da 100644 --- a/rts/win32/IOManager.h +++ b/rts/win32/IOManager.h @@ -30,9 +30,9 @@ */ typedef void (*CompletionProc)(unsigned int requestID, int fd, - int len, + HsInt len, void* buf, - int errCode); + HsInt errCode); /* * Asynchronous procedure calls executed by a worker thread @@ -44,11 +44,11 @@ typedef int (*DoProcProc)(void *param); typedef union workData { struct { int fd; - int len; + HsInt len; char *buf; } ioData; struct { - int usecs; + HsInt usecs; } delayData; struct { DoProcProc proc; @@ -80,7 +80,7 @@ extern CompletionProc onComplete; /* * Starting up and shutting down. */ -extern BOOL StartIOManager ( void ); +extern bool StartIOManager ( void ); extern void ShutdownIOManager ( bool wait_threads ); /* @@ -88,13 +88,13 @@ extern void ShutdownIOManager ( bool wait_threads ); * completion routine is supplied, which the worker thread * will invoke upon completion. */ -extern int AddDelayRequest ( unsigned int usecs, +extern int AddDelayRequest ( HsInt usecs, CompletionProc onCompletion); extern int AddIORequest ( int fd, - BOOL forWriting, - BOOL isSocket, - int len, + bool forWriting, + bool isSocket, + HsInt len, char* buffer, CompletionProc onCompletion); |