From 38f562181f3bb24132cbf57b2d59f3c5f8484f8d Mon Sep 17 00:00:00 2001 From: DH Date: Thu, 13 Jul 2023 15:53:05 +0300 Subject: [PATCH] [rpcsx-os] Setup altstack per thread --- rpcsx-os/main.cpp | 16 ---------------- rpcsx-os/thread.cpp | 20 +++++++++++++++++++- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/rpcsx-os/main.cpp b/rpcsx-os/main.cpp index 37d7db9e0..8c74375fb 100644 --- a/rpcsx-os/main.cpp +++ b/rpcsx-os/main.cpp @@ -84,22 +84,6 @@ handle_signal(int sig, siginfo_t *info, void *ucontext) { } static void setupSigHandlers() { - stack_t ss; - - ss.ss_sp = malloc(SIGSTKSZ); - if (ss.ss_sp == NULL) { - perror("malloc"); - exit(EXIT_FAILURE); - } - - ss.ss_size = SIGSTKSZ; - ss.ss_flags = 0; - - if (sigaltstack(&ss, NULL) == -1) { - perror("sigaltstack"); - exit(EXIT_FAILURE); - } - struct sigaction act {}; act.sa_sigaction = handle_signal; act.sa_flags = SA_SIGINFO | SA_ONSTACK; diff --git a/rpcsx-os/thread.cpp b/rpcsx-os/thread.cpp index 70c472444..722c248fa 100644 --- a/rpcsx-os/thread.cpp +++ b/rpcsx-os/thread.cpp @@ -1,4 +1,5 @@ #include "thread.hpp" +#include "backtrace.hpp" #include "orbis/sys/sysentry.hpp" #include #include @@ -7,7 +8,6 @@ #include #include #include -#include #include #include @@ -19,6 +19,8 @@ handleSigSys(int sig, siginfo_t *info, void *ucontext) { _writefsbase_u64(hostFs); } + // rx::printStackTrace(reinterpret_cast(ucontext), + // rx::thread::g_current, 1); auto prevContext = std::exchange(rx::thread::g_current->context, ucontext); orbis::syscall_entry(rx::thread::g_current); rx::thread::g_current->context = prevContext; @@ -41,6 +43,22 @@ void rx::thread::deinitialize() {} void rx::thread::invoke(orbis::Thread *thread) { g_current = thread; + stack_t ss; + + ss.ss_sp = malloc(SIGSTKSZ); + if (ss.ss_sp == NULL) { + perror("malloc"); + exit(EXIT_FAILURE); + } + + ss.ss_size = SIGSTKSZ; + ss.ss_flags = 0; + + if (sigaltstack(&ss, NULL) == -1) { + perror("sigaltstack"); + exit(EXIT_FAILURE); + } + sigset_t unblockSigs{}; sigset_t oldSigmask{}; sigaddset(&unblockSigs, SIGSYS);