Match OVERLAPPED structure to the SDK definition

Dmitry Timoshkov dmitry at baikal.ru
Wed Mar 16 07:31:55 CST 2005


Hello,

while browsing microsoft.public.win32.programmer.kernel I stumbled over
a discussion about layout of the OVERLAPPED structure. Here is a patch
which makes our version compatible with the PSDK one. The patch also
arranges low/high offset members similar to LARGE_INTEGER in order
to cope with endianes.

Changelog:
    Dmitry Timoshkov <dmitry at codeweavers.com>
    Match OVERLAPPED structure to the SDK definition.

diff -up cvs/hq/wine/dlls/kernel/comm.c wine/dlls/kernel/comm.c
--- cvs/hq/wine/dlls/kernel/comm.c	Sat Feb 26 17:42:47 2005
+++ wine/dlls/kernel/comm.c	Wed Mar 16 16:54:48 2005
@@ -1975,8 +1975,7 @@ static BOOL COMM_WaitCommEvent(
     commio->fd = fd;  /* FIXME */
 
     lpOverlapped->InternalHigh = 0;
-    lpOverlapped->Offset = 0;
-    lpOverlapped->OffsetHigh = 0;
+    lpOverlapped->u.Pointer = NULL;
 
     SERVER_START_REQ( register_async )
     {
diff -up cvs/hq/wine/dlls/kernel/file.c wine/dlls/kernel/file.c
--- cvs/hq/wine/dlls/kernel/file.c	Wed Jan 19 14:21:09 2005
+++ wine/dlls/kernel/file.c	Wed Mar 16 17:00:50 2005
@@ -323,8 +323,7 @@ BOOL WINAPI ReadFileEx(HANDLE hFile, LPV
         return FALSE;
     }
 
-    offset.u.LowPart = overlapped->Offset;
-    offset.u.HighPart = overlapped->OffsetHigh;
+    offset.QuadPart = (ULONG_PTR)overlapped->u.Pointer;
     io_status = (PIO_STATUS_BLOCK)overlapped;
     io_status->u.Status = STATUS_PENDING;
 
@@ -364,8 +363,7 @@ BOOL WINAPI ReadFile( HANDLE hFile, LPVO
 
     if (overlapped != NULL)
     {
-        offset.u.LowPart = overlapped->Offset;
-        offset.u.HighPart = overlapped->OffsetHigh;
+        offset.QuadPart = (ULONG_PTR)overlapped->u.Pointer;
         poffset = &offset;
         hEvent = overlapped->hEvent;
         io_status = (PIO_STATUS_BLOCK)overlapped;
@@ -405,8 +403,7 @@ BOOL WINAPI WriteFileEx(HANDLE hFile, LP
         SetLastError(ERROR_INVALID_PARAMETER);
         return FALSE;
     }
-    offset.u.LowPart = overlapped->Offset;
-    offset.u.HighPart = overlapped->OffsetHigh;
+    offset.QuadPart = (ULONG_PTR)overlapped->u.Pointer;
 
     io_status = (PIO_STATUS_BLOCK)overlapped;
     io_status->u.Status = STATUS_PENDING;
@@ -439,8 +436,7 @@ BOOL WINAPI WriteFile( HANDLE hFile, LPC
 
     if (overlapped)
     {
-        offset.u.LowPart = overlapped->Offset;
-        offset.u.HighPart = overlapped->OffsetHigh;
+        offset.QuadPart = (ULONG_PTR)overlapped->u.Pointer;
         poffset = &offset;
         hEvent = overlapped->hEvent;
         piosb = (PIO_STATUS_BLOCK)overlapped;
@@ -998,14 +994,12 @@ BOOL WINAPI LockFileEx( HANDLE hFile, DW
         return FALSE;
     }
 
-    TRACE( "%p %lx%08lx %lx%08lx flags %lx\n",
-           hFile, overlapped->OffsetHigh, overlapped->Offset, 
-           count_high, count_low, flags );
+    TRACE( "%p %p %lx%08lx flags %lx\n",
+           hFile, overlapped->u.Pointer, count_high, count_low, flags );
 
     count.u.LowPart = count_low;
     count.u.HighPart = count_high;
-    offset.u.LowPart = overlapped->Offset;
-    offset.u.HighPart = overlapped->OffsetHigh;
+    offset.QuadPart = (ULONG_PTR)overlapped->u.Pointer;
 
     status = NtLockFile( hFile, overlapped->hEvent, NULL, NULL, 
                          NULL, &offset, &count, NULL, 
@@ -1050,7 +1044,7 @@ BOOL WINAPI UnlockFileEx( HANDLE hFile, 
     }
     if (overlapped->hEvent) FIXME("Unimplemented overlapped operation\n");
 
-    return UnlockFile( hFile, overlapped->Offset, overlapped->OffsetHigh, count_low, count_high );
+    return UnlockFile( hFile, overlapped->u.s.Offset, overlapped->u.s.OffsetHigh, count_low, count_high );
 }
 
 
diff -up cvs/hq/wine/dlls/kernel/tests/file.c wine/dlls/kernel/tests/file.c
--- cvs/hq/wine/dlls/kernel/tests/file.c	Sat Mar  5 23:26:00 2005
+++ wine/dlls/kernel/tests/file.c	Wed Mar 16 20:09:57 2005
@@ -912,8 +912,7 @@ static void test_offset_in_overlapped_st
     ok(done == sizeof(buf), "expected number of bytes written %lu\n", done);
 
     memset(&ov, 0, sizeof(ov));
-    ov.Offset = PATTERN_OFFSET;
-    ov.OffsetHigh = 0;
+    ov.u.Pointer = (void *)PATTERN_OFFSET;
     rc=WriteFile(hFile, pattern, sizeof(pattern), &done, &ov);
     /* Win 9x does not support the overlapped I/O on files */
     if (rc || GetLastError()!=ERROR_INVALID_PARAMETER) {
@@ -923,8 +922,7 @@ static void test_offset_in_overlapped_st
         ok(SetFilePointer(hFile, 0, NULL, FILE_CURRENT) == (PATTERN_OFFSET + sizeof(pattern)),
            "expected file offset %d\n", PATTERN_OFFSET + sizeof(pattern));
 
-        ov.Offset = sizeof(buf) * 2;
-        ov.OffsetHigh = 0;
+        ov.u.Pointer = (void *)(sizeof(buf) * 2);
         ret = WriteFile(hFile, pattern, sizeof(pattern), &done, &ov);
         ok( ret, "WriteFile error %ld\n", GetLastError());
         ok(done == sizeof(pattern), "expected number of bytes written %lu\n", done);
@@ -942,8 +940,7 @@ static void test_offset_in_overlapped_st
 
     memset(buf, 0, sizeof(buf));
     memset(&ov, 0, sizeof(ov));
-    ov.Offset = PATTERN_OFFSET;
-    ov.OffsetHigh = 0;
+    ov.u.Pointer = (void *)PATTERN_OFFSET;
     rc=ReadFile(hFile, buf, sizeof(pattern), &done, &ov);
     /* Win 9x does not support the overlapped I/O on files */
     if (rc || GetLastError()!=ERROR_INVALID_PARAMETER) {
@@ -1001,8 +998,7 @@ static void test_LockFile(void)
     ok( !UnlockFile( handle, 10, 0, 20, 0 ), "UnlockFile 10,20 again succeeded\n" );
     ok( UnlockFile( handle, 5, 0, 5, 0 ), "UnlockFile 5,5 failed\n" );
 
-    overlapped.Offset = 100;
-    overlapped.OffsetHigh = 0;
+    overlapped.u.Pointer = (void *)100;
     overlapped.hEvent = 0;
 
     lockfileex_capable = dll_capable("kernel32", "LockFileEx");
@@ -1018,7 +1014,7 @@ static void test_LockFile(void)
     }
 
     /* overlapping shared locks are OK */
-    overlapped.Offset = 150;
+    overlapped.u.Pointer = (void *)150;
     limited_UnLockFile || ok( LockFileEx( handle, 0, 0, 100, 0, &overlapped ), "LockFileEx 150,100 failed\n" );
 
     /* but exclusive is not */
@@ -1031,7 +1027,7 @@ static void test_LockFile(void)
         {
             if (!UnlockFileEx( handle, 0, 100, 0, &overlapped ))
             { /* UnLockFile is capable. */
-                overlapped.Offset = 100;
+                overlapped.u.Pointer = (void *)100;
                 ok( !UnlockFileEx( handle, 0, 100, 0, &overlapped ),
                     "UnlockFileEx 150,100 again succeeded\n" );
 	    }
@@ -1287,7 +1283,7 @@ static int completion_count;
 
 static void CALLBACK FileIOComplete(DWORD dwError, DWORD dwBytes, LPOVERLAPPED ovl)
 {
-/*	printf("(%ld, %ld, %p { %ld, %ld, %ld, %ld, %p })\n", dwError, dwBytes, ovl, ovl->Internal, ovl->InternalHigh, ovl->Offset, ovl->OffsetHigh, ovl->hEvent);*/
+/*	printf("(%ld, %ld, %p { %ld, %ld, %p, %p })\n", dwError, dwBytes, ovl, ovl->Internal, ovl->InternalHigh, ovl->u.Pointer, ovl->hEvent);*/
 	ReleaseSemaphore(ovl->hEvent, 1, NULL);
 	completion_count++;
 }
@@ -1299,8 +1295,7 @@ static void test_async_file_errors(void)
     HANDLE hFile;
     LPVOID lpBuffer = HeapAlloc(GetProcessHeap(), 0, 4096);
     OVERLAPPED ovl;
-    ovl.Offset = 0;
-    ovl.OffsetHigh = 0;
+    ovl.u.Pointer = NULL;
     ovl.hEvent = hSem;
     completion_count = 0;
     szFile[0] = '\0';
@@ -1317,7 +1312,7 @@ static void test_async_file_errors(void)
         /*printf("Offset = %ld, result = %s\n", ovl.Offset, res ? "TRUE" : "FALSE");*/
         if (!res)
             break;
-        ovl.Offset += 4096;
+        (ULONG_PTR)ovl.u.Pointer += 4096;
         /* i/o completion routine only called if ReadFileEx returned success.
          * we only care about violations of this rule so undo what should have
          * been done */
diff -up cvs/hq/wine/dlls/kernel/tests/generated.c wine/dlls/kernel/tests/generated.c
--- cvs/hq/wine/dlls/kernel/tests/generated.c	Tue Sep  7 15:20:57 2004
+++ wine/dlls/kernel/tests/generated.c	Wed Mar 16 20:17:14 2005
@@ -835,10 +835,10 @@ static void test_pack_OVERLAPPED(void)
 {
     /* OVERLAPPED (pack 4) */
     TEST_TYPE(OVERLAPPED, 20, 4);
-    TEST_FIELD(OVERLAPPED, DWORD, Internal, 0, 4, 4);
-    TEST_FIELD(OVERLAPPED, DWORD, InternalHigh, 4, 4, 4);
-    TEST_FIELD(OVERLAPPED, DWORD, Offset, 8, 4, 4);
-    TEST_FIELD(OVERLAPPED, DWORD, OffsetHigh, 12, 4, 4);
+    TEST_FIELD(OVERLAPPED, ULONG_PTR, Internal, 0, 4, 4);
+    TEST_FIELD(OVERLAPPED, ULONG_PTR, InternalHigh, 4, 4, 4);
+    TEST_FIELD(OVERLAPPED, DWORD, u.s.Offset, 8, 4, 4);
+    TEST_FIELD(OVERLAPPED, DWORD, u.s.OffsetHigh, 12, 4, 4);
     TEST_FIELD(OVERLAPPED, HANDLE, hEvent, 16, 4, 4);
 }
 
diff -up cvs/hq/wine/dlls/quartz/filesource.c wine/dlls/quartz/filesource.c
--- cvs/hq/wine/dlls/quartz/filesource.c	Mon Jan 10 13:55:52 2005
+++ wine/dlls/quartz/filesource.c	Wed Mar 16 20:40:29 2005
@@ -966,8 +966,7 @@ static HRESULT WINAPI FileAsyncReader_Re
     {
         DWORD dwLength = (DWORD) BYTES_FROM_MEDIATIME(Stop - Start);
 
-        pDataRq->ovl.Offset = (DWORD) BYTES_FROM_MEDIATIME(Start);
-        pDataRq->ovl.OffsetHigh = (DWORD)(BYTES_FROM_MEDIATIME(Start) >> (sizeof(DWORD) * 8));
+        pDataRq->ovl.u.Pointer = (void *)(ULONG_PTR)BYTES_FROM_MEDIATIME(Start);
         pDataRq->ovl.hEvent = This->hEvent;
         pDataRq->dwUserData = dwUser;
         pDataRq->pNext = NULL;
@@ -1120,8 +1119,7 @@ static HRESULT WINAPI FileAsyncReader_Sy
 
     ovl.hEvent = CreateEventW(NULL, 0, 0, NULL);
     /* NOTE: llPosition is the actual byte position to start reading from */
-    ovl.Offset = (DWORD) llPosition;
-    ovl.OffsetHigh = (DWORD) (llPosition >> (sizeof(DWORD) * 8));
+    ovl.u.Pointer = (void *)(ULONG_PTR)llPosition;
 
     if (!ReadFile(This->hFile, pBuffer, lLength, NULL, &ovl))
         hr = HRESULT_FROM_WIN32(GetLastError());
diff -up cvs/hq/wine/include/winbase.h wine/include/winbase.h
--- cvs/hq/wine/include/winbase.h	Sat Feb 26 17:42:53 2005
+++ wine/include/winbase.h	Wed Mar 16 20:32:09 2005
@@ -485,10 +485,25 @@ typedef struct _SYSTEMTIME{
 /* The 'overlapped' data structure used by async I/O functions.
  */
 typedef struct _OVERLAPPED {
-        DWORD Internal;
-        DWORD InternalHigh;
-        DWORD Offset;
-        DWORD OffsetHigh;
+#ifdef WORDS_BIGENDIAN
+        ULONG_PTR InternalHigh;
+        ULONG_PTR Internal;
+#else
+        ULONG_PTR Internal;
+        ULONG_PTR InternalHigh;
+#endif
+        union {
+            struct {
+#ifdef WORDS_BIGENDIAN
+                DWORD OffsetHigh;
+                DWORD Offset;
+#else
+                DWORD Offset;
+                DWORD OffsetHigh;
+#endif
+            } DUMMYSTRUCTNAME;
+            PVOID Pointer;
+        } DUMMYUNIONNAME;
         HANDLE hEvent;
 } OVERLAPPED, *LPOVERLAPPED;
 
diff -up cvs/hq/wine/include/wine/mmsystem16.h wine/include/wine/mmsystem16.h
--- cvs/hq/wine/include/wine/mmsystem16.h	Tue Apr  6 12:17:02 2004
+++ wine/include/wine/mmsystem16.h	Wed Mar 16 16:37:14 2005
@@ -330,11 +330,11 @@ typedef struct {
 	struct {
 	    LONG	lMinimum;	/* signed minimum for this control */
 	    LONG	lMaximum;	/* signed maximum for this control */
-	} s;
+	} DUMMYSTRUCTNAME;
 	struct {
 	    DWORD	dwMinimum;	/* unsigned minimum for this control */
 	    DWORD	dwMaximum;	/* unsigned maximum for this control */
-	} s1;
+	} DUMMYSTRUCTNAME1;
 	DWORD       	dwReserved[6];
     } Bounds;
     union {
@@ -350,7 +350,7 @@ typedef struct {
     union {
 	DWORD	dwControlID;	/* MIXER_GETLINECONTROLSF_ONEBYID */
 	DWORD	dwControlType;	/* MIXER_GETLINECONTROLSF_ONEBYTYPE */
-    } u;
+    } DUMMYUNIONNAME;
     DWORD	cControls;	/* count of controls pmxctrl points to */
     DWORD	cbmxctrl;	/* size in bytes of _one_ MIXERCONTROL */
     SEGPTR	pamxctrl;	/* pointer to first MIXERCONTROL array */
@@ -363,7 +363,7 @@ typedef struct {
     union {
         HWND16	hwndOwner;	/* for MIXER_SETCONTROLDETAILSF_CUSTOM */
         DWORD	cMultipleItems;	/* if _MULTIPLE, the number of items per channel */
-    } u;
+    } DUMMYUNIONNAME;
     DWORD	cbDetails;	/* size of _one_ details_XX struct */
     LPVOID	paDetails;	/* pointer to array of details_XX structs */
 } MIXERCONTROLDETAILS16,*LPMIXERCONTROLDETAILS16;
diff -up cvs/hq/wine/include/wininet.h wine/include/wininet.h
--- cvs/hq/wine/include/wininet.h	Wed Feb  2 15:29:25 2005
+++ wine/include/wininet.h	Wed Mar 16 16:37:14 2005
@@ -1366,7 +1366,7 @@ typedef struct _INTERNET_CACHE_ENTRY_INF
     union {
       DWORD dwReserved;
       DWORD dwExemptDelta;
-    } u;
+    } DUMMYUNIONNAME;
 } INTERNET_CACHE_ENTRY_INFOA,* LPINTERNET_CACHE_ENTRY_INFOA;
 
 typedef struct _INTERNET_CACHE_ENTRY_INFOW {
@@ -1389,7 +1389,7 @@ typedef struct _INTERNET_CACHE_ENTRY_INF
     union {
       DWORD dwReserved;
       DWORD dwExemptDelta;
-    } u;
+    } DUMMYUNIONNAME;
 } INTERNET_CACHE_ENTRY_INFOW,* LPINTERNET_CACHE_ENTRY_INFOW;
 
 DECL_WINELIB_TYPE_AW(INTERNET_CACHE_ENTRY_INFO)
diff -up cvs/hq/wine/include/winnt.h wine/include/winnt.h
--- cvs/hq/wine/include/winnt.h	Sat Feb 26 17:42:53 2005
+++ wine/include/winnt.h	Wed Mar 16 16:37:14 2005
@@ -2189,7 +2189,7 @@ typedef struct _IMAGE_IMPORT_DESCRIPTOR 
 	union {
 		DWORD	Characteristics; /* 0 for terminating null import descriptor  */
 		PIMAGE_THUNK_DATA OriginalFirstThunk;	/* RVA to original unbound IAT */
-	} u;
+	} DUMMYUNIONNAME;
 	DWORD	TimeDateStamp;	/* 0 if not bound,
 				 * -1 if bound, and real date\time stamp
 				 *    in IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT






More information about the wine-patches mailing list