diff --git a/CMakeLists.txt b/CMakeLists.txt index 5df5a740d..124b8aca0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -574,6 +574,8 @@ IF(KWSYS_USE_SystemTools) ENDIF() IF(KWSYS_USE_SystemInformation) + SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS SIZEOF_VOID_P=${CMAKE_SIZEOF_VOID_P}) IF(NOT CYGWIN) INCLUDE(CheckIncludeFiles) CHECK_INCLUDE_FILES("sys/types.h;ifaddrs.h" KWSYS_SYS_HAS_IFADDRS_H) @@ -638,6 +640,20 @@ IF(KWSYS_USE_SystemInformation) SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY COMPILE_DEFINITIONS KWSYS_CXX_HAS__ATOI64=1) ENDIF() + IF(BORLAND) + KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_BORLAND_ASM + "Checking whether Borland CXX compiler supports assembler instructions" DIRECT) + IF(KWSYS_CXX_HAS_BORLAND_ASM) + SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS KWSYS_CXX_HAS_BORLAND_ASM=1) + KWSYS_PLATFORM_CXX_TEST(KWSYS_CXX_HAS_BORLAND_ASM_CPUID + "Checking whether Borland CXX compiler supports CPUID assembler instruction" DIRECT) + IF(KWSYS_CXX_HAS_BORLAND_ASM_CPUID) + SET_PROPERTY(SOURCE SystemInformation.cxx APPEND PROPERTY + COMPILE_DEFINITIONS KWSYS_CXX_HAS_BORLAND_ASM_CPUID=1) + ENDIF() + ENDIF() + ENDIF() IF(KWSYS_USE___INT64) SET_PROPERTY(SOURCE SystemInformation.cxx testSystemInformation.cxx APPEND PROPERTY COMPILE_DEFINITIONS KWSYS_USE___INT64=1) diff --git a/ProcessUNIX.c b/ProcessUNIX.c index 83838affc..2db12544c 100644 --- a/ProcessUNIX.c +++ b/ProcessUNIX.c @@ -418,9 +418,10 @@ int kwsysProcess_AddCommand(kwsysProcess* cp, char const* const* command) parse it. */ newCommands[cp->NumberOfCommands] = kwsysSystem_Parse_CommandForUnix(*command, 0); - if(!newCommands[cp->NumberOfCommands]) + if(!newCommands[cp->NumberOfCommands] || + !newCommands[cp->NumberOfCommands][0]) { - /* Out of memory. */ + /* Out of memory or no command parsed. */ free(newCommands); return 0; } diff --git a/SystemInformation.cxx b/SystemInformation.cxx index 59a9abe6b..b20d72458 100644 --- a/SystemInformation.cxx +++ b/SystemInformation.cxx @@ -202,7 +202,7 @@ typedef struct rlimit ResourceLimitType; #define USE_CPUID_INTRINSICS 0 #endif -#if USE_ASM_INSTRUCTIONS || USE_CPUID_INTRINSICS +#if USE_ASM_INSTRUCTIONS || USE_CPUID_INTRINSICS || defined(KWSYS_CXX_HAS_BORLAND_ASM_CPUID) # define USE_CPUID 1 #else # define USE_CPUID 0 @@ -224,6 +224,7 @@ static bool call_cpuid(int select, int result[4]) return true; #else int tmp[4]; +#if defined(_MSC_VER) // Use SEH to determine CPUID presence __try { _asm { @@ -262,7 +263,24 @@ static bool call_cpuid(int select, int result[4]) return false; } - memcpy(result, tmp, sizeof(tmp)); + memcpy(result, tmp, sizeof(tmp)); +#elif defined(KWSYS_CXX_HAS_BORLAND_ASM_CPUID) + unsigned int a, b, c, d; + __asm { + mov EAX, select; + cpuid + mov a, EAX; + mov b, EBX; + mov c, ECX; + mov d, EDX; + } + + result[0] = a; + result[1] = b; + result[2] = c; + result[3] = d; +#endif + // The cpuid instruction succeeded. return true; #endif @@ -432,7 +450,7 @@ protected: int CPUCount(); unsigned char LogicalCPUPerPhysicalCPU(); unsigned char GetAPICId(); - unsigned int IsHyperThreadingSupported(); + bool IsHyperThreadingSupported(); static LongLong GetCyclesDifference(DELAY_FUNC, unsigned int); // For Linux and Cygwin, /proc/cpuinfo formats are slightly different @@ -456,7 +474,8 @@ protected: kwsys_stl::string SysCtlBuffer; // For Solaris - bool QuerySolarisInfo(); + bool QuerySolarisMemory(); + bool QuerySolarisProcessor(); kwsys_stl::string ParseValueFromKStat(const char* arguments); kwsys_stl::string RunProcess(kwsys_stl::vector args); @@ -481,9 +500,11 @@ protected: //For AIX bool QueryAIXMemory(); + bool QueryProcessorBySysconf(); bool QueryProcessor(); // Evaluate the memory information. + bool QueryMemoryBySysconf(); bool QueryMemory(); size_t TotalVirtualMemory; size_t AvailableVirtualMemory; @@ -1287,7 +1308,7 @@ void SystemInformationImplementation::RunCPUCheck() #elif defined(__APPLE__) this->ParseSysCtl(); #elif defined (__SVR4) && defined (__sun) - this->QuerySolarisInfo(); + this->QuerySolarisProcessor(); #elif defined(__HAIKU__) this->QueryHaikuInfo(); #elif defined(__QNX__) @@ -1313,7 +1334,7 @@ void SystemInformationImplementation::RunMemoryCheck() #if defined(__APPLE__) this->ParseSysCtl(); #elif defined (__SVR4) && defined (__sun) - this->QuerySolarisInfo(); + this->QuerySolarisMemory(); #elif defined(__HAIKU__) this->QueryHaikuInfo(); #elif defined(__QNX__) @@ -3016,7 +3037,7 @@ bool SystemInformationImplementation::RetreiveInformationFromCpuInfoFile() return true; } -bool SystemInformationImplementation::QueryProcessor() +bool SystemInformationImplementation::QueryProcessorBySysconf() { #if defined(_SC_NPROC_ONLN) && !defined(_SC_NPROCESSORS_ONLN) // IRIX names this slightly different @@ -3039,6 +3060,11 @@ bool SystemInformationImplementation::QueryProcessor() #endif } +bool SystemInformationImplementation::QueryProcessor() +{ + return this->QueryProcessorBySysconf(); +} + /** Get total system RAM in units of KiB. */ @@ -3559,8 +3585,7 @@ bool SystemInformationImplementation::QueryAIXMemory() #endif } -/** Query for the memory status */ -bool SystemInformationImplementation::QueryMemory() +bool SystemInformationImplementation::QueryMemoryBySysconf() { #if defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE) // Assume the mmap() granularity as returned by _SC_PAGESIZE is also @@ -3597,6 +3622,12 @@ bool SystemInformationImplementation::QueryMemory() #endif } +/** Query for the memory status */ +bool SystemInformationImplementation::QueryMemory() +{ + return this->QueryMemoryBySysconf(); +} + /** */ size_t SystemInformationImplementation::GetTotalVirtualMemory() { @@ -3729,8 +3760,13 @@ unsigned char SystemInformationImplementation::LogicalCPUPerPhysicalCPU(void) /** Works only for windows */ -unsigned int SystemInformationImplementation::IsHyperThreadingSupported() +bool SystemInformationImplementation::IsHyperThreadingSupported() { + if (this->Features.ExtendedFeatures.SupportsHyperthreading) + { + return true; + } + #if USE_CPUID int Regs[4] = { 0, 0, 0, 0 }, VendorId[4] = { 0, 0, 0, 0 }; @@ -3748,13 +3784,15 @@ unsigned int SystemInformationImplementation::IsHyperThreadingSupported() if (((Regs[0] & FAMILY_ID) == PENTIUM4_ID) || (Regs[0] & EXT_FAMILY_ID)) { - if (VendorId[1] == 'uneG') + if (VendorId[1] == 0x756e6547) // 'uneG' { - if (VendorId[3] == 'Ieni') + if (VendorId[3] == 0x49656e69) // 'Ieni' { - if (VendorId[2] == 'letn') + if (VendorId[2] == 0x6c65746e) // 'letn' { - return(Regs[3] & HT_BIT); // Genuine Intel with hyper-Threading technology + // Genuine Intel with hyper-Threading technology + this->Features.ExtendedFeatures.SupportsHyperthreading = ((Regs[3] & HT_BIT) != 0); + return this->Features.ExtendedFeatures.SupportsHyperthreading; } } } @@ -4251,16 +4289,40 @@ kwsys_stl::string SystemInformationImplementation::ParseValueFromKStat(const cha return value; } - /** Querying for system information from Solaris */ -bool SystemInformationImplementation::QuerySolarisInfo() +bool SystemInformationImplementation::QuerySolarisMemory() { - // Parse values - this->NumberOfPhysicalCPU = static_cast( - atoi(this->ParseValueFromKStat("-n syste_misc -s ncpus").c_str())); - this->NumberOfLogicalCPU = this->NumberOfPhysicalCPU; - this->Features.ExtendedFeatures.LogicalProcessorsPerPhysical = 1; +#if defined (__SVR4) && defined (__sun) + // Solaris allows querying this value by sysconf, but if this is + // a 32 bit process on a 64 bit host the returned memory will be + // limited to 4GiB. So if this is a 32 bit process or if the sysconf + // method fails use the kstat interface. +#if SIZEOF_VOID_P == 8 + if (this->QueryMemoryBySysconf()) + { + return true; + } +#endif + char* tail; + unsigned long totalMemory = + strtoul(this->ParseValueFromKStat("-s physmem").c_str(),&tail,0); + this->TotalPhysicalMemory = totalMemory/128; + + return true; +#else + return false; +#endif +} + +bool SystemInformationImplementation::QuerySolarisProcessor() +{ + if (!this->QueryProcessorBySysconf()) + { + return false; + } + + // Parse values this->CPUSpeedInMHz = static_cast(atoi(this->ParseValueFromKStat("-s clock_MHz").c_str())); // Chip family @@ -4277,20 +4339,6 @@ bool SystemInformationImplementation::QuerySolarisInfo() this->FindManufacturer(); } - // Cache size - this->Features.L1CacheSize = 0; - this->Features.L2CacheSize = 0; - - char* tail; - unsigned long totalMemory = - strtoul(this->ParseValueFromKStat("-s physmem").c_str(),&tail,0); - this->TotalPhysicalMemory = totalMemory/128; - - // Undefined values (for now at least) - this->TotalVirtualMemory = 0; - this->AvailablePhysicalMemory = 0; - this->AvailableVirtualMemory = 0; - return true; } diff --git a/kwsysPlatformTestsCXX.cxx b/kwsysPlatformTestsCXX.cxx index ae5870342..48976c442 100644 --- a/kwsysPlatformTestsCXX.cxx +++ b/kwsysPlatformTestsCXX.cxx @@ -580,3 +580,30 @@ int main() } } #endif + +#ifdef TEST_KWSYS_CXX_HAS_BORLAND_ASM +int main() +{ + int a = 1; + __asm { + xor EBX, EBX; + mov a, EBX; + } + + return a; +} +#endif + +#ifdef TEST_KWSYS_CXX_HAS_BORLAND_ASM_CPUID +int main() +{ + int a = 0; + __asm { + xor EAX, EAX; + cpuid; + mov a, EAX; + } + + return a; +} +#endif