26 #include "src/trap-handler/handler-inside-posix.h" 33 #include <sys/ucontext.h> 39 #include "src/trap-handler/trap-handler-internal.h" 40 #include "src/trap-handler/trap-handler.h" 44 namespace trap_handler {
46 bool IsKernelGeneratedSignal(siginfo_t* info) {
50 return info->si_code > 0 && info->si_code != SI_USER &&
51 info->si_code != SI_QUEUE && info->si_code != SI_TIMER &&
52 info->si_code != SI_ASYNCIO && info->si_code != SI_MESGQ;
60 pthread_sigmask(SIG_UNBLOCK, &sigs, &old_mask_);
63 ~
SigUnmaskStack() { pthread_sigmask(SIG_SETMASK, &old_mask_,
nullptr); }
74 bool TryHandleSignal(
int signum, siginfo_t* info,
void* context) {
77 if (signum != kOobSignal) {
82 if (!IsKernelGeneratedSignal(info)) {
87 if (!IsThreadInWasm()) {
92 g_thread_in_wasm_code =
false;
104 sigaddset(&sigs, SIGSEGV);
105 SigUnmaskStack unmask(sigs);
107 ucontext_t* uc =
reinterpret_cast<ucontext_t*
>(context);
109 auto* context_rip = &uc->uc_mcontext.gregs[REG_RIP];
111 auto* context_rip = &uc->uc_mcontext->__ss.__rip;
113 #error Unsupported platform 117 if (TryFindLandingPad(fault_addr, &landing_pad)) {
119 *context_rip = landing_pad;
121 g_thread_in_wasm_code =
true;
132 void HandleSignal(
int signum, siginfo_t* info,
void* context) {
133 if (!TryHandleSignal(signum, info, context)) {
143 if (!IsKernelGeneratedSignal(info)) {