Commit 2d1beb1e authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari

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
parent 3dbd2b09
......@@ -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++;
......
......@@ -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);
......
......@@ -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));
......
......@@ -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);
......
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