diff --git a/src/backend/x64/exception_handler_posix.cpp b/src/backend/x64/exception_handler_posix.cpp index e1a3b190..86b89f59 100644 --- a/src/backend/x64/exception_handler_posix.cpp +++ b/src/backend/x64/exception_handler_posix.cpp @@ -35,6 +35,7 @@ struct CodeBlockInfo { class SigHandler { public: SigHandler(); + ~SigHandler(); void AddCodeBlock(CodeBlockInfo info); void RemoveCodeBlock(u64 rip); @@ -48,6 +49,8 @@ private: bool supports_fast_mem = true; + void* signal_stack_memory = nullptr; + std::vector code_block_infos; std::mutex code_block_infos_mutex; @@ -62,8 +65,10 @@ SigHandler sig_handler; SigHandler::SigHandler() { constexpr size_t signal_stack_size = std::max(SIGSTKSZ, 2 * 1024 * 1024); + signal_stack_memory = std::malloc(signal_stack_size); + stack_t signal_stack; - signal_stack.ss_sp = std::malloc(signal_stack_size); + signal_stack.ss_sp = signal_stack_memory; signal_stack.ss_size = signal_stack_size; signal_stack.ss_flags = 0; if (sigaltstack(&signal_stack, nullptr) != 0) { @@ -91,6 +96,10 @@ SigHandler::SigHandler() { #endif } +SigHandler::~SigHandler() { + std::free(signal_stack_memory); +} + void SigHandler::AddCodeBlock(CodeBlockInfo cbi) { std::lock_guard guard(code_block_infos_mutex); if (auto iter = FindCodeBlockInfo(cbi.code_begin); iter != code_block_infos.end()) {