Commit b73cfa72 authored by Alexandre Julliard's avatar Alexandre Julliard

kernel32: Move physical memory status functions to kernelbase.

parent dad14ab8
......@@ -762,7 +762,7 @@
@ stdcall -import GetOverlappedResult(long ptr ptr long)
@ stdcall GetUserPreferredUILanguages(long ptr ptr ptr)
@ stdcall GetPackageFullName(long ptr ptr)
@ stdcall GetPhysicallyInstalledSystemMemory(ptr)
@ stdcall -import GetPhysicallyInstalledSystemMemory(ptr)
@ stdcall -import GetPriorityClass(long)
@ stdcall GetPrivateProfileIntA(str str long str)
@ stdcall GetPrivateProfileIntW(wstr wstr long wstr)
......@@ -906,7 +906,7 @@
@ stdcall GlobalHandle(ptr)
@ stdcall GlobalLock(long)
@ stdcall GlobalMemoryStatus(ptr)
@ stdcall GlobalMemoryStatusEx(ptr)
@ stdcall -import GlobalMemoryStatusEx(ptr)
@ stdcall GlobalReAlloc(long long long)
@ stdcall GlobalSize(long)
@ stdcall GlobalUnWire(long)
......
......@@ -614,7 +614,7 @@
# @ stub GetPackageVolumeSisPath
# @ stub GetPackagesByPackageFamily
# @ stub GetPerformanceInfo
@ stdcall GetPhysicallyInstalledSystemMemory(ptr) kernel32.GetPhysicallyInstalledSystemMemory
@ stdcall GetPhysicallyInstalledSystemMemory(ptr)
# @ stub GetPreviousFgPolicyRefreshInfoInternal
@ stdcall GetPriorityClass(long)
@ stdcall GetPrivateObjectSecurity(ptr long ptr long ptr)
......@@ -767,7 +767,7 @@
# @ stub GetXStateFeaturesMask
@ stdcall GlobalAlloc(long long)
@ stdcall GlobalFree(long)
@ stdcall GlobalMemoryStatusEx(ptr) kernel32.GlobalMemoryStatusEx
@ stdcall GlobalMemoryStatusEx(ptr)
# @ stub GuardCheckLongJumpTarget
# @ stub HasPolicyForegroundProcessingCompletedInternal
@ stdcall HashData(ptr long ptr long)
......
......@@ -38,6 +38,7 @@
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(heap);
WINE_DECLARE_DEBUG_CHANNEL(virtual);
/***********************************************************************
......@@ -817,6 +818,82 @@ BOOL WINAPI DECLSPEC_HOTPATCH FreeUserPhysicalPages( HANDLE process, ULONG_PTR *
/***********************************************************************
* GetPhysicallyInstalledSystemMemory (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH GetPhysicallyInstalledSystemMemory( ULONGLONG *memory )
{
MEMORYSTATUSEX status;
if (!memory)
{
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
}
status.dwLength = sizeof(status);
GlobalMemoryStatusEx( &status );
*memory = status.ullTotalPhys / 1024;
return TRUE;
}
/***********************************************************************
* GlobalMemoryStatusEx (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH GlobalMemoryStatusEx( MEMORYSTATUSEX *status )
{
static MEMORYSTATUSEX cached_status;
static DWORD last_check;
SYSTEM_BASIC_INFORMATION basic_info;
SYSTEM_PERFORMANCE_INFORMATION perf_info;
if (status->dwLength != sizeof(*status))
{
SetLastError( ERROR_INVALID_PARAMETER );
return FALSE;
}
if ((NtGetTickCount() - last_check) < 1000)
{
*status = cached_status;
return TRUE;
}
last_check = NtGetTickCount();
if (!set_ntstatus( NtQuerySystemInformation( SystemBasicInformation,
&basic_info, sizeof(basic_info), NULL )) ||
!set_ntstatus( NtQuerySystemInformation( SystemPerformanceInformation,
&perf_info, sizeof(perf_info), NULL)))
return FALSE;
status->dwMemoryLoad = 0;
status->ullTotalPhys = perf_info.TotalCommitLimit;
status->ullAvailPhys = perf_info.AvailablePages;
status->ullTotalPageFile = perf_info.TotalCommitLimit + 1; /* Titan Quest refuses to run if TotalPageFile <= TotalPhys */
status->ullAvailPageFile = status->ullTotalPageFile - perf_info.TotalCommittedPages - perf_info.AvailablePages;
status->ullTotalVirtual = (ULONG_PTR)basic_info.HighestUserAddress - (ULONG_PTR)basic_info.LowestUserAddress;
status->ullAvailVirtual = status->ullTotalVirtual - 64 * 1024; /* FIXME */
status->ullAvailExtendedVirtual = 0;
status->ullTotalPhys *= basic_info.PageSize;
status->ullAvailPhys *= basic_info.PageSize;
status->ullTotalPageFile *= basic_info.PageSize;
status->ullAvailPageFile *= basic_info.PageSize;
if (status->ullTotalPhys)
status->dwMemoryLoad = (status->ullTotalPhys - status->ullAvailPhys) / (status->ullTotalPhys / 100);
TRACE_(virtual)( "MemoryLoad %d, TotalPhys %s, AvailPhys %s, TotalPageFile %s,"
"AvailPageFile %s, TotalVirtual %s, AvailVirtual %s\n",
status->dwMemoryLoad, wine_dbgstr_longlong(status->ullTotalPhys),
wine_dbgstr_longlong(status->ullAvailPhys), wine_dbgstr_longlong(status->ullTotalPageFile),
wine_dbgstr_longlong(status->ullAvailPageFile), wine_dbgstr_longlong(status->ullTotalVirtual),
wine_dbgstr_longlong(status->ullAvailVirtual) );
cached_status = *status;
return TRUE;
}
/***********************************************************************
* MapUserPhysicalPages (kernelbase.@)
*/
BOOL WINAPI DECLSPEC_HOTPATCH MapUserPhysicalPages( void *addr, ULONG_PTR page_count, ULONG_PTR *pages )
......
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