Commit 72c562ce authored by Paul Gofman's avatar Paul Gofman Committed by Alexandre Julliard

kernel32: Do not impose 32 bit limits on Win64 in GlobalMemoryStatus().

parent d1b80f4d
......@@ -543,7 +543,9 @@ VOID WINAPI GlobalMemoryStatus( LPMEMORYSTATUS lpBuffer )
{
MEMORYSTATUSEX memstatus;
OSVERSIONINFOW osver;
#ifndef _WIN64
IMAGE_NT_HEADERS *nt = RtlImageNtHeader( GetModuleHandleW(0) );
#endif
/* Because GlobalMemoryStatus is identical to GlobalMemoryStatusEX save
for one extra field in the struct, and the lack of a bug, we simply
......@@ -561,6 +563,14 @@ VOID WINAPI GlobalMemoryStatus( LPMEMORYSTATUS lpBuffer )
osver.dwOSVersionInfoSize = sizeof(osver);
GetVersionExW(&osver);
lpBuffer->dwTotalPhys = memstatus.ullTotalPhys;
lpBuffer->dwAvailPhys = memstatus.ullAvailPhys;
lpBuffer->dwTotalPageFile = memstatus.ullTotalPageFile;
lpBuffer->dwAvailPageFile = memstatus.ullAvailPageFile;
lpBuffer->dwTotalVirtual = memstatus.ullTotalVirtual;
lpBuffer->dwAvailVirtual = memstatus.ullAvailVirtual;
#ifndef _WIN64
if ( osver.dwMajorVersion >= 5 || osver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS )
{
lpBuffer->dwTotalPhys = min( memstatus.ullTotalPhys, MAXDWORD );
......@@ -570,16 +580,6 @@ VOID WINAPI GlobalMemoryStatus( LPMEMORYSTATUS lpBuffer )
lpBuffer->dwAvailPageFile = min( memstatus.ullAvailPageFile, MAXDWORD );
lpBuffer->dwTotalVirtual = min( memstatus.ullTotalVirtual, MAXDWORD );
lpBuffer->dwAvailVirtual = min( memstatus.ullAvailVirtual, MAXDWORD );
}
else /* duplicate NT bug */
{
lpBuffer->dwTotalPhys = memstatus.ullTotalPhys;
lpBuffer->dwAvailPhys = memstatus.ullAvailPhys;
lpBuffer->dwTotalPageFile = memstatus.ullTotalPageFile;
lpBuffer->dwAvailPageFile = memstatus.ullAvailPageFile;
lpBuffer->dwTotalVirtual = memstatus.ullTotalVirtual;
lpBuffer->dwAvailVirtual = memstatus.ullAvailVirtual;
}
/* values are limited to 2Gb unless the app has the IMAGE_FILE_LARGE_ADDRESS_AWARE flag */
......@@ -603,6 +603,7 @@ VOID WINAPI GlobalMemoryStatus( LPMEMORYSTATUS lpBuffer )
if (lpBuffer->dwTotalPageFile > MAXLONG) lpBuffer->dwTotalPageFile = MAXLONG;
if (lpBuffer->dwAvailPageFile > MAXLONG) lpBuffer->dwAvailPageFile = MAXLONG;
}
#endif
TRACE("Length %u, MemoryLoad %u, TotalPhys %lx, AvailPhys %lx,"
" TotalPageFile %lx, AvailPageFile %lx, TotalVirtual %lx, AvailVirtual %lx\n",
......
......@@ -1213,6 +1213,51 @@ static void test_GetPhysicallyInstalledSystemMemory(void)
"expected total_memory >= memstatus.ullTotalPhys / 1024\n");
}
static BOOL compare_ulong64(ULONG64 v1, ULONG64 v2, ULONG64 max_diff)
{
ULONG64 diff = v1 > v2 ? v1 - v2 : v2 - v1;
return diff <= max_diff;
}
static void test_GlobalMemoryStatus(void)
{
static const ULONG64 max_diff = 0x200000;
MEMORYSTATUSEX memex;
MEMORYSTATUS mem;
SIZE_T size;
mem.dwLength = sizeof(mem);
GlobalMemoryStatus(&mem);
memex.dwLength = sizeof(memex);
GlobalMemoryStatusEx(&memex);
/* Compare values approximately as the available memory may change between
* GlobalMemoryStatus() and GlobalMemoryStatusEx() calls. */
size = min(memex.ullTotalPhys, ~(SIZE_T)0 >> 1);
ok(compare_ulong64(mem.dwTotalPhys, size, max_diff), "Got unexpected dwTotalPhys %s, size %s.\n",
wine_dbgstr_longlong(mem.dwTotalPhys), wine_dbgstr_longlong(size));
size = min(memex.ullAvailPhys, ~(SIZE_T)0 >> 1);
ok(compare_ulong64(mem.dwAvailPhys, size, max_diff), "Got unexpected dwAvailPhys %s, size %s.\n",
wine_dbgstr_longlong(mem.dwAvailPhys), wine_dbgstr_longlong(size));
size = min(memex.ullTotalPageFile, ~(SIZE_T)0);
ok(compare_ulong64(mem.dwTotalPageFile, size, max_diff),
"Got unexpected dwTotalPageFile %s, size %s.\n",
wine_dbgstr_longlong(mem.dwTotalPageFile), wine_dbgstr_longlong(size));
size = min(memex.ullAvailPageFile, ~(SIZE_T)0);
ok(compare_ulong64(mem.dwAvailPageFile, size, max_diff), "Got unexpected dwAvailPageFile %s, size %s.\n",
wine_dbgstr_longlong(mem.dwAvailPageFile), wine_dbgstr_longlong(size));
ok(compare_ulong64(mem.dwTotalVirtual, memex.ullTotalVirtual, max_diff),
"Got unexpected dwTotalVirtual %s, ullTotalVirtual %s.\n",
wine_dbgstr_longlong(mem.dwTotalVirtual), wine_dbgstr_longlong(memex.ullTotalVirtual));
ok(compare_ulong64(mem.dwAvailVirtual, memex.ullAvailVirtual, max_diff),
"Got unexpected dwAvailVirtual %s, ullAvailVirtual %s.\n",
wine_dbgstr_longlong(mem.dwAvailVirtual), wine_dbgstr_longlong(memex.ullAvailVirtual));
}
START_TEST(heap)
{
int argc;
......@@ -1246,6 +1291,7 @@ START_TEST(heap)
test_HeapQueryInformation();
test_GetPhysicallyInstalledSystemMemory();
test_GlobalMemoryStatus();
if (pRtlGetNtGlobalFlags)
{
......
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