[dynarmic, MacroHLE] Fix crashes on W^X systems (#4090)
Some checks are pending
tx-src / sources (push) Waiting to run
Check Strings / check-strings (push) Waiting to run

should fix crashes on:
- NetBSD
- SELinux
- OpenBSD
- other W^X systems
- some person trying to be funny with W^X on their system even if they dont have to

perf impact should be minimal

Signed-off-by: lizzie <lizzie@eden-emu.dev>

Reviewed-on: https://git.eden-emu.dev/eden-emu/eden/pulls/4090
Reviewed-by: MaranBr <maranbr@eden-emu.dev>
Reviewed-by: Maufeat <sahyno1996@gmail.com>
This commit is contained in:
lizzie 2026-06-15 22:06:14 +02:00 committed by crueter
parent b05463ee19
commit c8c61a12c3
No known key found for this signature in database
GPG key ID: 425ACD2D4830EBC6
2 changed files with 6 additions and 0 deletions

View file

@ -90,6 +90,8 @@ std::once_flag flag;
std::optional<SpinLockImpl> impl;
void SpinLockImpl::Initialize() noexcept {
// Needed for W^X systems (i.e SElinux, OpenBSD)
code.setProtectMode(Xbyak::CodeArray::ProtectMode::PROTECT_RW);
Xbyak::Reg64 const ABI_PARAM1 = Backend::X64::HostLocToReg64(Backend::X64::ABI_PARAM1);
code.align();
lock = code.getCurr<void (*)(volatile int*)>();
@ -99,6 +101,7 @@ void SpinLockImpl::Initialize() noexcept {
unlock = code.getCurr<void (*)(volatile int*)>();
EmitSpinLockUnlock(code, ABI_PARAM1, code.eax);
code.ret();
code.setProtectMode(Xbyak::CodeArray::ProtectMode::PROTECT_RE);
}
void SpinLockImpl::GlobalInitialize() noexcept {

View file

@ -1117,6 +1117,8 @@ void MacroJITx64Impl::Optimizer_ScanFlags() {
}
void MacroJITx64Impl::Compile() {
// Matching PROTECT_RE needed for W^X systems
setProtectMode(Xbyak::CodeArray::ProtectMode::PROTECT_RW);
labels.fill(Xbyak::Label());
Common::X64::ABI_PushRegistersAndAdjustStack(*this, Common::X64::ABI_ALL_CALLEE_SAVED, 8);
@ -1164,6 +1166,7 @@ void MacroJITx64Impl::Compile() {
Common::X64::ABI_PopRegistersAndAdjustStack(*this, Common::X64::ABI_ALL_CALLEE_SAVED, 8);
ret();
ready();
setProtectMode(Xbyak::CodeArray::ProtectMode::PROTECT_RE);
program = getCode<ProgramType>();
}