user377158
user377158

Reputation: 79

Android : Catch SIGSEGV signal JNI

I am using tesseract project to convert image to string. However, SIGSEGV signal is sent (randomly ?) from he JNI.

I wanted to restart my app when the signal is sent, but I didn't find any solution to "catch" the signal with Java.

Anyone have suggestions ?

Thanks

Upvotes: 1

Views: 2472

Answers (2)

Aerodigital
Aerodigital

Reputation: 21

Since no one is helping. I would like to point out the fact that questioning the intention or goal is disrespectful. We want facts, not opinions or speculation. That seems to be a habit here. In my case I want to catch SIGSERV because I want to detect a vulnerability in a shared library. For security reasons, there is no other sure way to detect said vulnerability without welcome false-positives. Here is something I found a couple of days ago:

> #include <stdio.h>
> #include <stdlib.h>
> #include <dlfcn.h>
> 
> 
> int main(int argc, char **argv) {
>     void *handle;
>     void* (*doSomething)(char);
>     char *error;
>     handle = dlopen ("libexample.so", RTLD_LAZY);
>     if (!handle) {
>         fprintf (stderr, "%s\n", dlerror());
>         exit(1);
>     }
>     dlerror();    /* Clear any existing error */
>     foo = dlsym(handle, "doSomething");
>     if ((error = dlerror()) != NULL)  {
>         fprintf (stderr, "%s\n", error);
>         exit(1);
>     }
>     printf ("%f\n", (*setDataSource)("/data/data/com.example.ap/files/cve_2015_2396.mp4"));
>     dlclose(handle);
>     return 0;

Upvotes: 0

Chris Stratton
Chris Stratton

Reputation: 40397

While you can catch SIGSEGV with a native signal handler, you may not find it very easy to do anything useful in terms of android api interaction from within the handler.

Probably the best thing to do is to understand and fix the problem.

In terms of workaround - and that's really a very inferior solution - you could presumably either use AlarmManager to set an event a few second in the future, and cancel it/push it further out if you turn out to still be running after the "risky" operation. Or you could launch a service (not running in the same process) which would restart your application if the service connection is lost.

Upvotes: 1

Related Questions