diff options
Diffstat (limited to 'CPP/Windows/SystemInfo.cpp')
-rw-r--r-- | CPP/Windows/SystemInfo.cpp | 917 |
1 files changed, 917 insertions, 0 deletions
diff --git a/CPP/Windows/SystemInfo.cpp b/CPP/Windows/SystemInfo.cpp new file mode 100644 index 0000000..d882a8e --- /dev/null +++ b/CPP/Windows/SystemInfo.cpp | |||
@@ -0,0 +1,917 @@ | |||
1 | // Windows/SystemInfo.cpp | ||
2 | |||
3 | #include "StdAfx.h" | ||
4 | |||
5 | #include "../../C/CpuArch.h" | ||
6 | |||
7 | #include "../Common/IntToString.h" | ||
8 | |||
9 | #ifdef _WIN32 | ||
10 | |||
11 | #include "Registry.h" | ||
12 | |||
13 | #else | ||
14 | |||
15 | #include <unistd.h> | ||
16 | #include <sys/utsname.h> | ||
17 | #ifdef __APPLE__ | ||
18 | #include <sys/sysctl.h> | ||
19 | #elif !defined(_AIX) | ||
20 | |||
21 | #include <sys/auxv.h> | ||
22 | |||
23 | // #undef AT_HWCAP // to debug | ||
24 | // #undef AT_HWCAP2 // to debug | ||
25 | |||
26 | /* the following patch for some debian systems. | ||
27 | Is it OK to define AT_HWCAP and AT_HWCAP2 here with these constant numbers? */ | ||
28 | /* | ||
29 | #if defined(__FreeBSD_kernel__) && defined(__GLIBC__) | ||
30 | #ifndef AT_HWCAP | ||
31 | #define AT_HWCAP 16 | ||
32 | #endif | ||
33 | #ifndef AT_HWCAP2 | ||
34 | #define AT_HWCAP2 26 | ||
35 | #endif | ||
36 | #endif | ||
37 | */ | ||
38 | |||
39 | #ifdef MY_CPU_ARM_OR_ARM64 | ||
40 | #include <asm/hwcap.h> | ||
41 | #endif | ||
42 | #endif | ||
43 | |||
44 | #ifdef __linux__ | ||
45 | #include "../Windows/FileIO.h" | ||
46 | #endif | ||
47 | |||
48 | #endif // WIN32 | ||
49 | |||
50 | #include "SystemInfo.h" | ||
51 | #include "System.h" | ||
52 | |||
53 | using namespace NWindows; | ||
54 | |||
55 | #ifdef __linux__ | ||
56 | |||
57 | static bool ReadFile_to_Buffer(CFSTR fileName, CByteBuffer &buf) | ||
58 | { | ||
59 | NWindows::NFile::NIO::CInFile file; | ||
60 | if (!file.Open(fileName)) | ||
61 | return false; | ||
62 | /* | ||
63 | UInt64 size; | ||
64 | if (!file.GetLength(size)) | ||
65 | { | ||
66 | // GetLength() doesn't work "/proc/cpuinfo" | ||
67 | return false; | ||
68 | } | ||
69 | if (size >= ((UInt32)1 << 29)) | ||
70 | return false; | ||
71 | */ | ||
72 | size_t size = 0; | ||
73 | size_t addSize = ((size_t)1 << 12); | ||
74 | for (;;) | ||
75 | { | ||
76 | // printf("\nsize = %d\n", (unsigned)size); | ||
77 | buf.ChangeSize_KeepData(size + addSize, size); | ||
78 | size_t processed; | ||
79 | if (!file.ReadFull(buf + size, addSize, processed)) | ||
80 | return false; | ||
81 | if (processed == 0) | ||
82 | { | ||
83 | buf.ChangeSize_KeepData(size, size); | ||
84 | return true; | ||
85 | } | ||
86 | size += processed; | ||
87 | addSize *= 2; | ||
88 | } | ||
89 | } | ||
90 | |||
91 | #endif | ||
92 | |||
93 | |||
94 | #if defined(_WIN32) || defined(AT_HWCAP) || defined(AT_HWCAP2) | ||
95 | static void PrintHex(AString &s, UInt64 v) | ||
96 | { | ||
97 | char temp[32]; | ||
98 | ConvertUInt64ToHex(v, temp); | ||
99 | s += temp; | ||
100 | } | ||
101 | #endif | ||
102 | |||
103 | #ifdef MY_CPU_X86_OR_AMD64 | ||
104 | |||
105 | static void PrintCpuChars(AString &s, UInt32 v) | ||
106 | { | ||
107 | for (int j = 0; j < 4; j++) | ||
108 | { | ||
109 | Byte b = (Byte)(v & 0xFF); | ||
110 | v >>= 8; | ||
111 | if (b == 0) | ||
112 | break; | ||
113 | s += (char)b; | ||
114 | } | ||
115 | } | ||
116 | |||
117 | |||
118 | static void x86cpuid_to_String(const Cx86cpuid &c, AString &s, AString &ver) | ||
119 | { | ||
120 | s.Empty(); | ||
121 | |||
122 | UInt32 maxFunc2 = 0; | ||
123 | UInt32 t[3]; | ||
124 | |||
125 | MyCPUID(0x80000000, &maxFunc2, &t[0], &t[1], &t[2]); | ||
126 | |||
127 | bool fullNameIsAvail = (maxFunc2 >= 0x80000004); | ||
128 | |||
129 | if (fullNameIsAvail) | ||
130 | { | ||
131 | for (unsigned i = 0; i < 3; i++) | ||
132 | { | ||
133 | UInt32 d[4] = { 0 }; | ||
134 | MyCPUID(0x80000002 + i, &d[0], &d[1], &d[2], &d[3]); | ||
135 | for (unsigned j = 0; j < 4; j++) | ||
136 | PrintCpuChars(s, d[j]); | ||
137 | } | ||
138 | } | ||
139 | |||
140 | s.Trim(); | ||
141 | |||
142 | if (s.IsEmpty()) | ||
143 | { | ||
144 | for (int i = 0; i < 3; i++) | ||
145 | PrintCpuChars(s, c.vendor[i]); | ||
146 | s.Trim(); | ||
147 | } | ||
148 | |||
149 | { | ||
150 | char temp[32]; | ||
151 | ConvertUInt32ToHex(c.ver, temp); | ||
152 | ver += temp; | ||
153 | } | ||
154 | } | ||
155 | |||
156 | /* | ||
157 | static void x86cpuid_all_to_String(AString &s) | ||
158 | { | ||
159 | Cx86cpuid p; | ||
160 | if (!x86cpuid_CheckAndRead(&p)) | ||
161 | return; | ||
162 | s += "x86cpuid maxFunc = "; | ||
163 | s.Add_UInt32(p.maxFunc); | ||
164 | for (unsigned j = 0; j <= p.maxFunc; j++) | ||
165 | { | ||
166 | s.Add_LF(); | ||
167 | // s.Add_UInt32(j); // align | ||
168 | { | ||
169 | char temp[32]; | ||
170 | ConvertUInt32ToString(j, temp); | ||
171 | unsigned len = (unsigned)strlen(temp); | ||
172 | while (len < 8) | ||
173 | { | ||
174 | len++; | ||
175 | s.Add_Space(); | ||
176 | } | ||
177 | s += temp; | ||
178 | } | ||
179 | |||
180 | s += ":"; | ||
181 | UInt32 d[4] = { 0 }; | ||
182 | MyCPUID(j, &d[0], &d[1], &d[2], &d[3]); | ||
183 | for (unsigned i = 0; i < 4; i++) | ||
184 | { | ||
185 | char temp[32]; | ||
186 | ConvertUInt32ToHex8Digits(d[i], temp); | ||
187 | s += " "; | ||
188 | s += temp; | ||
189 | } | ||
190 | } | ||
191 | } | ||
192 | */ | ||
193 | |||
194 | #endif | ||
195 | |||
196 | |||
197 | |||
198 | #ifdef _WIN32 | ||
199 | |||
200 | static const char * const k_PROCESSOR_ARCHITECTURE[] = | ||
201 | { | ||
202 | "x86" // "INTEL" | ||
203 | , "MIPS" | ||
204 | , "ALPHA" | ||
205 | , "PPC" | ||
206 | , "SHX" | ||
207 | , "ARM" | ||
208 | , "IA64" | ||
209 | , "ALPHA64" | ||
210 | , "MSIL" | ||
211 | , "x64" // "AMD64" | ||
212 | , "IA32_ON_WIN64" | ||
213 | , "NEUTRAL" | ||
214 | , "ARM64" | ||
215 | , "ARM32_ON_WIN64" | ||
216 | }; | ||
217 | |||
218 | #define MY__PROCESSOR_ARCHITECTURE_INTEL 0 | ||
219 | #define MY__PROCESSOR_ARCHITECTURE_AMD64 9 | ||
220 | |||
221 | |||
222 | #define MY__PROCESSOR_INTEL_PENTIUM 586 | ||
223 | #define MY__PROCESSOR_AMD_X8664 8664 | ||
224 | |||
225 | /* | ||
226 | static const CUInt32PCharPair k_PROCESSOR[] = | ||
227 | { | ||
228 | { 2200, "IA64" }, | ||
229 | { 8664, "x64" } | ||
230 | }; | ||
231 | |||
232 | #define PROCESSOR_INTEL_386 386 | ||
233 | #define PROCESSOR_INTEL_486 486 | ||
234 | #define PROCESSOR_INTEL_PENTIUM 586 | ||
235 | #define PROCESSOR_INTEL_860 860 | ||
236 | #define PROCESSOR_INTEL_IA64 2200 | ||
237 | #define PROCESSOR_AMD_X8664 8664 | ||
238 | #define PROCESSOR_MIPS_R2000 2000 | ||
239 | #define PROCESSOR_MIPS_R3000 3000 | ||
240 | #define PROCESSOR_MIPS_R4000 4000 | ||
241 | #define PROCESSOR_ALPHA_21064 21064 | ||
242 | #define PROCESSOR_PPC_601 601 | ||
243 | #define PROCESSOR_PPC_603 603 | ||
244 | #define PROCESSOR_PPC_604 604 | ||
245 | #define PROCESSOR_PPC_620 620 | ||
246 | #define PROCESSOR_HITACHI_SH3 10003 | ||
247 | #define PROCESSOR_HITACHI_SH3E 10004 | ||
248 | #define PROCESSOR_HITACHI_SH4 10005 | ||
249 | #define PROCESSOR_MOTOROLA_821 821 | ||
250 | #define PROCESSOR_SHx_SH3 103 | ||
251 | #define PROCESSOR_SHx_SH4 104 | ||
252 | #define PROCESSOR_STRONGARM 2577 // 0xA11 | ||
253 | #define PROCESSOR_ARM720 1824 // 0x720 | ||
254 | #define PROCESSOR_ARM820 2080 // 0x820 | ||
255 | #define PROCESSOR_ARM920 2336 // 0x920 | ||
256 | #define PROCESSOR_ARM_7TDMI 70001 | ||
257 | #define PROCESSOR_OPTIL 18767 // 0x494f | ||
258 | */ | ||
259 | |||
260 | |||
261 | /* | ||
262 | static const char * const k_PF[] = | ||
263 | { | ||
264 | "FP_ERRATA" | ||
265 | , "FP_EMU" | ||
266 | , "CMPXCHG" | ||
267 | , "MMX" | ||
268 | , "PPC_MOVEMEM_64BIT" | ||
269 | , "ALPHA_BYTE" | ||
270 | , "SSE" | ||
271 | , "3DNOW" | ||
272 | , "RDTSC" | ||
273 | , "PAE" | ||
274 | , "SSE2" | ||
275 | , "SSE_DAZ" | ||
276 | , "NX" | ||
277 | , "SSE3" | ||
278 | , "CMPXCHG16B" | ||
279 | , "CMP8XCHG16" | ||
280 | , "CHANNELS" | ||
281 | , "XSAVE" | ||
282 | , "ARM_VFP_32" | ||
283 | , "ARM_NEON" | ||
284 | , "L2AT" | ||
285 | , "VIRT_FIRMWARE" | ||
286 | , "RDWRFSGSBASE" | ||
287 | , "FASTFAIL" | ||
288 | , "ARM_DIVIDE" | ||
289 | , "ARM_64BIT_LOADSTORE_ATOMIC" | ||
290 | , "ARM_EXTERNAL_CACHE" | ||
291 | , "ARM_FMAC" | ||
292 | , "RDRAND" | ||
293 | , "ARM_V8" | ||
294 | , "ARM_V8_CRYPTO" | ||
295 | , "ARM_V8_CRC32" | ||
296 | , "RDTSCP" | ||
297 | , "RDPID" | ||
298 | , "ARM_V81_ATOMIC" | ||
299 | , "MONITORX" | ||
300 | }; | ||
301 | */ | ||
302 | |||
303 | #endif | ||
304 | |||
305 | |||
306 | #ifdef _WIN32 | ||
307 | |||
308 | static void PrintPage(AString &s, UInt32 v) | ||
309 | { | ||
310 | if ((v & 0x3FF) == 0) | ||
311 | { | ||
312 | s.Add_UInt32(v >> 10); | ||
313 | s += "K"; | ||
314 | } | ||
315 | else | ||
316 | s.Add_UInt32(v >> 10); | ||
317 | } | ||
318 | |||
319 | static AString TypeToString2(const char * const table[], unsigned num, UInt32 value) | ||
320 | { | ||
321 | char sz[16]; | ||
322 | const char *p = NULL; | ||
323 | if (value < num) | ||
324 | p = table[value]; | ||
325 | if (!p) | ||
326 | { | ||
327 | ConvertUInt32ToString(value, sz); | ||
328 | p = sz; | ||
329 | } | ||
330 | return (AString)p; | ||
331 | } | ||
332 | |||
333 | // #if defined(_7ZIP_LARGE_PAGES) || defined(_WIN32) | ||
334 | // #ifdef _WIN32 | ||
335 | void PrintSize_KMGT_Or_Hex(AString &s, UInt64 v) | ||
336 | { | ||
337 | char c = 0; | ||
338 | if ((v & 0x3FF) == 0) { v >>= 10; c = 'K'; | ||
339 | if ((v & 0x3FF) == 0) { v >>= 10; c = 'M'; | ||
340 | if ((v & 0x3FF) == 0) { v >>= 10; c = 'G'; | ||
341 | if ((v & 0x3FF) == 0) { v >>= 10; c = 'T'; | ||
342 | }}}} | ||
343 | else | ||
344 | { | ||
345 | PrintHex(s, v); | ||
346 | return; | ||
347 | } | ||
348 | char temp[32]; | ||
349 | ConvertUInt64ToString(v, temp); | ||
350 | s += temp; | ||
351 | if (c) | ||
352 | s += c; | ||
353 | } | ||
354 | // #endif | ||
355 | // #endif | ||
356 | |||
357 | static void SysInfo_To_String(AString &s, const SYSTEM_INFO &si) | ||
358 | { | ||
359 | s += TypeToString2(k_PROCESSOR_ARCHITECTURE, ARRAY_SIZE(k_PROCESSOR_ARCHITECTURE), si.wProcessorArchitecture); | ||
360 | |||
361 | if (!( (si.wProcessorArchitecture == MY__PROCESSOR_ARCHITECTURE_INTEL && si.dwProcessorType == MY__PROCESSOR_INTEL_PENTIUM) | ||
362 | || (si.wProcessorArchitecture == MY__PROCESSOR_ARCHITECTURE_AMD64 && si.dwProcessorType == MY__PROCESSOR_AMD_X8664))) | ||
363 | { | ||
364 | s += " "; | ||
365 | // s += TypePairToString(k_PROCESSOR, ARRAY_SIZE(k_PROCESSOR), si.dwProcessorType); | ||
366 | s.Add_UInt32(si.dwProcessorType); | ||
367 | } | ||
368 | s += " "; | ||
369 | PrintHex(s, si.wProcessorLevel); | ||
370 | s += "."; | ||
371 | PrintHex(s, si.wProcessorRevision); | ||
372 | if ((UInt64)si.dwActiveProcessorMask + 1 != ((UInt64)1 << si.dwNumberOfProcessors)) | ||
373 | if ((UInt64)si.dwActiveProcessorMask + 1 != 0 || si.dwNumberOfProcessors != sizeof(UInt64) * 8) | ||
374 | { | ||
375 | s += " act:"; | ||
376 | PrintHex(s, si.dwActiveProcessorMask); | ||
377 | } | ||
378 | s += " cpus:"; | ||
379 | s.Add_UInt32(si.dwNumberOfProcessors); | ||
380 | if (si.dwPageSize != 1 << 12) | ||
381 | { | ||
382 | s += " page:"; | ||
383 | PrintPage(s, si.dwPageSize); | ||
384 | } | ||
385 | if (si.dwAllocationGranularity != 1 << 16) | ||
386 | { | ||
387 | s += " gran:"; | ||
388 | PrintPage(s, si.dwAllocationGranularity); | ||
389 | } | ||
390 | s += " "; | ||
391 | |||
392 | DWORD_PTR minAdd = (DWORD_PTR)si.lpMinimumApplicationAddress; | ||
393 | UInt64 maxSize = (UInt64)(DWORD_PTR)si.lpMaximumApplicationAddress + 1; | ||
394 | const UInt32 kReserveSize = ((UInt32)1 << 16); | ||
395 | if (minAdd != kReserveSize) | ||
396 | { | ||
397 | PrintSize_KMGT_Or_Hex(s, minAdd); | ||
398 | s += "-"; | ||
399 | } | ||
400 | else | ||
401 | { | ||
402 | if ((maxSize & (kReserveSize - 1)) == 0) | ||
403 | maxSize += kReserveSize; | ||
404 | } | ||
405 | PrintSize_KMGT_Or_Hex(s, maxSize); | ||
406 | } | ||
407 | |||
408 | #ifndef _WIN64 | ||
409 | EXTERN_C_BEGIN | ||
410 | typedef VOID (WINAPI *Func_GetNativeSystemInfo)(LPSYSTEM_INFO lpSystemInfo); | ||
411 | EXTERN_C_END | ||
412 | #endif | ||
413 | |||
414 | #endif | ||
415 | |||
416 | #ifdef __APPLE__ | ||
417 | #ifndef MY_CPU_X86_OR_AMD64 | ||
418 | static void Add_sysctlbyname_to_String(const char *name, AString &s) | ||
419 | { | ||
420 | size_t bufSize = 256; | ||
421 | char buf[256]; | ||
422 | if (My_sysctlbyname_Get(name, &buf, &bufSize) == 0) | ||
423 | s += buf; | ||
424 | } | ||
425 | #endif | ||
426 | #endif | ||
427 | |||
428 | void GetSysInfo(AString &s1, AString &s2); | ||
429 | void GetSysInfo(AString &s1, AString &s2) | ||
430 | { | ||
431 | s1.Empty(); | ||
432 | s2.Empty(); | ||
433 | |||
434 | #ifdef _WIN32 | ||
435 | SYSTEM_INFO si; | ||
436 | GetSystemInfo(&si); | ||
437 | { | ||
438 | SysInfo_To_String(s1, si); | ||
439 | // s += " : "; | ||
440 | } | ||
441 | |||
442 | #if !defined(_WIN64) && !defined(UNDER_CE) | ||
443 | Func_GetNativeSystemInfo fn_GetNativeSystemInfo = (Func_GetNativeSystemInfo)(void *)GetProcAddress( | ||
444 | GetModuleHandleA("kernel32.dll"), "GetNativeSystemInfo"); | ||
445 | if (fn_GetNativeSystemInfo) | ||
446 | { | ||
447 | SYSTEM_INFO si2; | ||
448 | fn_GetNativeSystemInfo(&si2); | ||
449 | // if (memcmp(&si, &si2, sizeof(si)) != 0) | ||
450 | { | ||
451 | // s += " - "; | ||
452 | SysInfo_To_String(s2, si2); | ||
453 | } | ||
454 | } | ||
455 | #endif | ||
456 | #endif | ||
457 | } | ||
458 | |||
459 | |||
460 | void GetCpuName(AString &s); | ||
461 | |||
462 | static void AddBracedString(AString &dest, AString &src) | ||
463 | { | ||
464 | if (!src.IsEmpty()) | ||
465 | { | ||
466 | AString s; | ||
467 | s += '('; | ||
468 | s += src; | ||
469 | s += ')'; | ||
470 | dest.Add_OptSpaced(s); | ||
471 | } | ||
472 | } | ||
473 | |||
474 | struct CCpuName | ||
475 | { | ||
476 | AString CpuName; | ||
477 | AString Revision; | ||
478 | AString Microcode; | ||
479 | AString LargePages; | ||
480 | |||
481 | void Fill(); | ||
482 | |||
483 | void Get_Revision_Microcode_LargePages(AString &s) | ||
484 | { | ||
485 | s.Empty(); | ||
486 | AddBracedString(s, Revision); | ||
487 | AddBracedString(s, Microcode); | ||
488 | s.Add_OptSpaced(LargePages); | ||
489 | } | ||
490 | }; | ||
491 | |||
492 | void CCpuName::Fill() | ||
493 | { | ||
494 | CpuName.Empty(); | ||
495 | Revision.Empty(); | ||
496 | Microcode.Empty(); | ||
497 | LargePages.Empty(); | ||
498 | |||
499 | AString &s = CpuName; | ||
500 | |||
501 | #ifdef MY_CPU_X86_OR_AMD64 | ||
502 | { | ||
503 | Cx86cpuid cpuid; | ||
504 | if (x86cpuid_CheckAndRead(&cpuid)) | ||
505 | { | ||
506 | x86cpuid_to_String(cpuid, s, Revision); | ||
507 | } | ||
508 | else | ||
509 | { | ||
510 | #ifdef MY_CPU_AMD64 | ||
511 | s += "x64"; | ||
512 | #else | ||
513 | s += "x86"; | ||
514 | #endif | ||
515 | } | ||
516 | } | ||
517 | #elif defined(__APPLE__) | ||
518 | { | ||
519 | Add_sysctlbyname_to_String("machdep.cpu.brand_string", s); | ||
520 | } | ||
521 | #endif | ||
522 | |||
523 | |||
524 | if (s.IsEmpty()) | ||
525 | { | ||
526 | #ifdef MY_CPU_LE | ||
527 | s += "LE"; | ||
528 | #elif defined(MY_CPU_BE) | ||
529 | s += "BE"; | ||
530 | #endif | ||
531 | } | ||
532 | |||
533 | #ifdef __APPLE__ | ||
534 | { | ||
535 | AString s2; | ||
536 | UInt32 v = 0; | ||
537 | if (My_sysctlbyname_Get_UInt32("machdep.cpu.core_count", &v) == 0) | ||
538 | { | ||
539 | s2.Add_UInt32(v); | ||
540 | s2 += 'C'; | ||
541 | } | ||
542 | if (My_sysctlbyname_Get_UInt32("machdep.cpu.thread_count", &v) == 0) | ||
543 | { | ||
544 | s2.Add_UInt32(v); | ||
545 | s2 += 'T'; | ||
546 | } | ||
547 | if (!s2.IsEmpty()) | ||
548 | { | ||
549 | s.Add_Space_if_NotEmpty(); | ||
550 | s += s2; | ||
551 | } | ||
552 | } | ||
553 | #endif | ||
554 | |||
555 | |||
556 | #ifdef _WIN32 | ||
557 | { | ||
558 | NRegistry::CKey key; | ||
559 | if (key.Open(HKEY_LOCAL_MACHINE, TEXT("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0"), KEY_READ) == ERROR_SUCCESS) | ||
560 | { | ||
561 | LONG res[2]; | ||
562 | CByteBuffer bufs[2]; | ||
563 | { | ||
564 | for (int i = 0; i < 2; i++) | ||
565 | { | ||
566 | UInt32 size = 0; | ||
567 | res[i] = key.QueryValue(i == 0 ? | ||
568 | TEXT("Previous Update Revision") : | ||
569 | TEXT("Update Revision"), bufs[i], size); | ||
570 | if (res[i] == ERROR_SUCCESS) | ||
571 | if (size != bufs[i].Size()) | ||
572 | res[i] = ERROR_SUCCESS + 1; | ||
573 | } | ||
574 | } | ||
575 | if (res[0] == ERROR_SUCCESS || res[1] == ERROR_SUCCESS) | ||
576 | { | ||
577 | for (int i = 0; i < 2; i++) | ||
578 | { | ||
579 | if (i == 1) | ||
580 | Microcode += "->"; | ||
581 | if (res[i] != ERROR_SUCCESS) | ||
582 | continue; | ||
583 | const CByteBuffer &buf = bufs[i]; | ||
584 | if (buf.Size() == 8) | ||
585 | { | ||
586 | UInt32 high = GetUi32(buf); | ||
587 | if (high != 0) | ||
588 | { | ||
589 | PrintHex(Microcode, high); | ||
590 | Microcode += "."; | ||
591 | } | ||
592 | PrintHex(Microcode, GetUi32(buf + 4)); | ||
593 | } | ||
594 | } | ||
595 | } | ||
596 | } | ||
597 | } | ||
598 | #endif | ||
599 | |||
600 | |||
601 | #ifdef _7ZIP_LARGE_PAGES | ||
602 | Add_LargePages_String(LargePages); | ||
603 | #endif | ||
604 | } | ||
605 | |||
606 | void AddCpuFeatures(AString &s); | ||
607 | void AddCpuFeatures(AString &s) | ||
608 | { | ||
609 | #ifdef _WIN32 | ||
610 | // const unsigned kNumFeatures_Extra = 32; // we check also for unknown features | ||
611 | // const unsigned kNumFeatures = ARRAY_SIZE(k_PF) + kNumFeatures_Extra; | ||
612 | const unsigned kNumFeatures = 64; | ||
613 | UInt64 flags = 0; | ||
614 | for (unsigned i = 0; i < kNumFeatures; i++) | ||
615 | { | ||
616 | if (IsProcessorFeaturePresent(i)) | ||
617 | { | ||
618 | flags += (UInt64)1 << i; | ||
619 | // s.Add_Space_if_NotEmpty(); | ||
620 | // s += TypeToString2(k_PF, ARRAY_SIZE(k_PF), i); | ||
621 | } | ||
622 | } | ||
623 | s.Add_OptSpaced("f:"); | ||
624 | PrintHex(s, flags); | ||
625 | |||
626 | #elif defined(__APPLE__) | ||
627 | { | ||
628 | UInt32 v = 0; | ||
629 | if (My_sysctlbyname_Get_UInt32("hw.pagesize", &v) == 0) | ||
630 | { | ||
631 | s += "PageSize:"; | ||
632 | s.Add_UInt32(v >> 10); | ||
633 | s += "KB"; | ||
634 | } | ||
635 | } | ||
636 | |||
637 | #else | ||
638 | |||
639 | const long v = sysconf(_SC_PAGESIZE); | ||
640 | if (v != -1) | ||
641 | { | ||
642 | s.Add_Space_if_NotEmpty(); | ||
643 | s += "PageSize:"; | ||
644 | s.Add_UInt32((UInt32)(v >> 10)); | ||
645 | s += "KB"; | ||
646 | } | ||
647 | |||
648 | #if !defined(_AIX) | ||
649 | |||
650 | #ifdef __linux__ | ||
651 | |||
652 | CByteBuffer buf; | ||
653 | if (ReadFile_to_Buffer("/sys/kernel/mm/transparent_hugepage/enabled", buf)) | ||
654 | // if (ReadFile_to_Buffer("/proc/cpuinfo", buf)) | ||
655 | { | ||
656 | s.Add_OptSpaced("THP:"); | ||
657 | AString s2; | ||
658 | s2.SetFrom_CalcLen((const char *)(const void *)(const Byte *)buf, (unsigned)buf.Size()); | ||
659 | const int pos = s2.Find('['); | ||
660 | if (pos >= 0) | ||
661 | { | ||
662 | const int pos2 = s2.Find(']', pos + 1); | ||
663 | if (pos2 >= 0) | ||
664 | { | ||
665 | s2.DeleteFrom(pos2); | ||
666 | s2.DeleteFrontal(pos + 1); | ||
667 | } | ||
668 | } | ||
669 | s += s2; | ||
670 | } | ||
671 | // else throw CSystemException(MY_SRes_HRESULT_FROM_WRes(errno)); | ||
672 | |||
673 | #endif | ||
674 | |||
675 | |||
676 | #ifdef AT_HWCAP | ||
677 | s.Add_OptSpaced("hwcap:"); | ||
678 | { | ||
679 | unsigned long h = getauxval(AT_HWCAP); | ||
680 | PrintHex(s, h); | ||
681 | #ifdef MY_CPU_ARM64 | ||
682 | if (h & HWCAP_CRC32) s += ":CRC32"; | ||
683 | if (h & HWCAP_SHA1) s += ":SHA1"; | ||
684 | if (h & HWCAP_SHA2) s += ":SHA2"; | ||
685 | if (h & HWCAP_AES) s += ":AES"; | ||
686 | if (h & HWCAP_ASIMD) s += ":ASIMD"; | ||
687 | #elif defined(MY_CPU_ARM) | ||
688 | if (h & HWCAP_NEON) s += ":NEON"; | ||
689 | #endif | ||
690 | } | ||
691 | #endif // AT_HWCAP | ||
692 | |||
693 | #ifdef AT_HWCAP2 | ||
694 | { | ||
695 | unsigned long h = getauxval(AT_HWCAP2); | ||
696 | #ifndef MY_CPU_ARM | ||
697 | if (h != 0) | ||
698 | #endif | ||
699 | { | ||
700 | s += " hwcap2:"; | ||
701 | PrintHex(s, h); | ||
702 | #ifdef MY_CPU_ARM | ||
703 | if (h & HWCAP2_CRC32) s += ":CRC32"; | ||
704 | if (h & HWCAP2_SHA1) s += ":SHA1"; | ||
705 | if (h & HWCAP2_SHA2) s += ":SHA2"; | ||
706 | if (h & HWCAP2_AES) s += ":AES"; | ||
707 | #endif | ||
708 | } | ||
709 | } | ||
710 | #endif // AT_HWCAP2 | ||
711 | #endif // _AIX | ||
712 | #endif // _WIN32 | ||
713 | } | ||
714 | |||
715 | |||
716 | #ifdef _WIN32 | ||
717 | #ifndef UNDER_CE | ||
718 | |||
719 | EXTERN_C_BEGIN | ||
720 | typedef void (WINAPI * Func_RtlGetVersion) (OSVERSIONINFOEXW *); | ||
721 | EXTERN_C_END | ||
722 | |||
723 | static BOOL My_RtlGetVersion(OSVERSIONINFOEXW *vi) | ||
724 | { | ||
725 | HMODULE ntdll = ::GetModuleHandleW(L"ntdll.dll"); | ||
726 | if (!ntdll) | ||
727 | return FALSE; | ||
728 | Func_RtlGetVersion func = (Func_RtlGetVersion)(void *)GetProcAddress(ntdll, "RtlGetVersion"); | ||
729 | if (!func) | ||
730 | return FALSE; | ||
731 | func(vi); | ||
732 | return TRUE; | ||
733 | } | ||
734 | |||
735 | #endif | ||
736 | #endif | ||
737 | |||
738 | |||
739 | void GetOsInfoText(AString &sRes) | ||
740 | { | ||
741 | sRes.Empty(); | ||
742 | AString s; | ||
743 | |||
744 | #ifdef _WIN32 | ||
745 | #ifndef UNDER_CE | ||
746 | // OSVERSIONINFO vi; | ||
747 | OSVERSIONINFOEXW vi; | ||
748 | vi.dwOSVersionInfoSize = sizeof(vi); | ||
749 | // if (::GetVersionEx(&vi)) | ||
750 | if (My_RtlGetVersion(&vi)) | ||
751 | { | ||
752 | s += "Windows"; | ||
753 | if (vi.dwPlatformId != VER_PLATFORM_WIN32_NT) | ||
754 | s.Add_UInt32(vi.dwPlatformId); | ||
755 | s += " "; s.Add_UInt32(vi.dwMajorVersion); | ||
756 | s += "."; s.Add_UInt32(vi.dwMinorVersion); | ||
757 | s += " "; s.Add_UInt32(vi.dwBuildNumber); | ||
758 | |||
759 | if (vi.wServicePackMajor != 0 || vi.wServicePackMinor != 0) | ||
760 | { | ||
761 | s += " SP:"; s.Add_UInt32(vi.wServicePackMajor); | ||
762 | s += "."; s.Add_UInt32(vi.wServicePackMinor); | ||
763 | } | ||
764 | // s += " Suite:"; PrintHex(s, vi.wSuiteMask); | ||
765 | // s += " Type:"; s.Add_UInt32(vi.wProductType); | ||
766 | // s += " "; s += GetOemString(vi.szCSDVersion); | ||
767 | } | ||
768 | /* | ||
769 | { | ||
770 | s += " OEMCP:"; s.Add_UInt32(GetOEMCP()); | ||
771 | s += " ACP:"; s.Add_UInt32(GetACP()); | ||
772 | } | ||
773 | */ | ||
774 | #endif | ||
775 | #else // _WIN32 | ||
776 | |||
777 | if (!s.IsEmpty()) | ||
778 | s.Add_LF(); | ||
779 | struct utsname un; | ||
780 | if (uname(&un) == 0) | ||
781 | { | ||
782 | s += un.sysname; | ||
783 | // s += " : "; s += un.nodename; // we don't want to show name of computer | ||
784 | s += " : "; s += un.release; | ||
785 | s += " : "; s += un.version; | ||
786 | s += " : "; s += un.machine; | ||
787 | |||
788 | #ifdef __APPLE__ | ||
789 | // Add_sysctlbyname_to_String("kern.version", s); | ||
790 | // it's same as "utsname.version" | ||
791 | #endif | ||
792 | } | ||
793 | #endif // _WIN32 | ||
794 | |||
795 | sRes += s; | ||
796 | } | ||
797 | |||
798 | |||
799 | |||
800 | void GetSystemInfoText(AString &sRes) | ||
801 | { | ||
802 | GetOsInfoText(sRes); | ||
803 | sRes.Add_LF(); | ||
804 | |||
805 | { | ||
806 | AString s, s1, s2; | ||
807 | GetSysInfo(s1, s2); | ||
808 | if (!s1.IsEmpty() || !s2.IsEmpty()) | ||
809 | { | ||
810 | s = s1; | ||
811 | if (s1 != s2 && !s2.IsEmpty()) | ||
812 | { | ||
813 | s += " - "; | ||
814 | s += s2; | ||
815 | } | ||
816 | } | ||
817 | { | ||
818 | AddCpuFeatures(s); | ||
819 | if (!s.IsEmpty()) | ||
820 | { | ||
821 | sRes += s; | ||
822 | sRes.Add_LF(); | ||
823 | } | ||
824 | } | ||
825 | } | ||
826 | { | ||
827 | AString s; | ||
828 | GetCpuName(s); | ||
829 | if (!s.IsEmpty()) | ||
830 | { | ||
831 | sRes += s; | ||
832 | sRes.Add_LF(); | ||
833 | } | ||
834 | } | ||
835 | /* | ||
836 | #ifdef MY_CPU_X86_OR_AMD64 | ||
837 | { | ||
838 | AString s; | ||
839 | x86cpuid_all_to_String(s); | ||
840 | if (!s.IsEmpty()) | ||
841 | { | ||
842 | printCallback->Print(s); | ||
843 | printCallback->NewLine(); | ||
844 | } | ||
845 | } | ||
846 | #endif | ||
847 | */ | ||
848 | } | ||
849 | |||
850 | |||
851 | void GetCpuName(AString &s); | ||
852 | void GetCpuName(AString &s) | ||
853 | { | ||
854 | CCpuName cpuName; | ||
855 | cpuName.Fill(); | ||
856 | s = cpuName.CpuName; | ||
857 | AString s2; | ||
858 | cpuName.Get_Revision_Microcode_LargePages(s2); | ||
859 | s.Add_OptSpaced(s2); | ||
860 | } | ||
861 | |||
862 | |||
863 | void GetCpuName_MultiLine(AString &s); | ||
864 | void GetCpuName_MultiLine(AString &s) | ||
865 | { | ||
866 | CCpuName cpuName; | ||
867 | cpuName.Fill(); | ||
868 | s = cpuName.CpuName; | ||
869 | AString s2; | ||
870 | cpuName.Get_Revision_Microcode_LargePages(s2); | ||
871 | if (!s2.IsEmpty()) | ||
872 | { | ||
873 | s.Add_LF(); | ||
874 | s += s2; | ||
875 | } | ||
876 | } | ||
877 | |||
878 | void GetCompiler(AString &s) | ||
879 | { | ||
880 | #ifdef __VERSION__ | ||
881 | s += __VERSION__; | ||
882 | #endif | ||
883 | |||
884 | #ifdef __GNUC__ | ||
885 | s += " GCC "; | ||
886 | s.Add_UInt32(__GNUC__); | ||
887 | s += '.'; | ||
888 | s.Add_UInt32(__GNUC_MINOR__); | ||
889 | s += '.'; | ||
890 | s.Add_UInt32(__GNUC_PATCHLEVEL__); | ||
891 | #endif | ||
892 | |||
893 | #ifdef __clang__ | ||
894 | s += " CLANG "; | ||
895 | s.Add_UInt32(__clang_major__); | ||
896 | s += '.'; | ||
897 | s.Add_UInt32(__clang_minor__); | ||
898 | #endif | ||
899 | |||
900 | #ifdef __xlC__ | ||
901 | s += " XLC "; | ||
902 | s.Add_UInt32(__xlC__ >> 8); | ||
903 | s += '.'; | ||
904 | s.Add_UInt32(__xlC__ & 0xFF); | ||
905 | #ifdef __xlC_ver__ | ||
906 | s += '.'; | ||
907 | s.Add_UInt32(__xlC_ver__ >> 8); | ||
908 | s += '.'; | ||
909 | s.Add_UInt32(__xlC_ver__ & 0xFF); | ||
910 | #endif | ||
911 | #endif | ||
912 | |||
913 | #ifdef _MSC_VER | ||
914 | s += " MSC "; | ||
915 | s.Add_UInt32(_MSC_VER); | ||
916 | #endif | ||
917 | } | ||