Fix system memory check

git-svn-id: https://svn.eduke32.com/eduke32@7333 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
terminx 2019-02-18 22:02:50 +00:00
parent af83ff0675
commit 360ee42e0e

View file

@ -574,8 +574,9 @@ typedef BOOL (WINAPI *aGlobalMemoryStatusExType)(LPMEMORYSTATUSEX);
uint32_t Bgetsysmemsize(void) uint32_t Bgetsysmemsize(void)
{ {
#ifdef _WIN32
uint32_t siz = UINT32_MAX; uint32_t siz = UINT32_MAX;
#ifdef _WIN32
HMODULE lib = LoadLibrary("KERNEL32.DLL"); HMODULE lib = LoadLibrary("KERNEL32.DLL");
if (lib) if (lib)
@ -592,7 +593,7 @@ uint32_t Bgetsysmemsize(void)
siz = min<decltype(memst.ullTotalPhys)>(UINT32_MAX, memst.ullTotalPhys); siz = min<decltype(memst.ullTotalPhys)>(UINT32_MAX, memst.ullTotalPhys);
} }
if (siz == UINT32_MAX || siz == 0) if (!aGlobalMemoryStatusEx || siz == 0)
{ {
initprintf("Bgetsysmemsize(): error determining system memory size!\n"); initprintf("Bgetsysmemsize(): error determining system memory size!\n");
siz = UINT32_MAX; siz = UINT32_MAX;
@ -601,10 +602,7 @@ uint32_t Bgetsysmemsize(void)
FreeLibrary(lib); FreeLibrary(lib);
} }
else initprintf("Bgetsysmemsize(): unable to load KERNEL32.DLL!\n"); else initprintf("Bgetsysmemsize(): unable to load KERNEL32.DLL!\n");
return siz;
#elif (defined(_SC_PAGE_SIZE) || defined(_SC_PAGESIZE)) && defined(_SC_PHYS_PAGES) && !defined(GEKKO) #elif (defined(_SC_PAGE_SIZE) || defined(_SC_PAGESIZE)) && defined(_SC_PHYS_PAGES) && !defined(GEKKO)
uint32_t siz = UINT32_MAX;
#ifdef _SC_PAGE_SIZE #ifdef _SC_PAGE_SIZE
int64_t const scpagesiz = sysconf(_SC_PAGE_SIZE); int64_t const scpagesiz = sysconf(_SC_PAGE_SIZE);
#else #else
@ -613,15 +611,14 @@ uint32_t Bgetsysmemsize(void)
int64_t const scphyspages = sysconf(_SC_PHYS_PAGES); int64_t const scphyspages = sysconf(_SC_PHYS_PAGES);
if (scpagesiz >= 0 && scphyspages >= 0) if (scpagesiz >= 0 && scphyspages >= 0)
siz = min<uint32_t>(UINT32_MAX, scpagesiz * scphyspages); siz = (uint32_t)min<uint64_t>(UINT32_MAX, scpagesiz * scphyspages);
//initprintf("Bgetsysmemsize(): %d pages of %d bytes, %d bytes of system memory\n", //initprintf("Bgetsysmemsize(): %d pages of %d bytes, %d bytes of system memory\n",
// scphyspages, scpagesiz, siz); // scphyspages, scpagesiz, siz);
return siz;
#else
return UINT32_MAX;
#endif #endif
return siz;
} }
#ifdef GEKKO #ifdef GEKKO