[racket] FFI crashing Racket

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Sun Oct 19 09:23:19 EDT 2014

It appears that calling clang_createIndex() sets the handler for
SIGSEGV, which interferes with Racket's own SIGSEGV handler to
implement the GC's write barrier.

The program below illustrates. It sets the handler before and after a
call to clang_createIndex() and shows that the handler has been changed
after the call. If you comment out the clang_createIndex() call, then
the handler is unchanged.

I have no idea why clang_createIndex() would set the SIGSEGV handler or
whether that can be disabled.

----------------------------------------

#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>

typedef void *CXIndex;
extern CXIndex clang_createIndex(int, int);

void fault_handler() 
{
  printf("fault\n");
}

void check()
{
  struct sigaction act, oact;
  memset(&act, 0, sizeof(act));
  act.sa_sigaction = fault_handler;
  sigemptyset(&act.sa_mask);
  sigaction(SIGSEGV, &act, &oact);

  printf("%p %d\n", oact.sa_sigaction, oact.sa_sigaction == fault_handler);
}

int main() {
  void *dl;

  check();

  clang_createIndex(0, 0);

  check();

  return 0;
}


Posted on the users mailing list.