summaryrefslogtreecommitdiffstats
path: root/tksao/frame/sigbus.h
blob: 04645b38043a00b4c3e13704e7f4fec0aded4f95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Copyright (C) 1999-2016
// Smithsonian Astrophysical Observatory, Cambridge, MA, USA
// For conditions of distribution and use, see copyright notice in "copyright"

#ifndef __sigbus_h__
#define __sigbus_h__

#ifdef __WIN32
#define INTERP
#define SETSIGBUS
#define CLEARSIGBUS
#else

// Signal Support
#include <setjmp.h>
#include <signal.h>

static sigjmp_buf crashbuf;
static struct sigaction sigact, osigbus, osigsegv;
static void crashHandler(int dummy) {
  siglongjmp(crashbuf, 1);
}
#define INTERP interp
#define SETSIGBUS \
  if (sigsetjmp(crashbuf, 1)) { \
    Tcl_SetVar2(INTERP, "ds9", "msg", "A SIGBUS or SIGSEGV error has been received.", TCL_GLOBAL_ONLY); \
    Tcl_SetVar2(INTERP, "ds9", "msg,level", "error", TCL_GLOBAL_ONLY); \
  } \
  else { \
    sigact.sa_handler = crashHandler; \
    sigemptyset(&sigact.sa_mask); \
    sigact.sa_flags = 0; \
    sigaction(SIGSEGV, &sigact, &osigsegv); \
    sigaction(SIGBUS, &sigact, &osigbus);
  
#define CLEARSIGBUS \
  } \
  sigaction(SIGSEGV, &osigsegv, NULL); \
  sigaction(SIGBUS, &osigbus, NULL);

#endif

#endif