SignalCatcher() { // THIS IS A BIG HACK // We intercept SIGABRT signal here, which may be intercepted somewhere // else already. We shouldn't do this in a generic system, but for now // I think we don't intercept it anywhere else anyway. // // Note: Current Android use SIGSEGV instead of SIGABRT. // See bionic/libc/unistd/abort.c LOGE("SignalCatcher::SignalCatcher constructed"); struct sigaction sig_handler; memset(&sig_handler, 0, sizeof(struct sigaction)); sig_handler.sa_sigaction = android_signal_handler; sig_handler.sa_flags = SA_RESETHAND; #define CATCHSIG(X) sigaction(X, &sig_handler, &old_signalhandlers[X]) CATCHSIG(SIGILL); CATCHSIG(SIGABRT); CATCHSIG(SIGBUS); CATCHSIG(SIGFPE); CATCHSIG(SIGSEGV); CATCHSIG(SIGSTKFLT); CATCHSIG(SIGPIPE); CATCHSIG(SIGTERM); CATCHSIG(SIGQUIT); CATCHSIG(SIGKILL); #undef CATCHSIG }
void crSetSignalHandler() { #ifdef _LINUX if (signals_are_set) return; signals_are_set = true; struct sigaction handler; // = {0}; //size_t s = sizeof(handler); //void * p = &handler; //memset(p, 0, s); memset(&handler, 0, sizeof(handler)); handler.sa_sigaction = cr_sigaction; handler.sa_flags = SA_RESETHAND; #define CATCHSIG(X) sigaction(X, &handler, &old_sa[X]) CATCHSIG(SIGILL); CATCHSIG(SIGABRT); CATCHSIG(SIGBUS); CATCHSIG(SIGFPE); CATCHSIG(SIGSEGV); // CATCHSIG(SIGSTKFLT); CATCHSIG(SIGPIPE); #endif }
JNIEXPORT void JNICALL Java_com_wheelphone_targetNavigation_WheelphoneTargetNavigation_initApplicationNative( JNIEnv* env, jobject obj, jint width, jint height) { LOG("Java_com_qualcomm_QCARSamples_FrameMarkers_FrameMarkers_initApplicationNative"); g_sigEnv = env; jclass javaClass = env->GetObjectClass(obj); // "obj" is the java class object calling the "initApplicationNative" method, that is an WheelphoneTargetNavigation instance. g_sigNativeCrashed = env->GetMethodID(javaClass, "onNativeCrashed", "()V"); g_sigObj = env->NewGlobalRef(obj); struct sigaction handler; memset(&handler, 0, sizeof(struct sigaction)); handler.sa_sigaction = android_sigaction; handler.sa_flags = SA_RESETHAND; #define CATCHSIG(X) sigaction(X, &handler, &old_sa[X]) CATCHSIG(SIGILL); CATCHSIG(SIGABRT); CATCHSIG(SIGBUS); CATCHSIG(SIGFPE); CATCHSIG(SIGSEGV); CATCHSIG(SIGSTKFLT); CATCHSIG(SIGPIPE); // Store screen dimensions screenWidth = width; screenHeight = height; // Handle to the activity class: jclass activityClass = env->GetObjectClass(obj); jmethodID getTextureCountMethodID = env->GetMethodID(activityClass, "getTextureCount", "()I"); if (getTextureCountMethodID == 0) { LOG("Function getTextureCount() not found."); return; } textureCount = env->CallIntMethod(obj, getTextureCountMethodID); if (!textureCount) { LOG("getTextureCount() returned zero."); return; } textures = new Texture*[textureCount]; jmethodID getTextureMethodID = env->GetMethodID(activityClass, "getTexture", "(I)Lcom/wheelphone/targetNavigation/Texture;"); if (getTextureMethodID == 0) { LOG("Function getTexture() not found."); return; } // Register the textures for (int i = 0; i < textureCount; ++i) { jobject textureObject = env->CallObjectMethod(obj, getTextureMethodID, i); if (textureObject == NULL) { LOG("GetTexture() returned zero pointer"); return; } textures[i] = Texture::create(env, textureObject); } }