From dfd567e4b536fdb43c96586afb72d8999769df74 Mon Sep 17 00:00:00 2001 From: Maurus Cuelenaere Date: Sun, 30 Jan 2011 19:31:28 +0100 Subject: [PATCH 10/10] Android: signal handlers (WIP) --- firmware/target/hosted/android/system-android.c | 26 +++++++++++++++++++++++ 1 files changed, 26 insertions(+), 0 deletions(-) diff --git a/firmware/target/hosted/android/system-android.c b/firmware/target/hosted/android/system-android.c index fa24d25..938f9bf 100644 --- a/firmware/target/hosted/android/system-android.c +++ b/firmware/target/hosted/android/system-android.c @@ -23,6 +23,8 @@ #include #include "config.h" #include "system.h" +#include +#include @@ -70,6 +72,28 @@ void power_off(void) wakeup_signal(&shutdown_completed); } +static void signal_handler(int signal, siginfo_t *info, void *context) +{ + char buf[256]; + + snprintf(buf, sizeof(buf), "%s occurred, errno: %s (%d), at %p [%p]", + sys_siglist[signal], strerror(info->si_errno), info->si_errno, + info->si_addr, context); + (*env_ptr)->FatalError(env_ptr, buf); +} + +static void setup_sighandlers(void) +{ + struct sigaction action; + action.sa_sigaction = &signal_handler; + sigemptyset(&action.sa_mask); + action.sa_flags = SA_SIGINFO | SA_RESETHAND; + + sigaction(SIGSEGV, &action, NULL); + sigaction(SIGBUS, &action, NULL); + sigaction(SIGILL, &action, NULL); +} + /* this is the entry point of the android app initially called by jni */ JNIEXPORT void JNICALL Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this) @@ -81,6 +105,7 @@ Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this) (void)env; (void)this; + volatile uintptr_t stack = 0; stackbegin = stackend = (uintptr_t*) &stack; env_ptr = env; @@ -88,6 +113,7 @@ Java_org_rockbox_RockboxService_main(JNIEnv *env, jobject this) RockboxService_class = (*env)->GetObjectClass(env, this); wakeup_init(&shutdown_completed); + setup_sighandlers(); main(); } -- 1.7.1