Skip to content

Commit

Permalink
Check only for Rosetta
Browse files Browse the repository at this point in the history
  • Loading branch information
janvorli committed May 23, 2024
1 parent c737b9a commit 7c734b0
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 33 deletions.
10 changes: 7 additions & 3 deletions src/coreclr/minipal/Unix/doublemapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
#include "minipal.h"
#include "minipal/cpufeatures.h"

#ifndef TARGET_OSX
#ifdef TARGET_OSX

#include <mach/mach.h>

#else // TARGET_OSX

#ifdef TARGET_64BIT
static const off_t MaxDoubleMappedSize = 2048ULL*1024*1024*1024;
Expand All @@ -34,9 +38,9 @@ static const off_t MaxDoubleMappedSize = UINT_MAX;

bool VMToOSInterface::CreateDoubleMemoryMapper(void** pHandle, size_t *pMaxExecutableCodeSize)
{
if (minipal_detect_emulation())
if (minipal_detect_rosetta())
{
// Rosetta or QEMU doesn't support double mapping correctly
// Rosetta doesn't support double mapping correctly
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/minipal/Windows/doublemapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ inline void *GetBotMemoryAddress(void)

bool VMToOSInterface::CreateDoubleMemoryMapper(void **pHandle, size_t *pMaxExecutableCodeSize)
{
if (minipal_detect_emulation())
if (minipal_detect_rosetta())
{
// Rosetta or QEMU doesn't support double mapping correctly
// Rosetta doesn't support double mapping correctly
return false;
}

Expand Down
11 changes: 0 additions & 11 deletions src/coreclr/vm/amd64/asmhelpers.S
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,3 @@ LEAF_ENTRY GetTlsIndexObjectDescOffset, _TEXT
int 3
LEAF_END GetTlsIndexObjectDescOffset, _TEXT
#endif

# These functions are used to verify that double mapping used to implement W^X works.
LEAF_ENTRY VerifyDoubleMapping1, _TEXT
mov rax, 1
ret
LEAF_END_MARKED VerifyDoubleMapping1, _TEXT

LEAF_ENTRY VerifyDoubleMapping2, _TEXT
mov rax, 2
ret
LEAF_END_MARKED VerifyDoubleMapping2, _TEXT
19 changes: 3 additions & 16 deletions src/native/minipal/cpufeatures.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,8 @@ int minipal_getcpufeatures(void)
return result;
}

bool minipal_detect_emulation(void)
// Detect if the current process is running under the Apple Rosetta x64 emulator
bool minipal_detect_rosetta(void)
{
#ifdef HOST_AMD64
// Check for CPU brand indicating emulation
Expand All @@ -499,25 +500,11 @@ bool minipal_detect_emulation(void)
brand[sizeof(brand) - 1] = '\0';

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

// Check for process name of PID 1 indicating emulation
char cmdline[256];
FILE *cmdline_file = fopen("/proc/1/cmdline", "r");
if (cmdline_file != NULL)
{
fgets(cmdline, sizeof(cmdline), cmdline_file);
fclose(cmdline_file);

if (strstr(cmdline, "qemu") != NULL || strstr(cmdline, "rosetta") != NULL)
{
return true;
}
}

return false;
}
2 changes: 1 addition & 1 deletion src/native/minipal/cpufeatures.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ extern "C"
#endif // __cplusplus

int minipal_getcpufeatures(void);
bool minipal_detect_emulation(void);
bool minipal_detect_rosetta(void);

#ifdef __cplusplus
}
Expand Down

0 comments on commit 7c734b0

Please sign in to comment.