GlobalMemoryStatusEx patch

Rob Crittenden <[email protected]> Tue, 3 Aug 2004 12:59:34 -0400 (EDT)
Newsgroups gmane.comp.emulators.winex.devel
Message-ID <[email protected]>
Attached is a patch that adds the function GlobalMemoryStatusEx. This
is required for Doom 3 to run.

It just copies data from a call to GlobalMemoryStatus() and seems to
work ok.

There is one thing to note though. ullAvailExtendedVirtual is not well-defined
so I'm setting it to 0. It doesn't seem to hurt anything.

rob
mem.patch (text/plain, 3.5 KB)
Index: ./include/winbase.h
===================================================================
RCS file: /cvsroot/winex/include/winbase.h,v
retrieving revision 1.30
diff -u -r1.30 winbase.h
--- ./include/winbase.h	8 Jul 2004 15:32:03 -0000	1.30
+++ ./include/winbase.h	3 Aug 2004 16:55:41 -0000
@@ -426,6 +426,17 @@
     DWORD    dwAvailVirtual;
 } MEMORYSTATUS, *LPMEMORYSTATUS;
 
+typedef struct tagMEMORYSTATUSEX {
+    DWORD     dwLength;
+    DWORD     dwMemoryLoad;
+    DWORDLONG ullTotalPhys;
+    DWORDLONG ullAvailPhys;
+    DWORDLONG ullTotalPageFile;
+    DWORDLONG ullAvailPageFile;
+    DWORDLONG ullTotalVirtual;
+    DWORDLONG ullAvailVirtual;
+    DWORDLONG ullAvailExtendedVirtual;
+} MEMORYSTATUSEX, *LPMEMORYSTATUSEX;
 
 typedef struct {
         WORD wYear;
@@ -1357,6 +1368,7 @@
 BOOL        WINAPI GetUserNameW(LPWSTR,LPDWORD);
 #define     GetUserName WINELIB_NAME_AW(GetUserName)
 VOID        WINAPI GlobalMemoryStatus(LPMEMORYSTATUS);
+BOOL        WINAPI GlobalMemoryStatusEx(LPMEMORYSTATUSEX);
 DWORD       WINAPI HeapCompact(HANDLE,DWORD);
 HANDLE    WINAPI HeapCreate(DWORD,DWORD,DWORD);
 BOOL      WINAPI HeapDestroy(HANDLE);
Index: ./memory/global.c
===================================================================
RCS file: /cvsroot/winex/memory/global.c,v
retrieving revision 1.3
diff -u -r1.3 global.c
--- ./memory/global.c	18 Feb 2004 22:27:49 -0000	1.3
+++ ./memory/global.c	3 Aug 2004 16:55:45 -0000
@@ -1625,6 +1625,39 @@
 }
 
 /***********************************************************************
+ *           GlobalMemoryStatusEx   (KERNEL32.@)
+ * RETURNS
+ *      TRUE
+ */
+BOOL WINAPI GlobalMemoryStatusEx(LPMEMORYSTATUSEX lpmemex)
+{
+    MEMORYSTATUS ms;
+    GlobalMemoryStatus( &ms );
+
+    /* The structures are the same, just copy them */
+    lpmemex->dwLength = sizeof(MEMORYSTATUSEX);
+    lpmemex->dwMemoryLoad = ms.dwMemoryLoad;
+    lpmemex->ullTotalPhys = ms.dwTotalPhys;
+    lpmemex->ullAvailPhys = ms.dwTotalPageFile;
+    lpmemex->ullTotalPageFile = ms.dwTotalPageFile;
+    lpmemex->ullAvailPageFile = ms.dwAvailPageFile;
+    lpmemex->ullTotalVirtual = ms.dwTotalVirtual;
+    lpmemex->ullAvailVirtual = ms.dwAvailVirtual;
+
+    /* I don't know what this is. MSDN says it is "the amount of extended
+     * memory available" and "size of unreserved and uncommitted memory in
+     * the extended portion of the virtual address space of the calling
+     * process, in bytes."
+     *
+     * Um, ok. The MSDN example shows this as 0 and that's good enough for
+     * me.
+     */
+    lpmemex->ullAvailExtendedVirtual = 0;
+
+    return TRUE;
+}
+
+/***********************************************************************
  *           A20Proc   (KERNEL.165)
  *           A20_Proc  (SYSTEM.20)
  */
Index: ./dlls/kernel/kernel32.spec
===================================================================
RCS file: /cvsroot/winex/dlls/kernel/kernel32.spec,v
retrieving revision 1.6
diff -u -r1.6 kernel32.spec
--- ./dlls/kernel/kernel32.spec	8 Jul 2004 15:33:26 -0000	1.6
+++ ./dlls/kernel/kernel32.spec	3 Aug 2004 16:55:48 -0000
@@ -498,6 +498,7 @@
 @ stdcall GlobalHandle(ptr) GlobalHandle
 @ stdcall GlobalLock(long) GlobalLock
 @ stdcall GlobalMemoryStatus(ptr) GlobalMemoryStatus
+@ stdcall GlobalMemoryStatusEx(ptr) GlobalMemoryStatusEx
 @ stdcall GlobalReAlloc(long long long) GlobalReAlloc
 @ stdcall GlobalSize(long) GlobalSize
 @ stdcall GlobalUnWire(long) GlobalUnWire