[commit: ghc] master: rts/win32/IOManager: Fix integer types (2d1beb1)

git at git.haskell.org git at git.haskell.org
Sun Dec 18 01:02:12 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/2d1beb1ec84c2d22c6be83944ef4ea8626abd76a/ghc

>---------------------------------------------------------------

commit 2d1beb1ec84c2d22c6be83944ef4ea8626abd76a
Author: Ben Gamari <bgamari.foss at gmail.com>
Date:   Sat Dec 17 18:08:00 2016 -0500

    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


>---------------------------------------------------------------

2d1beb1ec84c2d22c6be83944ef4ea8626abd76a
 rts/win32/AsyncIO.c   | 16 ++++++++--------
 rts/win32/AsyncIO.h   |  8 ++++----
 rts/win32/IOManager.c | 12 ++++++------
 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 6a05f68..9e6594f 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 bedbf5b..3737db0 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 f25b006..c5cae75 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 94821a8..01521ca 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);
 



More information about the ghc-commits mailing list