Skip to content
This repository was archived by the owner on Sep 29, 2025. It is now read-only.

Commit 4b0fce2

Browse files
authored
Merge pull request #1713 from reicast/skmp/sigaction-workaround
Android: Try to use sigaction from libc.so. libart is buggy sometimes.
2 parents 35bb796 + ba19394 commit 4b0fce2

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

libswirl/linux/common.cpp

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#include <sys/param.h>
2222
#include <sys/mman.h>
2323
#include <sys/time.h>
24-
#if !defined(TARGET_BSD) && !defined(_ANDROID) && !defined(TARGET_IPHONE) && !defined(TARGET_NACL32) && !defined(TARGET_EMSCRIPTEN) && !defined(TARGET_OSX) && !defined(TARGET_OSX_X64)
24+
#if !defined(TARGET_BSD) && !defined(TARGET_IPHONE) && !defined(TARGET_NACL32) && !defined(TARGET_EMSCRIPTEN) && !defined(TARGET_OSX) && !defined(TARGET_OSX_X64)
2525
#include <sys/personality.h>
2626
#include <dlfcn.h>
2727
#endif
@@ -188,6 +188,31 @@ static void fault_handler (int sn, siginfo_t * si, void *segfault_ctx)
188188
fault_printf("fault_handler exit\n");
189189
}
190190

191+
typedef int sigaction_fn(int signum, const struct sigaction *act,
192+
struct sigaction *oldact);
193+
194+
static sigaction_fn* get_sigaction()
195+
{
196+
197+
void* libc;
198+
sigaction_fn* rv = nullptr;
199+
200+
libc = dlopen("libc.so", RTLD_NOLOAD);
201+
202+
if (libc)
203+
{
204+
printf("get_sigaction: found libc.so\n");
205+
*(void**) (&rv) = dlsym(libc, "sigaction");
206+
207+
if (rv && rv != sigaction) {
208+
printf("get_sigaction: libc override detected, working around...\n");
209+
return rv;
210+
}
211+
}
212+
213+
return &sigaction;
214+
}
215+
191216
static void install_fault_handler(void)
192217
{
193218
// initialize trap state
@@ -202,13 +227,16 @@ static void install_fault_handler(void)
202227
act.sa_sigaction = fault_handler;
203228
sigemptyset(&act.sa_mask);
204229
act.sa_flags = SA_SIGINFO;
205-
sigaction(SIGSEGV, &act, &segv_oact);
230+
231+
auto libc_sigaction = get_sigaction();
232+
233+
libc_sigaction(SIGSEGV, &act, &segv_oact);
206234
#if HOST_OS == OS_DARWIN
207235
//this is broken on osx/ios/mach in general
208-
sigaction(SIGBUS, &act, &segv_oact);
236+
libc_sigaction(SIGBUS, &act, &segv_oact);
209237

210238
act.sa_sigaction = sigill_handler;
211-
sigaction(SIGILL, &act, &segv_oact);
239+
libc_sigaction(SIGILL, &act, &segv_oact);
212240
#endif
213241
}
214242
#else // !defined(TARGET_NO_EXCEPTIONS)

0 commit comments

Comments
 (0)