arm_dynarmic.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. // SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #ifdef __linux__
  4. #include "common/signal_chain.h"
  5. #include "core/arm/dynarmic/arm_dynarmic.h"
  6. #include "core/hle/kernel/k_process.h"
  7. #include "core/memory.h"
  8. namespace Core {
  9. namespace {
  10. thread_local Core::Memory::Memory* g_current_memory{};
  11. std::once_flag g_registered{};
  12. struct sigaction g_old_segv {};
  13. void HandleSigSegv(int sig, siginfo_t* info, void* ctx) {
  14. if (g_current_memory && g_current_memory->InvalidateSeparateHeap(info->si_addr)) {
  15. return;
  16. }
  17. return g_old_segv.sa_sigaction(sig, info, ctx);
  18. }
  19. } // namespace
  20. ScopedJitExecution::ScopedJitExecution(Kernel::KProcess* process) {
  21. g_current_memory = std::addressof(process->GetMemory());
  22. }
  23. ScopedJitExecution::~ScopedJitExecution() {
  24. g_current_memory = nullptr;
  25. }
  26. void ScopedJitExecution::RegisterHandler() {
  27. std::call_once(g_registered, [] {
  28. struct sigaction sa {};
  29. sa.sa_sigaction = &HandleSigSegv;
  30. sa.sa_flags = SA_SIGINFO | SA_ONSTACK;
  31. Common::SigAction(SIGSEGV, std::addressof(sa), std::addressof(g_old_segv));
  32. });
  33. }
  34. } // namespace Core
  35. #endif