File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -125,6 +125,31 @@ bool IsRunningInXen()
125125 return true ;
126126}
127127
128+ Result<uint64_t > GetPhysicallyInstalledSystemMemoryApi ()
129+ {
130+ using FnGetPhysicallyInstalledSystemMemory = BOOL (__stdcall*)(PULONGLONG);
131+
132+ static FnGetPhysicallyInstalledSystemMemory fn = nullptr ;
133+ if (fn == nullptr )
134+ {
135+ fn = reinterpret_cast <FnGetPhysicallyInstalledSystemMemory>(
136+ ::GetProcAddress (GetModuleHandleA(" kernel32.dll" ), "GetPhysicallyInstalledSystemMemory"));
137+ if (!fn)
138+ {
139+ return LastWin32Error ();
140+ }
141+ }
142+
143+ uint64_t installed = 0 ;
144+ BOOL ret = fn (&installed);
145+ if (!ret)
146+ {
147+ return LastWin32Error ();
148+ }
149+
150+ return installed;
151+ }
152+
128153} // namespace
129154
130155namespace Orc {
@@ -724,6 +749,26 @@ Result<uint64_t> SystemDetails::GetPhysicalMemoryAdjustedSize()
724749 return roundedToGB;
725750}
726751
752+ // Attempt to get the real installed memory size (GlobalMemoryStatusEx exclude some bytes)
753+ Result<uint64_t > SystemDetails::GetPhysicalMemoryInstalledSize ()
754+ {
755+ auto memory = ::GetPhysicallyInstalledSystemMemoryApi ();
756+ if (memory)
757+ {
758+ return *memory * 1024 ;
759+ }
760+
761+ Log::Debug (" Failed GetPhysicallyInstalledSystemMemory [{}]" , memory);
762+
763+ memory = SystemDetails::GetPhysicalMemoryAdjustedSize ();
764+ if (memory)
765+ {
766+ return *memory;
767+ }
768+
769+ return memory.error ();
770+ }
771+
727772HRESULT SystemDetails::GetPageSize (DWORD& dwPageSize)
728773{
729774 HRESULT hr = E_FAIL;
Original file line number Diff line number Diff line change @@ -77,6 +77,7 @@ class SystemDetails
7777
7878 static Result<MEMORYSTATUSEX> GetPhysicalMemory ();
7979 static Result<uint64_t > GetPhysicalMemoryAdjustedSize ();
80+ static Result<uint64_t > GetPhysicalMemoryInstalledSize ();
8081
8182 static HRESULT GetPageSize (DWORD& dwPageSize);
8283 static HRESULT GetLargePageSize (DWORD& dwPageSize);
You can’t perform that action at this time.
0 commit comments