Skip to content

Commit

Permalink
Fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
am11 committed Jun 27, 2024
1 parent 1daa030 commit f0eacc3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static partial class PlatformDetection
public static bool IsNotMonoLinuxArm64 => !IsMonoLinuxArm64;

public static bool IsQemuDetected =>
#if TARGET_WINDOWS
#if TARGET_WINDOWS || TARGET_BROWSER || TARGET_WASI
false;
#else
Interop.Sys.IsQemuDetected();
Expand Down
2 changes: 1 addition & 1 deletion src/native/libs/System.Native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ set(NATIVE_SOURCES
pal_time.c
pal_datetime.c
pal_sysctl.c
"${CLR_SRC_NATIVE_DIR}/minipal/cpufeatures.c"
)

list(APPEND NATIVE_SOURCES
Expand All @@ -48,6 +47,7 @@ if (NOT CLR_CMAKE_TARGET_WASI)
pal_signal.c
pal_threading.c
pal_uid.c
"${CLR_SRC_NATIVE_DIR}/minipal/cpufeatures.c"
)
else()
list (APPEND NATIVE_SOURCES
Expand Down
71 changes: 33 additions & 38 deletions src/native/minipal/cpufeatures.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
#include <sys/auxv.h>
#include <asm/hwcap.h>

#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wunused-macros"
#endif

// Light-up for hardware capabilities that are not present in older headers used by the portable build.
#ifndef HWCAP_ASIMDRDM
#define HWCAP_ASIMDRDM (1 << 12)
Expand All @@ -45,6 +50,10 @@
#define HWCAP_SVE (1 << 22)
#endif

#ifdef __clang__
#pragma clang diagnostic pop
#endif

#endif

#if HAVE_SYSCTLBYNAME
Expand All @@ -56,7 +65,7 @@
#if defined(HOST_UNIX)
#if defined(HOST_X86) || defined(HOST_AMD64)

static uint32_t xmmYmmStateSupport()
static uint32_t xmmYmmStateSupport(void)
{
uint32_t eax;
__asm(" xgetbv\n" \
Expand All @@ -72,7 +81,7 @@ static uint32_t xmmYmmStateSupport()
#define XSTATE_MASK_AVX512 (0xE0) /* 0b1110_0000 */

Check failure on line 81 in src/native/minipal/cpufeatures.c

View check run for this annotation

Azure Pipelines / runtime (Build tvossimulator-x64 Debug AllSubsets_Mono)

src/native/minipal/cpufeatures.c#L81

src/native/minipal/cpufeatures.c(81,9): error GD9BE0D0B: (NETCORE_ENGINEERING_TELEMETRY=Build) macro is not used [-Werror,-Wunused-macros]

Check failure on line 81 in src/native/minipal/cpufeatures.c

View check run for this annotation

Azure Pipelines / runtime (Build tvossimulator-x64 Debug AllSubsets_Mono)

src/native/minipal/cpufeatures.c#L81

src/native/minipal/cpufeatures.c(81,9): error GD9BE0D0B: (NETCORE_ENGINEERING_TELEMETRY=Build) macro is not used [-Werror,-Wunused-macros]

Check failure on line 81 in src/native/minipal/cpufeatures.c

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Release NativeAOT)

src/native/minipal/cpufeatures.c#L81

src/native/minipal/cpufeatures.c(81,9): error G102FB154: (NETCORE_ENGINEERING_TELEMETRY=Build) macro is not used [-Werror,-Wunused-macros]

Check failure on line 81 in src/native/minipal/cpufeatures.c

View check run for this annotation

Azure Pipelines / runtime (Build osx-x64 Release NativeAOT)

src/native/minipal/cpufeatures.c#L81

src/native/minipal/cpufeatures.c(81,9): error G102FB154: (NETCORE_ENGINEERING_TELEMETRY=Build) macro is not used [-Werror,-Wunused-macros]
#endif // XSTATE_MASK_AVX512

static uint32_t avx512StateSupport()
static uint32_t avx512StateSupport(void)
{
#if defined(HOST_APPLE)
// MacOS has specialized behavior where it reports AVX512 support but doesnt
Expand All @@ -99,12 +108,12 @@ static uint32_t avx512StateSupport()
#endif
}

static bool IsAvxEnabled()
static bool IsAvxEnabled(void)
{
return true;
}

static bool IsAvx512Enabled()
static bool IsAvx512Enabled(void)
{
return true;
}
Expand Down Expand Up @@ -301,12 +310,12 @@ int minipal_getcpufeatures(void)
}
}

__cpuid(cpuidInfo, 0x80000000);
__cpuid(cpuidInfo, (int)0x80000000);
uint32_t maxCpuIdEx = (uint32_t)cpuidInfo[CPUID_EAX];

if (maxCpuIdEx >= 0x80000001)
{
__cpuid(cpuidInfo, 0x80000001);
__cpuid(cpuidInfo, (int)0x80000001);

if ((cpuidInfo[CPUID_ECX] & (1 << 5)) != 0) // LZCNT
{
Expand Down Expand Up @@ -441,19 +450,18 @@ int minipal_getcpufeatures(void)
return result;
}

// Detect if the current process is running under the Apple Rosetta x64 emulator
bool minipal_detect_rosetta(void)
static const char* GetCpuBrand(void)
{
#if defined(HOST_AMD64) || defined(HOST_X86)
// Check for CPU brand indicating emulation
int regs[4];
char brand[49];
static char brand[49];

// Get the maximum value for extended function CPUID info
__cpuid(regs, (int)0x80000000);
if ((unsigned int)regs[0] < 0x80000004)
{
return false; // Extended CPUID not supported
return ""; // Extended CPUID not supported, return empty string or handle error
}

// Retrieve the CPU brand string
Expand All @@ -464,44 +472,29 @@ bool minipal_detect_rosetta(void)
}
brand[sizeof(brand) - 1] = '\0';

// Check if CPU brand indicates emulation
if (strstr(brand, "VirtualApple") != NULL)
{
return true;
}
return brand;
#else
return "";
#endif // HOST_AMD64 || HOST_X86

return false;
}

bool minipal_detect_qemu(void)
// Detect if the current process is running under the Apple Rosetta x64 emulator
bool minipal_detect_rosetta(void)
{
#if defined(HOST_AMD64) || defined(HOST_X86)
// Check for CPU brand indicating emulation
unsigned int regs[4];
char brand[49];
// Check if CPU brand indicates emulation
return (strstr(GetCpuBrand(), "VirtualApple") != NULL);
}

// Get the maximum value for extended function CPUID info
__cpuid(0x80000000, regs[0], regs[1], regs[2], regs[3]);
if (regs[0] < 0x80000004)
{
return false; // Extended CPUID not supported
}

// Retrieve the CPU brand string
for (unsigned int i = 0x80000002; i <= 0x80000004; ++i)
{
__cpuid(i, regs[0], regs[1], regs[2], regs[3]);
memcpy(brand + (i - 0x80000002) * sizeof(regs), regs, sizeof(regs));
}
brand[sizeof(brand) - 1] = '\0';
#if !defined(HOST_WINDOWS)

// Detect if the current process is running under QEMU
bool minipal_detect_qemu(void)
{
// Check if CPU brand indicates emulation
if (strstr(brand, "QEMU") != NULL)
if (strstr(GetCpuBrand(), "QEMU") != NULL)
{
return true;
}
#endif

// Check for process name of PID 1 indicating emulation
char cmdline[256];
Expand Down Expand Up @@ -535,3 +528,5 @@ bool minipal_detect_qemu(void)

return false;
}

#endif // !HOST_WINDOWS

0 comments on commit f0eacc3

Please sign in to comment.