29#include <sys/sysctl.h>
30#elif (OOLITE_LINUX || OOLITE_WINDOWS)
32#define __block __glibc_block
43#if OOLITE_LITTLE_ENDIAN
44#warning Little-endian.
46#if OOLITE_NATIVE_64_BIT
65 uint8_t endianTag[4] = {0x12, 0x34, 0x56, 0x78};
68 if (*(uint32_t*)endianTag != 0x12345678)
70 OOLog(
@"cpuInfo.endianTest.failed",
@"%@",
@"OOLITE_BIG_ENDIAN is set, but the system is not big-endian -- aborting.");
75#if OOLITE_LITTLE_ENDIAN
76 if (*(uint32_t*)endianTag != 0x78563412)
78 OOLog(
@"cpuInfo.endianTest.failed",
@"%@",
@"OOLITE_LITTLE_ENDIAN is set, but the system is not little-endian -- aborting.");
89 GetSystemInfo(&sysInfo);
91#elif defined _SC_NPROCESSORS_ONLN
94 #warning Do not know how to find number of CPUs on this architecture.
108#if (OOLITE_WINDOWS || OOLITE_LINUX)
110 #define OO_GNU_INLINE __attribute__((gnu_inline))
112 #define OO_GNU_INLINE
117inline OO_GNU_INLINE
void OOCPUID(
int CPUInfo[4],
int InfoType)
119 __asm__ __volatile__ (
126 :
"=a" (CPUInfo [0]),
"=r" (CPUInfo [1]),
"=c" (CPUInfo [2]),
"=d" (CPUInfo [3])
129 :
"=a" (CPUInfo [0]),
"=b" (CPUInfo [1]),
"=c" (CPUInfo [2]),
"=d" (CPUInfo [3])
135NSString* OOCPUDescription(
void)
138 int CPUInfo[4] = {-1};
139 unsigned nExIds, i = 0;
140 char CPUBrandString[0x40];
142 OOCPUID(CPUInfo, 0x80000000);
144 for (i=0x80000000; i<=nExIds; ++i)
149 memcpy(CPUBrandString, CPUInfo,
sizeof(CPUInfo));
150 else if (i == 0x80000003)
151 memcpy(CPUBrandString + 16, CPUInfo,
sizeof(CPUInfo));
152 else if (i == 0x80000004)
153 memcpy(CPUBrandString + 32, CPUInfo,
sizeof(CPUInfo));
155 return [NSString stringWithCString:CPUBrandString];
159OOMemoryStatus OOSystemMemoryStatus(
void)
161 const unsigned int toMegabyte = 1024 * 1024;
163 OOMemoryStatus systemMemoryStatus;
164 memset(&systemMemoryStatus, 0,
sizeof(systemMemoryStatus));
167 MEMORYSTATUSEX memStatus;
168 memStatus.dwLength =
sizeof(memStatus);
169 if(GlobalMemoryStatusEx(&memStatus))
172 systemMemoryStatus.ooPhysicalMemory = memStatus.ullTotalPhys / toMegabyte;
173 systemMemoryStatus.ooAvailableMemory = memStatus.ullAvailPhys / toMegabyte;
178 systemMemoryStatus.ooPhysicalMemory = (
unsigned long long)(si.totalram / toMegabyte);
179 systemMemoryStatus.ooAvailableMemory = (
unsigned long long)(si.freeram / toMegabyte);
182 return systemMemoryStatus;
188NSString* operatingSystemFullVersion(
void)
190 OSVERSIONINFOW osver;
191 char outUBRString[65] =
"";
193 osver.dwOSVersionInfoSize =
sizeof(osver);
194 GetVersionExW (&osver);
198 if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, L
"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", 0, KEY_READ, &hKey) == ERROR_SUCCESS)
200 DWORD dwUBRSize =
sizeof(DWORD);
202 if (RegQueryValueEx(hKey,
"UBR", NULL, NULL, (BYTE*)&dwUBR, &dwUBRSize) == ERROR_SUCCESS)
204 char strUBR[64] =
"";
205 ltoa(dwUBR, strUBR, 10);
206 strcpy(outUBRString,
".");
207 strcat(outUBRString, strUBR);
211 return [NSString stringWithFormat:@"%d.%d.%d%s %S",
212 osver.dwMajorVersion, osver.dwMinorVersion, osver.dwBuildNumber, outUBRString, osver.szCSDVersion];
219BOOL is64BitSystem(
void)
227 IW64PFP IW64P = (IW64PFP)GetProcAddress(GetModuleHandle(
"kernel32"),
"IsWow64Process");
230 IW64P(GetCurrentProcess(), &is64Bit);
static NSUInteger sNumberOfCPUs
NSUInteger OOCPUCount(void)
#define OOLog(class, format,...)
typedef long(ZCALLBACK *tell_file_func) OF((voidpf opaque