500
507
Str_Strcpy(distroShort, STR_OS_RED_HAT, distroShortSize);
509
} else if (strstr(distroLower, "opensuse")) {
510
Str_Strcpy(distroShort, STR_OS_OPENSUSE, distroShortSize);
502
511
} else if (strstr(distroLower, "suse")) {
503
512
if (strstr(distroLower, "enterprise")) {
504
if (strstr(distroLower, "server 11")) {
513
if (strstr(distroLower, "server 11") ||
514
strstr(distroLower, "desktop 11")) {
505
515
Str_Strcpy(distroShort, STR_OS_SLES_11, distroShortSize);
506
} else if (strstr(distroLower, "server 10")) {
516
} else if (strstr(distroLower, "server 10") ||
517
strstr(distroLower, "desktop 10")) {
507
518
Str_Strcpy(distroShort, STR_OS_SLES_10, distroShortSize);
509
Str_Strcpy(distroShort, STR_OS_SUSE_EN, distroShortSize);
520
Str_Strcpy(distroShort, STR_OS_SLES, distroShortSize);
511
522
} else if (strstr(distroLower, "sun")) {
512
523
Str_Strcpy(distroShort, STR_OS_SUN_DESK, distroShortSize);
549
560
} else if (strstr(distroLower, "5.0")) {
550
561
Str_Strcpy(distroShort, STR_OS_DEBIAN_5, distroShortSize);
552
} else if (StrUtil_StartsWith(distroLower, "enterprise linux")) {
563
} else if (StrUtil_StartsWith(distroLower, "enterprise linux") ||
564
StrUtil_StartsWith(distroLower, "oracle")) {
554
566
* [root@localhost ~]# lsb_release -sd
555
567
* "Enterprise Linux Enterprise Linux Server release 5.4 (Carthage)"
557
569
* Not sure why they didn't brand their releases as "Oracle Enterprise
570
* Linux". Oh well. It's fixed in 6.0, though.
560
572
Str_Strcpy(distroShort, STR_OS_ORACLE, distroShortSize);
561
573
} else if (strstr(distroLower, "fedora")) {
840
846
Str_Strcpy(osName, STR_OS_EMPTY, sizeof osName);
841
Str_Sprintf(osNameFull, sizeof osNameFull, "%s %s", buf.sysname, buf.release);
844
* Check to see if this is Linux
845
* If yes, determine the distro by looking for /etc/xxx file.
847
Str_Sprintf(osNameFull, sizeof osNameFull, "%s %s", buf.sysname,
850
#if defined __APPLE__
853
* The easiest way is to invoke "system_profiler" and hope that the
854
* format of its unlocalized output will never change.
856
* Alternatively, we could do what system_profiler does and use the
857
* CFPropertyList/CFDIctionary APIs to parse
858
* /System/Library/CoreServices/{Server,System}Version.plist.
860
* On a MacBookPro4,1 (and possibly other models), invoking
861
* "system_profiler" can take several seconds: it seems to spin up the CD
862
* drive as a side-effect. So use "system_profiler SPSoftwareDataType"
866
char *sysname = HostinfoGetCmdOutput(
867
"/usr/sbin/system_profiler SPSoftwareDataType"
868
" | /usr/bin/grep 'System Version:'"
869
" | /usr/bin/cut -d : -f 2");
872
char *trimmed = Unicode_Trim(sysname);
874
ASSERT_MEM_ALLOC(trimmed);
876
Str_Snprintf(osNameFull, sizeof osNameFull, "%s", trimmed);
879
Log("%s: Failed to get output of system_profiler.\n", __FUNCTION__);
880
/* Fall back to returning the original osNameFull. */
883
if (Gestalt(gestaltSystemVersionMajor, &major) == 0) {
885
* XXX: some places in the code refer to Mac OS X Lion (10.7?)
886
* as "darwin11", which is not what this code is doing. Once it's
887
* released and we support it, this code may need some tweaking.
889
Str_Snprintf(osName, sizeof osName, "%s%d", STR_OS_MACOS, (int) major);
890
} else if (Gestalt(gestaltSystemVersion, &major) == 0) {
891
/* Pre 10.3 Mac OS doesn't have gestaltSystemVersionMajor. */
893
major = (major & 0xFF00) >> 8;
894
Str_Snprintf(osName, sizeof osName, "%s%x", STR_OS_MACOS, (int) major);
896
Log("Call to Gestalt() failed!\n");
897
Str_Snprintf(osName, sizeof osName, "%s", STR_OS_MACOS);
901
// XXX Use compile-time instead of run-time checks for these as well.
848
902
if (strstr(osNameFull, "Linux")) {
849
903
char distro[DISTRO_BUF_SIZE];
850
904
char distroShort[DISTRO_BUF_SIZE];
852
int distroSize = sizeof distro;
905
static int const distroSize = sizeof distro;
855
909
* Write default distro string depending on the kernel version. If
1017
#if defined(VMX86_SERVER)
1019
*----------------------------------------------------------------------
1021
* HostinfoReadProc --
1023
* Depending on what string is passed to it, this function parses the
1024
* /proc/vmware/sched/ncpus node and returns the requested value.
1074
*-----------------------------------------------------------------------------
1076
* Hostinfo_CPUCounts --
1078
* Get a count of CPUs for the host.
1079
* pkgs := total number of sockets/packages
1080
* cores := total number of actual cores (not including hyperthreads)
1081
* logical := total schedulable threads, as seen by host scheduler
1082
* Depending on available host OS interfaces, these numbers may be
1083
* either "active" or "possible", so do not depend upon them for
1086
* As an example, a 2 socket Nehalem (4 cores + HT) would return:
1087
* pkgs = 2, cores = 8, logical = 16
1089
* Again, this interface is generally not useful b/c of its potential
1090
* inaccuracy (especially with hotplug!) and because it is only implemented
1093
* If you are trying to use this interface, it probably means you are doing
1094
* something 'clever' with licensing. Don't.
1027
* A postive value on success, -1 (0xFFFFFFFF) on failure.
1097
* TRUE if sane numbers are populated, FALSE otherwise.
1029
1099
* Side effects:
1032
*----------------------------------------------------------------------
1102
*-----------------------------------------------------------------------------
1036
HostinfoReadProc(const char *str) // IN:
1106
Hostinfo_CPUCounts(uint32 *logical, // OUT
1107
uint32 *cores, // OUT
1108
uint32 *pkgs) // OUT
1038
/* XXX this should use sysinfo!! (bug 59849)
1110
#if defined __APPLE__
1112
* Lame logic. Because Apple doesn't really expose this info,
1113
* we'd only use it for licensing anyway, and we just plain
1114
* don't need it on Apple except that VMHS stuffs it somewhere
1115
* and may result in a division-by-zero if we don't provide it.
1117
*logical = Hostinfo_NumCPUs();
1118
*pkgs = *logical > 4 ? 2 : 1;
1119
*cores = *logical / *pkgs;
1122
#elif defined __linux__
1044
ASSERT(!strcmp("logical", str) || !strcmp("cores", str) ||
1045
!strcmp("packages", str));
1047
ASSERT(!HostType_OSIsVMK()); // Don't use /proc/vmware
1049
f = Posix_Fopen("/proc/vmware/sched/ncpus", "r");
1052
while (StdIO_ReadNextLine(f, &line, 0, NULL) == StdIO_Success) {
1053
if (strstr(line, str)) {
1054
if (sscanf(line, "%d ", &count) == 1) {
1073
*----------------------------------------------------------------------
1075
* Hostinfo_HTDisabled --
1077
* Figure out if hyperthreading is enabled
1080
* TRUE if hyperthreading is disabled, FALSE otherwise
1085
*----------------------------------------------------------------------
1089
Hostinfo_HTDisabled(void)
1091
static uint32 logical = 0, cores = 0;
1093
if (HostType_OSIsVMK()) {
1094
return VMKernel_HTEnabledCPU() != VMK_OK;
1097
if (logical == 0 && cores == 0) {
1098
logical = HostinfoReadProc("logical");
1099
cores = HostinfoReadProc("cores");
1101
if (logical <= 0 || cores <= 0) {
1102
logical = cores = 0;
1106
return logical == cores;
1108
#endif /*ifdef VMX86_SERVER*/
1125
unsigned count = 0, coresPerProc = 0, siblingsPerProc = 0;
1127
f = Posix_Fopen("/proc/cpuinfo", "r");
1132
while (StdIO_ReadNextLine(f, &line, 0, NULL) == StdIO_Success) {
1133
if (strncmp(line, "processor", strlen("processor")) == 0) {
1136
/* Assume all processors are identical, so just read the first. */
1137
if (coresPerProc == 0) {
1138
sscanf(line, "cpu cores : %u", &coresPerProc);
1140
if (siblingsPerProc == 0) {
1141
sscanf(line, "siblings : %u", &siblingsPerProc);
1149
*pkgs = siblingsPerProc > 0 ? count / siblingsPerProc : count;
1150
*cores = coresPerProc > 0 ? *pkgs * coresPerProc : *pkgs;
1152
Log(LGPFX" This machine has %u physical CPUS, %u total cores, and %u "
1153
"logical CPUs.\n", *pkgs, *cores, *logical);
1771
1814
*----------------------------------------------------------------------
1773
* Hostinfo_TouchBackDoor --
1775
* Access the backdoor. This is used to determine if we are
1776
* running in a VM or on a physical host. On a physical host
1777
* this should generate a GP which we catch and thereby determine
1778
* that we are not in a VM. However some OSes do not handle the
1779
* GP correctly and the process continues running returning garbage.
1780
* In this case we check the EBX register which should be
1781
* BDOOR_MAGIC if the IN was handled in a VM. Based on this we
1782
* return either TRUE or FALSE.
1785
* TRUE if we succesfully accessed the backdoor, FALSE or segfault
1789
* Exception if not in a VM.
1791
*----------------------------------------------------------------------
1795
Hostinfo_TouchBackDoor(void)
1798
* XXX: This can cause Apple's Crash Reporter to erroneously display
1799
* a crash, even though the process has caught the SIGILL and handled
1803
#if !defined(__APPLE__) && (defined(__i386__) || defined(__x86_64__))
1808
__asm__ __volatile__(
1809
# if defined __PIC__ && !vm_x86_64 // %ebx is reserved by the compiler.
1810
"xchgl %%ebx, %1" "\n\t"
1811
"inl %%dx, %%eax" "\n\t"
1821
: "0" (BDOOR_MAGIC),
1823
"2" (BDOOR_CMD_GETVERSION),
1826
if (ebx == BDOOR_MAGIC) {
1836
*----------------------------------------------------------------------
1838
* Hostinfo_TouchVirtualPC --
1840
* Access MS Virtual PC's backdoor. This is used to determine if
1841
* we are running in a MS Virtual PC or on a physical host. Works
1842
* the same as Hostinfo_TouchBackDoor, except the entry to MS VPC
1843
* is an invalid opcode instead or writing to a port. Since
1844
* MS VPC is 32-bit only, the 64-bit path returns FALSE.
1845
* See: http://www.codeproject.com/KB/system/VmDetect.aspx
1848
* TRUE if we succesfully accessed MS Virtual PC, FALSE or
1852
* Exception if not in a VM.
1854
*----------------------------------------------------------------------
1858
Hostinfo_TouchVirtualPC(void)
1860
#if defined vm_x86_64
1866
__asm__ __volatile__ (
1867
# if defined __PIC__ // %ebx is reserved by the compiler.
1868
"xchgl %%ebx, %1" "\n\t"
1869
".long 0x0B073F0F" "\n\t"
1881
return !ebxval; // %%ebx is zero if inside Virtual PC
1887
*----------------------------------------------------------------------
1889
* Hostinfo_NestingSupported --
1891
* Access the backdoor with a nesting control query. This is used
1892
* to determine if we are running inside a VM that supports nesting.
1893
* This function should only be called after determining that the
1894
* backdoor is present with Hostinfo_TouchBackdoor().
1897
* TRUE if the outer VM supports nesting.
1901
* Exception if not in a VM, so don't do that!
1903
*----------------------------------------------------------------------
1907
Hostinfo_NestingSupported(void)
1909
#if defined(__i386__) || defined(__x86_64__)
1910
uint32 cmd = NESTING_CONTROL_QUERY << 16 | BDOOR_CMD_NESTING_CONTROL;
1913
__asm__ __volatile__(
1916
: "0" (BDOOR_MAGIC),
1921
if (result >= NESTING_CONTROL_QUERY && result != ~0U) {
1931
*----------------------------------------------------------------------
1933
1816
* Hostinfo_ResetProcessState --
1935
1818
* Clean up signal handlers and file descriptors before an exec().
3316
*-----------------------------------------------------------------------------
3318
* Hostinfo_GetCOSMemoryInfoInPages --
3320
* Obtain the minimum memory to be maintained, total memory available, and
3321
* free memory available on the COS in pages.
3324
* TRUE on success: '*minSize', '*maxSize' and '*currentSize' are set
3330
*-----------------------------------------------------------------------------
3334
Hostinfo_GetCOSMemoryInfoInPages(unsigned int *minSize, // OUT:
3335
unsigned int *maxSize, // OUT:
3336
unsigned int *currentSize) // OUT:
3338
if (HostType_OSIsPureVMK()) {
3341
return HostinfoGetLinuxMemoryInfoInPages(minSize, maxSize, currentSize);
3348
3198
*-----------------------------------------------------------------------------