diff options
-rw-r--r-- | src/common/sysinfo.c | 53 | ||||
-rw-r--r-- | src/common/sysinfo.h | 1 | ||||
-rw-r--r-- | src/common/thread.c | 5 |
3 files changed, 41 insertions, 18 deletions
diff --git a/src/common/sysinfo.c b/src/common/sysinfo.c index 40ef6cfc0..5ecb7b5ad 100644 --- a/src/common/sysinfo.c +++ b/src/common/sysinfo.c @@ -607,6 +607,37 @@ void sysinfo_osversion_retrieve(void) { } typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO); + +/** + * Retrieves SYSTEM_INFO (Windows only) + * System info is not stored anywhere after retrieval + * @see http://msdn.microsoft.com/en-us/library/windows/desktop/ms724958(v=vs.85).aspx + **/ +void sysinfo_systeminfo_retrieve( LPSYSTEM_INFO info ) { + PGNSI pGNSI; + + // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise. + pGNSI = (PGNSI) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo"); + if (NULL != pGNSI) + pGNSI(info); + else + GetSystemInfo(info); + + return; +} + +/** + * Returns number of bytes in a memory page + * Only needed when compiling with MSVC + **/ +long sysinfo_getpagesize( void ) { + SYSTEM_INFO si; + ZeroMemory(&si, sizeof(SYSTEM_INFO)); + + sysinfo_systeminfo_retrieve(&si); + return si.dwPageSize; +} + /** * Retrieves the CPU type (Windows only). * @@ -615,7 +646,6 @@ typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO); */ void sysinfo_cpu_retrieve(void) { StringBuf buf; - PGNSI pGNSI; SYSTEM_INFO si; ZeroMemory(&si, sizeof(SYSTEM_INFO)); StrBuf->Init(&buf); @@ -625,12 +655,7 @@ void sysinfo_cpu_retrieve(void) { sysinfo->p->cpu = NULL; } - // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise. - pGNSI = (PGNSI) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo"); - if (NULL != pGNSI) - pGNSI(&si); - else - GetSystemInfo(&si); + sysinfo_systeminfo_retrieve(&si); if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL || si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64 @@ -656,7 +681,6 @@ void sysinfo_cpu_retrieve(void) { * Once retrieved, the name is stored into sysinfo->p->arch. */ void sysinfo_arch_retrieve(void) { - PGNSI pGNSI; SYSTEM_INFO si; ZeroMemory(&si, sizeof(SYSTEM_INFO)); @@ -665,12 +689,7 @@ void sysinfo_arch_retrieve(void) { sysinfo->p->arch = NULL; } - // Call GetNativeSystemInfo if supported or GetSystemInfo otherwise. - pGNSI = (PGNSI) GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo"); - if (NULL != pGNSI) - pGNSI(&si); - else - GetSystemInfo(&si); + sysinfo_systeminfo_retrieve(&si); if (si.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) // x64 sysinfo->p->arch = aStrdup("x86_64"); @@ -1018,7 +1037,11 @@ void sysinfo_defaults(void) { sysinfo = &sysinfo_s; memset(&sysinfo_p, '\0', sizeof(sysinfo_p)); sysinfo->p = &sysinfo_p; - +#if defined(WIN32) && !defined(__CYGWIN__) + sysinfo->getpagesize = sysinfo_getpagesize; +#else + sysinfo->getpagesize = getpagesize(); +#endif sysinfo->platform = sysinfo_platform; sysinfo->osversion = sysinfo_osversion; sysinfo->cpu = sysinfo_cpu; diff --git a/src/common/sysinfo.h b/src/common/sysinfo.h index c0c4d276a..97f14d0f2 100644 --- a/src/common/sysinfo.h +++ b/src/common/sysinfo.h @@ -21,6 +21,7 @@ struct sysinfo_private; struct sysinfo_interface { struct sysinfo_private *p; + long (*getpagesize) (void); const char *(*platform) (void); const char *(*osversion) (void); const char *(*cpu) (void); diff --git a/src/common/thread.c b/src/common/thread.c index 4be37d576..933ee2c0e 100644 --- a/src/common/thread.c +++ b/src/common/thread.c @@ -10,13 +10,13 @@ #include "thread.h" +#include "../common/sysinfo.h" // sysinfo->getpagesize() #include "../common/cbasetypes.h" #include "../common/malloc.h" #include "../common/showmsg.h" #ifdef WIN32 # include "../common/winapi.h" -# define getpagesize() 4096 // @TODO: implement this properly (GetSystemInfo .. dwPageSize..). (Atm as on all supported win platforms its 4k its static.) # define __thread __declspec( thread ) #else # include <pthread.h> @@ -32,7 +32,6 @@ #define HAS_TLS #endif - #define RA_THREADS_MAX 64 struct rAthread { @@ -170,7 +169,7 @@ rAthread rathread_createEx( rAthreadProc entryPoint, void *param, size_t szSta // given stacksize aligned to systems pagesize? - tmp = szStack % getpagesize(); + tmp = szStack % sysinfo->getpagesize(); if(tmp != 0) szStack += tmp; |