Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7505343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:52:50+00:00 2026-05-29T21:52:50+00:00

The code pasted here is an attempt to map a SIGSEGV to a java

  • 0

The code pasted here is an attempt to map a SIGSEGV to a java exception. Before anyone gets too excited, yes, I know, this trangresses various statements in various standards. It’s intended as an entirely temporary tactic to track down a stubborn bug.

On a Mac, at least, it doesn’t work. the C++ throw in the sigaction function calls terminate.

I post this question to ask if anyone knows how to tweak this to work.

#include <stdio.h>
#include <signal.h>
#include "com_github_bimargulies_jnisigsegv_Native.h"

static JavaVM* staticJvm;

JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) {
  staticJvm = jvm;
  return JNI_VERSION_1_6;
}

/* there has to be a catch. */
struct SomethingToThrow {};

void handler_function(int sig, struct __siginfo* si, void *) {
  JNIEnv *env = 0;
  staticJvm->GetEnv((void **)&env, JNI_VERSION_1_6);
  jclass newExcCls = env->FindClass("java/lang/RuntimeException");
  env->ThrowNew(newExcCls, "SIGSEGV");
  fprintf(stderr, "About to throw at the catch ... block\n");
  fflush(stderr);
  throw SomethingToThrow();
 }

JNIEXPORT void JNICALL Java_com_github_bimargulies_jnisigsegv_Native_setupHandler(JNIEnv *, jclass) {

  struct sigaction sa;
  struct sigaction oldsa;
  sa.sa_sigaction = handler_function;
  sa.sa_mask = 0;
  sa.sa_flags = SA_SIGINFO;
  int r = sigaction(SIGSEGV, &sa, &oldsa);
  fprintf(stderr, "Signaction returned %d\n", r);
  fflush(stderr);
}

JNIEXPORT void JNICALL Java_com_github_bimargulies_jnisigsegv_Native_getAnError
(JNIEnv *, jclass, jstring) {
  /* First experiment, just get a sigsegv */
  char * p = 0;
  try {
    *p = 1;
  } catch (...) {
    fprintf(stderr, "Caught something\n");
  }
  return;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:52:51+00:00Added an answer on May 29, 2026 at 9:52 pm

    Take a look at the native bits of JNA, which uses setjmp/longjmp to translate SIGSEGV into a Java exception.

    https://github.com/twall/jna/blob/master/native/protect.h

    Note that when you start adding your own signal handlers, you need to properly chain signals normally handled by the VM (see http://download.oracle.com/javase/6/docs/technotes/guides/vm/signal-chaining.html).

    You should read carefully the man pages for sigaction to review what you should and should not do within a signal handler. There are only a few system calls that are “safe”, and I don’t recall seeing anything about throwing C++ exceptions from the context of the signal handler being a supported operation. It’s quite possible that your C++ exception stack unwind information may not be valid or accessible in the context of the signal handler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use the code posted here: http://seanho.posterous.com/monotouch-first-attempt-arkit-c-version however - when i try
I am going to paste here my code and errors: #include stdio.h #include winsock2.h
I'm utilizing the code posted by Jesper Palm here: Make user control display outside
simonn helped me to code an ordered integer partition function here. He posted two
I have a plot (sample code pasted below) that I am trying to add
Firstly sorry for the long piece of code pasted below. This is my first
I pasted the code given in this link to a file called md5.js. http://www.webtoolkit.info/javascript-md5.html
The code I have pasted below is meant to display images on the middle
For a rich text editor that has to handle pasted HTML code from MS
Pasted a piece of code from the shell script transfer.sh if [[ ${ld} -eq

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.