Skip to content

fix: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR) crashes #1545

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions test-app/runtime/src/main/cpp/Runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,23 @@ using namespace tns;
bool tns::LogEnabled = true;
SimpleAllocator g_allocator;

void SIGABRT_handler(int sigNumber) {
throw NativeScriptException("JNI Exception occurred (SIGABRT).\n=======\nCheck the 'adb logcat' for additional information about the error.\n=======\n");
void SIG_handler(int sigNumber) {
stringstream msg;
msg << "JNI Exception occurred (";
switch (sigNumber) {
case SIGABRT:
msg << "SIGABRT";
break;
case SIGSEGV:
msg << "SIGSEGV";
break;
default:
// Shouldn't happen, but for completeness
msg << "Signal #" << sigNumber;
break;
}
msg << ").\n=======\nCheck the 'adb logcat' for additional information about the error.\n=======\n";
throw NativeScriptException(msg.str());
}

void Runtime::Init(JavaVM* vm, void* reserved) {
Expand All @@ -56,11 +71,12 @@ void Runtime::Init(JavaVM* vm, void* reserved) {
JEnv::Init(s_jvm);
}

if (m_androidVersion > 25) {
// handle SIGABRT only on API level > 25 as the handling is not so efficient in older versions
// handle SIGABRT/SIGSEGV only on API level > 20 as the handling is not so efficient in older versions
if (m_androidVersion > 20) {
struct sigaction action;
action.sa_handler = SIGABRT_handler;
action.sa_handler = SIG_handler;
sigaction(SIGABRT, &action, NULL);
sigaction(SIGSEGV, &action, NULL);
}
}

Expand Down