Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions src/mono/mono/utils/mono-codeman.c
Original file line number Diff line number Diff line change
Expand Up @@ -735,12 +735,10 @@ mono_codeman_enable_write (void)
if (codeman_no_exec)
return;
#ifdef HAVE_PTHREAD_JIT_WRITE_PROTECT_NP
if (__builtin_available (macOS 11, *)) {
int level = GPOINTER_TO_INT (mono_native_tls_get_value (write_level_tls_id));
level ++;
mono_native_tls_set_value (write_level_tls_id, GINT_TO_POINTER (level));
pthread_jit_write_protect_np (0);
}
int level = GPOINTER_TO_INT (mono_native_tls_get_value (write_level_tls_id));
level ++;
mono_native_tls_set_value (write_level_tls_id, GINT_TO_POINTER (level));
pthread_jit_write_protect_np (0);
#elif defined(HOST_MACCAT) && defined(__aarch64__)
/* JITing in Catalyst apps is not allowed on Apple Silicon, so assume if we're here we don't really have executable pages. */
#endif
Expand All @@ -758,14 +756,12 @@ mono_codeman_disable_write (void)
if (codeman_no_exec)
return;
#ifdef HAVE_PTHREAD_JIT_WRITE_PROTECT_NP
if (__builtin_available (macOS 11, *)) {
int level = GPOINTER_TO_INT (mono_native_tls_get_value (write_level_tls_id));
g_assert (level);
level --;
mono_native_tls_set_value (write_level_tls_id, GINT_TO_POINTER (level));
if (level == 0)
pthread_jit_write_protect_np (1);
}
int level = GPOINTER_TO_INT (mono_native_tls_get_value (write_level_tls_id));
g_assert (level);
level --;
mono_native_tls_set_value (write_level_tls_id, GINT_TO_POINTER (level));
if (level == 0)
pthread_jit_write_protect_np (1);
#elif defined(HOST_MACCAT) && defined(__aarch64__)
/* JITing in Catalyst apps is not allowed on Apple Silicon, so assume if we're here we don't really have executable pages */
#endif
Expand Down
4 changes: 1 addition & 3 deletions src/mono/mono/utils/mono-mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -285,9 +285,7 @@ mono_valloc (void *addr, size_t length, int flags, MonoMemAccountType type)
mflags |= MAP_JIT;
#if defined(HOST_ARM64) && !defined(HOST_MACCAT)
/* Patching code on apple silicon seems to cause random crashes without this flag */
/* No __builtin_available in old versions of Xcode that could be building Mono on x86 or amd64 */
if (__builtin_available (macOS 11, *))
mflags |= MAP_JIT;
mflags |= MAP_JIT;
#endif
}
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ int32_t AppleCryptoNative_EccGenerateKey(int32_t keySizeBits,
{
CFDictionaryAddValue(attributes, kSecAttrKeyType, kSecAttrKeyTypeEC);
CFDictionaryAddValue(attributes, kSecAttrKeySizeInBits, cfKeySizeValue);
if (__builtin_available(macOS 10.15, iOS 13, tvOS 13, *))
{
CFDictionaryAddValue(attributes, kSecUseDataProtectionKeychain, kCFBooleanTrue);
}
CFDictionaryAddValue(attributes, kSecUseDataProtectionKeychain, kCFBooleanTrue);

*pPrivateKey = SecKeyCreateRandomKey(attributes, pErrorOut);
if (*pPrivateKey != NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ int32_t AppleCryptoNative_RsaGenerateKey(int32_t keySizeBits,
{
CFDictionaryAddValue(attributes, kSecAttrKeyType, kSecAttrKeyTypeRSA);
CFDictionaryAddValue(attributes, kSecAttrKeySizeInBits, cfKeySizeValue);
if (__builtin_available(macOS 10.15, iOS 13, tvOS 13, *))
{
CFDictionaryAddValue(attributes, kSecUseDataProtectionKeychain, kCFBooleanTrue);
}
CFDictionaryAddValue(attributes, kSecUseDataProtectionKeychain, kCFBooleanTrue);

*pPrivateKey = SecKeyCreateRandomKey(attributes, pErrorOut);
if (*pPrivateKey != NULL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,5 @@

CFStringRef AppleCryptoNative_SecCopyErrorMessageString(OSStatus osStatus)
{
if (__builtin_available(iOS 11.3, tvOS 11.3, *))
{
return SecCopyErrorMessageString(osStatus, NULL);
}

return CFStringCreateWithFormat(NULL, NULL, CFSTR("OSStatus %d"), (int)osStatus);
return SecCopyErrorMessageString(osStatus, NULL);
}
24 changes: 3 additions & 21 deletions src/native/minipal/memorybarrierprocesswide.c
Original file line number Diff line number Diff line change
Expand Up @@ -166,27 +166,9 @@ void minipal_memory_barrier_process_wide(void)
// Iterate through each of the threads in the list.
for (mach_msg_type_number_t i = 0; i < cThreads; i++)
{
if (__builtin_available (macOS 10.14, iOS 12, tvOS 9, *))
{
// Request the threads pointer values to force the thread to emit a memory barrier
size_t registers = 128;
machret = thread_get_register_pointer_values(pThreads[i], &sp, &registers, registerValues);
}
else
{
// fallback implementation for older OS versions
#if defined(HOST_AMD64)
x86_thread_state64_t threadState;
mach_msg_type_number_t count = x86_THREAD_STATE64_COUNT;
machret = thread_get_state(pThreads[i], x86_THREAD_STATE64, (thread_state_t)&threadState, &count);
#elif defined(HOST_ARM64)
arm_thread_state64_t threadState;
mach_msg_type_number_t count = ARM_THREAD_STATE64_COUNT;
machret = thread_get_state(pThreads[i], ARM_THREAD_STATE64, (thread_state_t)&threadState, &count);
#else
#error Unexpected architecture
#endif
}
// Request the threads pointer values to force the thread to emit a memory barrier
size_t registers = 128;
machret = thread_get_register_pointer_values(pThreads[i], &sp, &registers, registerValues);

if (machret == KERN_INSUFFICIENT_BUFFER_SIZE)
{
Expand Down
Loading