-
Notifications
You must be signed in to change notification settings - Fork 726
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CPU/CodeCache: Fix crash on Apple Silicon
- Loading branch information
Showing
5 changed files
with
72 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
// SPDX-FileCopyrightText: 2019-2022 Connor McLaughlin <[email protected]> | ||
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <[email protected]> | ||
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0) | ||
|
||
#include "jit_code_buffer.h" | ||
|
||
#include "common/align.h" | ||
#include "common/assert.h" | ||
#include "common/log.h" | ||
#include "common/memmap.h" | ||
|
||
#include <algorithm> | ||
|
||
Log_SetChannel(JitCodeBuffer); | ||
|
||
#if defined(_WIN32) | ||
|
@@ -15,11 +19,6 @@ Log_SetChannel(JitCodeBuffer); | |
#include <sys/mman.h> | ||
#endif | ||
|
||
#if defined(__APPLE__) && defined(__aarch64__) | ||
// pthread_jit_write_protect_np() | ||
#include <pthread.h> | ||
#endif | ||
|
||
JitCodeBuffer::JitCodeBuffer() = default; | ||
|
||
JitCodeBuffer::JitCodeBuffer(u32 size, u32 far_code_size) | ||
|
@@ -235,7 +234,7 @@ void JitCodeBuffer::CommitFarCode(u32 length) | |
|
||
void JitCodeBuffer::Reset() | ||
{ | ||
WriteProtect(false); | ||
MemMap::BeginCodeWrite(); | ||
|
||
m_free_code_ptr = m_code_ptr + m_guard_size + m_code_reserve_size; | ||
m_code_used = 0; | ||
|
@@ -250,7 +249,7 @@ void JitCodeBuffer::Reset() | |
FlushInstructionCache(m_free_far_code_ptr, m_far_code_size); | ||
} | ||
|
||
WriteProtect(true); | ||
MemMap::EndCodeWrite(); | ||
} | ||
|
||
void JitCodeBuffer::Align(u32 alignment, u8 padding_value) | ||
|
@@ -275,26 +274,3 @@ void JitCodeBuffer::FlushInstructionCache(void* address, u32 size) | |
#error Unknown platform. | ||
#endif | ||
} | ||
|
||
#if defined(__APPLE__) && defined(__aarch64__) | ||
|
||
void JitCodeBuffer::WriteProtect(bool enabled) | ||
{ | ||
static bool initialized = false; | ||
static bool needs_write_protect = false; | ||
|
||
if (!initialized) | ||
{ | ||
initialized = true; | ||
needs_write_protect = (pthread_jit_write_protect_supported_np() != 0); | ||
if (needs_write_protect) | ||
Log_InfoPrint("pthread_jit_write_protect_np() will be used before writing to JIT space."); | ||
} | ||
|
||
if (!needs_write_protect) | ||
return; | ||
|
||
pthread_jit_write_protect_np(enabled ? 1 : 0); | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters