Commit b2218370 authored by Alexandre Julliard's avatar Alexandre Julliard

kernel32: Fix GlobalMemoryStatus to take into account the IMAGE_FILE_LARGE_ADDRESS_AWARE flag.

Also the page file size must not be truncated to 2Gb no matter what the flag is set to.
parent 9fd2d443
...@@ -1220,13 +1220,18 @@ BOOL WINAPI GlobalMemoryStatusEx( LPMEMORYSTATUSEX lpmemex ) ...@@ -1220,13 +1220,18 @@ BOOL WINAPI GlobalMemoryStatusEx( LPMEMORYSTATUSEX lpmemex )
int rval; int rval;
#endif #endif
if (lpmemex->dwLength != sizeof(*lpmemex))
{
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
}
if (time(NULL)==cache_lastchecked) { if (time(NULL)==cache_lastchecked) {
memcpy(lpmemex,&cached_memstatus,sizeof(*lpmemex)); memcpy(lpmemex,&cached_memstatus,sizeof(*lpmemex));
return TRUE; return TRUE;
} }
cache_lastchecked = time(NULL); cache_lastchecked = time(NULL);
lpmemex->dwLength = sizeof(*lpmemex);
lpmemex->dwMemoryLoad = 0; lpmemex->dwMemoryLoad = 0;
lpmemex->ullTotalPhys = 16*1024*1024; lpmemex->ullTotalPhys = 16*1024*1024;
lpmemex->ullAvailPhys = 16*1024*1024; lpmemex->ullAvailPhys = 16*1024*1024;
...@@ -1366,10 +1371,12 @@ VOID WINAPI GlobalMemoryStatus( LPMEMORYSTATUS lpBuffer ) ...@@ -1366,10 +1371,12 @@ VOID WINAPI GlobalMemoryStatus( LPMEMORYSTATUS lpBuffer )
{ {
MEMORYSTATUSEX memstatus; MEMORYSTATUSEX memstatus;
OSVERSIONINFOW osver; OSVERSIONINFOW osver;
IMAGE_NT_HEADERS *nt = RtlImageNtHeader( GetModuleHandleW(0) );
/* Because GlobalMemoryStatus is identical to GlobalMemoryStatusEX save /* Because GlobalMemoryStatus is identical to GlobalMemoryStatusEX save
for one extra field in the struct, and the lack of a bug, we simply for one extra field in the struct, and the lack of a bug, we simply
call GlobalMemoryStatusEx and copy the values across. */ call GlobalMemoryStatusEx and copy the values across. */
memstatus.dwLength = sizeof(memstatus);
GlobalMemoryStatusEx(&memstatus); GlobalMemoryStatusEx(&memstatus);
lpBuffer->dwLength = sizeof(*lpBuffer); lpBuffer->dwLength = sizeof(*lpBuffer);
...@@ -1377,7 +1384,6 @@ VOID WINAPI GlobalMemoryStatus( LPMEMORYSTATUS lpBuffer ) ...@@ -1377,7 +1384,6 @@ VOID WINAPI GlobalMemoryStatus( LPMEMORYSTATUS lpBuffer )
/* Windows 2000 and later report -1 when values are greater than 4 Gb. /* Windows 2000 and later report -1 when values are greater than 4 Gb.
* NT reports values modulo 4 Gb. * NT reports values modulo 4 Gb.
* Values between 2 Gb and 4 Gb are rounded down to 2 Gb.
*/ */
osver.dwOSVersionInfoSize = sizeof(osver); osver.dwOSVersionInfoSize = sizeof(osver);
...@@ -1385,33 +1391,32 @@ VOID WINAPI GlobalMemoryStatus( LPMEMORYSTATUS lpBuffer ) ...@@ -1385,33 +1391,32 @@ VOID WINAPI GlobalMemoryStatus( LPMEMORYSTATUS lpBuffer )
if ( osver.dwMajorVersion >= 5 ) if ( osver.dwMajorVersion >= 5 )
{ {
lpBuffer->dwTotalPhys = (memstatus.ullTotalPhys > MAXDWORD) ? MAXDWORD : lpBuffer->dwTotalPhys = min( memstatus.ullTotalPhys, MAXDWORD );
(memstatus.ullTotalPhys > MAXLONG) ? MAXLONG : memstatus.ullTotalPhys; lpBuffer->dwAvailPhys = min( memstatus.ullAvailPhys, MAXDWORD );
lpBuffer->dwAvailPhys = (memstatus.ullAvailPhys > MAXDWORD) ? MAXDWORD : lpBuffer->dwTotalPageFile = min( memstatus.ullTotalPageFile, MAXDWORD );
(memstatus.ullAvailPhys > MAXLONG) ? MAXLONG : memstatus.ullAvailPhys; lpBuffer->dwAvailPageFile = min( memstatus.ullAvailPageFile, MAXDWORD );
lpBuffer->dwTotalPageFile = (memstatus.ullTotalPageFile > MAXDWORD) ? MAXDWORD : lpBuffer->dwTotalVirtual = min( memstatus.ullTotalVirtual, MAXDWORD );
(memstatus.ullTotalPageFile > MAXLONG) ? MAXLONG : memstatus.ullTotalPageFile; lpBuffer->dwAvailVirtual = min( memstatus.ullAvailVirtual, MAXDWORD );
lpBuffer->dwAvailPageFile = (memstatus.ullAvailPageFile > MAXDWORD) ? MAXDWORD :
(memstatus.ullAvailPageFile > MAXLONG) ? MAXLONG : memstatus.ullAvailPageFile;
lpBuffer->dwTotalVirtual = (memstatus.ullTotalVirtual > MAXDWORD) ? MAXDWORD :
(memstatus.ullTotalVirtual > MAXLONG) ? MAXLONG : memstatus.ullTotalVirtual;
lpBuffer->dwAvailVirtual = (memstatus.ullAvailVirtual > MAXDWORD) ? MAXDWORD :
(memstatus.ullAvailVirtual > MAXLONG) ? MAXLONG : memstatus.ullAvailVirtual;
} }
else /* duplicate NT bug */ else /* duplicate NT bug */
{ {
lpBuffer->dwTotalPhys = (memstatus.ullTotalPhys > MAXDWORD) ? memstatus.ullTotalPhys : lpBuffer->dwTotalPhys = memstatus.ullTotalPhys;
(memstatus.ullTotalPhys > MAXLONG) ? MAXLONG : memstatus.ullTotalPhys; lpBuffer->dwAvailPhys = memstatus.ullAvailPhys;
lpBuffer->dwAvailPhys = (memstatus.ullAvailPhys > MAXDWORD) ? memstatus.ullAvailPhys : lpBuffer->dwTotalPageFile = memstatus.ullTotalPageFile;
(memstatus.ullAvailPhys > MAXLONG) ? MAXLONG : memstatus.ullAvailPhys; lpBuffer->dwAvailPageFile = memstatus.ullAvailPageFile;
lpBuffer->dwTotalPageFile = (memstatus.ullTotalPageFile > MAXDWORD) ? memstatus.ullTotalPageFile : lpBuffer->dwTotalVirtual = memstatus.ullTotalVirtual;
(memstatus.ullTotalPageFile > MAXLONG) ? MAXLONG : memstatus.ullTotalPageFile; lpBuffer->dwAvailVirtual = memstatus.ullAvailVirtual;
lpBuffer->dwAvailPageFile = (memstatus.ullAvailPageFile > MAXDWORD) ? memstatus.ullAvailPageFile : }
(memstatus.ullAvailPageFile > MAXLONG) ? MAXLONG : memstatus.ullAvailPageFile;
lpBuffer->dwTotalVirtual = (memstatus.ullTotalVirtual > MAXDWORD) ? memstatus.ullTotalVirtual : /* values are limited to 2Gb unless the app has the IMAGE_FILE_LARGE_ADDRESS_AWARE flag */
(memstatus.ullTotalVirtual > MAXLONG) ? MAXLONG : memstatus.ullTotalVirtual; /* page file sizes are not limited (Adobe Illustrator 8 depends on this) */
lpBuffer->dwAvailVirtual = (memstatus.ullAvailVirtual > MAXDWORD) ? memstatus.ullAvailVirtual : if (!(nt->FileHeader.Characteristics & IMAGE_FILE_LARGE_ADDRESS_AWARE))
(memstatus.ullAvailVirtual > MAXLONG) ? MAXLONG : memstatus.ullAvailVirtual; {
if (lpBuffer->dwTotalPhys > MAXLONG) lpBuffer->dwTotalPhys = MAXLONG;
if (lpBuffer->dwAvailPhys > MAXLONG) lpBuffer->dwAvailPhys = MAXLONG;
if (lpBuffer->dwTotalVirtual > MAXLONG) lpBuffer->dwTotalVirtual = MAXLONG;
if (lpBuffer->dwAvailVirtual > MAXLONG) lpBuffer->dwAvailVirtual = MAXLONG;
} }
/* work around for broken photoshop 4 installer */ /* work around for broken photoshop 4 installer */
......
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