WaitForMultipleObjectsEx will not take up to MAXIMUM_WAIT_OBJECTS

Bryan Mayland bmayland at leoninedev.com
Tue Mar 21 15:45:40 CST 2006


As discussed in the wine-devel thread of the same name, this patch fixes 
that WaitForMultipleObjects will not correctly wait on up to 
MAXIMUM_WAIT_OBJECTS (it supports 63 instead of 64).  Only kernel32 was 
affected; ntdll was not as it already had the correct comparison.  I've 
also included a test case to prevent regressions. 


-------------- next part --------------
? max_wait_objects_fix.diff
Index: dlls/kernel/sync.c
===================================================================
RCS file: /home/wine/wine/dlls/kernel/sync.c,v
retrieving revision 1.101
diff -u -r1.101 sync.c
--- dlls/kernel/sync.c	17 Jan 2006 12:38:38 -0000	1.101
+++ dlls/kernel/sync.c	21 Mar 2006 21:41:07 -0000
@@ -173,7 +173,7 @@
     HANDLE hloc[MAXIMUM_WAIT_OBJECTS];
     unsigned int i;
 
-    if (count >= MAXIMUM_WAIT_OBJECTS)
+    if (count > MAXIMUM_WAIT_OBJECTS)
     {
         SetLastError(ERROR_INVALID_PARAMETER);
         return WAIT_FAILED;
Index: dlls/kernel/tests/sync.c
===================================================================
RCS file: /home/wine/wine/dlls/kernel/tests/sync.c,v
retrieving revision 1.3
diff -u -r1.3 sync.c
--- dlls/kernel/tests/sync.c	12 Dec 2005 17:14:27 -0000	1.3
+++ dlls/kernel/tests/sync.c	21 Mar 2006 21:41:07 -0000
@@ -31,7 +31,8 @@
     DWORD (WINAPI *pSignalObjectAndWait)(HANDLE, HANDLE, DWORD, BOOL);
     HMODULE kernel32;
     DWORD r;
-    HANDLE event[2], semaphore[2], file;
+    int i;
+    HANDLE event[2], maxevents[MAXIMUM_WAIT_OBJECTS], semaphore[2], file;
 
     kernel32 = GetModuleHandle("kernel32");
     pSignalObjectAndWait = (void*) GetProcAddress(kernel32, "SignalObjectAndWait");
@@ -83,6 +84,21 @@
     CloseHandle(event[0]);
     CloseHandle(event[1]);
 
+    /* create the maximum number of events and make sure 
+     * we can wait on that many */
+    for (i=0; i<MAXIMUM_WAIT_OBJECTS; i++)
+        maxevents[i] = INVALID_HANDLE_VALUE;
+    for (i=0; i<MAXIMUM_WAIT_OBJECTS; i++)
+    {
+        maxevents[i] = CreateEvent(NULL, 1, 1, NULL);
+        ok( maxevents[i] != INVALID_HANDLE_VALUE, "should create enough events\n");
+    }
+    r = WaitForMultipleObjects(MAXIMUM_WAIT_OBJECTS, maxevents, 0, 0);
+    ok( r != WAIT_FAILED && r != WAIT_TIMEOUT, "should succeed\n");
+    
+    for (i=0; i<MAXIMUM_WAIT_OBJECTS; i++)
+        if (maxevents[i] != INVALID_HANDLE_VALUE)
+            CloseHandle(maxevents[i]);
 
     /* semaphores */
     semaphore[0] = CreateSemaphore( NULL, 0, 1, NULL );


More information about the wine-patches mailing list