mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-28 18:31:45 +00:00
we noticed that vcbuild somehow excludes winit function pointers from components that don't contain externals referenced by the main EXE (i.e. wposix, wnuma, wsock). the solution will include calling enet_initialize (to replace or coexist with wsock), removing wposix (see below) and ignoring wnuma (because apps that use it will need to call its functions).
wposix's sysconf is no longer used because OS X doesn't support some of the POSIX names, so we had to add os_cpu routines that supplant the use of sysconf. am now removing the no-longer needed sysconf emulation, which also gets rid of wposix_Init. This was SVN commit r7680.
This commit is contained in:
@@ -148,11 +148,11 @@ size_t os_cpu_LargePageSize()
|
||||
}
|
||||
|
||||
|
||||
static void GetMemoryStatus(MEMORYSTATUSEX& mse)
|
||||
static void GetMemoryStatusEx(MEMORYSTATUSEX& mse)
|
||||
{
|
||||
// note: we no longer bother dynamically importing GlobalMemoryStatusEx -
|
||||
// it's available on Win2k and above. this function safely handles
|
||||
// systems with > 4 GB of memory.
|
||||
// it's available starting with Win2k and avoids overflow/wraparound
|
||||
// on systems with >= 4 GB of memory.
|
||||
mse.dwLength = sizeof(mse);
|
||||
const BOOL ok = GlobalMemoryStatusEx(&mse);
|
||||
WARN_IF_FALSE(ok);
|
||||
@@ -165,7 +165,7 @@ size_t os_cpu_MemorySize()
|
||||
if(memorySizeMiB == 0)
|
||||
{
|
||||
MEMORYSTATUSEX mse;
|
||||
GetMemoryStatus(mse);
|
||||
GetMemoryStatusEx(mse);
|
||||
DWORDLONG memorySize = mse.ullTotalPhys;
|
||||
|
||||
// Richter, "Programming Applications for Windows": the reported
|
||||
@@ -184,7 +184,7 @@ size_t os_cpu_MemorySize()
|
||||
size_t os_cpu_MemoryAvailable()
|
||||
{
|
||||
MEMORYSTATUSEX mse;
|
||||
GetMemoryStatus(mse);
|
||||
GetMemoryStatusEx(mse);
|
||||
const size_t memoryAvailableMiB = size_t(mse.ullAvailPhys / MiB);
|
||||
return memoryAvailableMiB;
|
||||
}
|
||||
|
||||
@@ -30,8 +30,6 @@
|
||||
#include "lib/sysdep/os/win/wposix/wposix_internal.h"
|
||||
#include "lib/bits.h"
|
||||
|
||||
WINIT_REGISTER_CRITICAL_INIT(wposix_Init); // wposix -> error handling
|
||||
|
||||
|
||||
int setenv(const char* envname, const char* envval, int overwrite)
|
||||
{
|
||||
@@ -46,101 +44,3 @@ int setenv(const char* envname, const char* envval, int overwrite)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// sysconf
|
||||
|
||||
// used by _SC_PAGESIZE and _SC_*_PAGES
|
||||
static DWORD pageSize;
|
||||
static DWORD numProcessors;
|
||||
typedef BOOL (WINAPI *PGlobalMemoryStatusEx)(MEMORYSTATUSEX*);
|
||||
static PGlobalMemoryStatusEx pGlobalMemoryStatusEx;
|
||||
|
||||
// NB: called from critical init
|
||||
static void InitSysconf()
|
||||
{
|
||||
SYSTEM_INFO si;
|
||||
GetSystemInfo(&si); // can't fail
|
||||
pageSize = si.dwPageSize; // used by _SC_PAGESIZE and _SC_*_PAGES
|
||||
numProcessors = si.dwNumberOfProcessors;
|
||||
|
||||
// import GlobalMemoryStatusEx - it's not defined by the VC6 PSDK.
|
||||
// used by _SC_*_PAGES if available (provides better results).
|
||||
const HMODULE hKernel32Dll = GetModuleHandleW(L"kernel32.dll");
|
||||
pGlobalMemoryStatusEx = (PGlobalMemoryStatusEx)GetProcAddress(hKernel32Dll, "GlobalMemoryStatusEx");
|
||||
}
|
||||
|
||||
long sysconf(int name)
|
||||
{
|
||||
// called before InitSysconf => winit/wstartup are broken. this is
|
||||
// going to cause a hard crash because debug.cpp's error reporting
|
||||
// code requires the page size to be known. we'll raise an exception
|
||||
// with a unique value so that this issue is immediately noticed.
|
||||
if(!pageSize)
|
||||
RaiseException(0xFA57FA57, 0, 0, 0);
|
||||
|
||||
switch(name)
|
||||
{
|
||||
case _SC_PAGESIZE:
|
||||
// note: no separate case for _SC_PAGE_SIZE - they are
|
||||
// different names but have the same value.
|
||||
return pageSize;
|
||||
|
||||
case _SC_PHYS_PAGES:
|
||||
case _SC_AVPHYS_PAGES:
|
||||
{
|
||||
u64 total_phys_mem;
|
||||
u64 avail_phys_mem;
|
||||
|
||||
// first query GlobalMemoryStatus - cannot fail.
|
||||
// override its results if GlobalMemoryStatusEx is available.
|
||||
{
|
||||
MEMORYSTATUS ms;
|
||||
GlobalMemoryStatus(&ms);
|
||||
total_phys_mem = ms.dwTotalPhys;
|
||||
avail_phys_mem = ms.dwAvailPhys;
|
||||
}
|
||||
|
||||
// newer API is available: use it to report correct results
|
||||
// (no overflow or wraparound) on systems with > 4 GB of memory.
|
||||
{
|
||||
MEMORYSTATUSEX mse = { sizeof(mse) };
|
||||
if(pGlobalMemoryStatusEx && pGlobalMemoryStatusEx(&mse))
|
||||
{
|
||||
total_phys_mem = mse.ullTotalPhys;
|
||||
avail_phys_mem = mse.ullAvailPhys;
|
||||
}
|
||||
// else: not an error, since this isn't available before Win2k / XP.
|
||||
// we have results from GlobalMemoryStatus anyway.
|
||||
}
|
||||
|
||||
// Richter, "Programming Applications for Windows": the reported
|
||||
// value doesn't include non-paged pool reserved during boot;
|
||||
// it's not considered available to kernel. (size is 528 KiB on
|
||||
// a 512 MiB WinXP/Win2k machine)
|
||||
// something similar may happen on other OSes, so it is fixed
|
||||
// by cpu.cpp instead of here.
|
||||
|
||||
if(name == _SC_PHYS_PAGES)
|
||||
return (long)(total_phys_mem / pageSize);
|
||||
else
|
||||
return (long)(avail_phys_mem / pageSize);
|
||||
}
|
||||
|
||||
case _SC_NPROCESSORS_CONF:
|
||||
return numProcessors;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static LibError wposix_Init()
|
||||
{
|
||||
InitSysconf();
|
||||
return INFO::OK;
|
||||
}
|
||||
|
||||
@@ -55,20 +55,6 @@
|
||||
LIB_API int setenv(const char* envname, const char* envval, int overwrite);
|
||||
|
||||
|
||||
//
|
||||
// <unistd.h>
|
||||
//
|
||||
|
||||
// user tests if available via #ifdef; can't use enum.
|
||||
#define _SC_PAGESIZE 1
|
||||
#define _SC_PAGE_SIZE 1
|
||||
#define _SC_PHYS_PAGES 2
|
||||
#define _SC_AVPHYS_PAGES 3
|
||||
#define _SC_NPROCESSORS_CONF 4
|
||||
|
||||
LIB_API long sysconf(int name);
|
||||
|
||||
|
||||
//
|
||||
// <math.h>
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user