| [9d944b2] | 1 | //
|
|---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2016 University of Waterloo
|
|---|
| 3 | //
|
|---|
| 4 | // The contents of this file are covered under the licence agreement in the
|
|---|
| 5 | // file "LICENCE" distributed with Cforall.
|
|---|
| 6 | //
|
|---|
| 7 | // interpose.c --
|
|---|
| 8 | //
|
|---|
| 9 | // Author : Thierry Delisle
|
|---|
| 10 | // Created On : Wed Mar 29 16:10:31 2017
|
|---|
| [6b0b624] | 11 | // Last Modified By : Peter A. Buhr
|
|---|
| [6791213] | 12 | // Last Modified On : Fri Mar 13 17:35:37 2020
|
|---|
| 13 | // Update Count : 178
|
|---|
| [9d944b2] | 14 | //
|
|---|
| 15 |
|
|---|
| [7867eb9] | 16 | #include <stdarg.h> // va_start, va_end
|
|---|
| [851fd92] | 17 | #include <stdio.h>
|
|---|
| [7867eb9] | 18 | #include <string.h> // strlen
|
|---|
| 19 | #include <unistd.h> // _exit, getpid
|
|---|
| [dbe9b08] | 20 | #define __USE_GNU
|
|---|
| [58b6d1b] | 21 | #include <signal.h>
|
|---|
| [dbe9b08] | 22 | #undef __USE_GNU
|
|---|
| [67db067] | 23 | extern "C" {
|
|---|
| [7867eb9] | 24 | #include <dlfcn.h> // dlopen, dlsym
|
|---|
| 25 | #include <execinfo.h> // backtrace, messages
|
|---|
| [9d944b2] | 26 | }
|
|---|
| 27 |
|
|---|
| [73abe95] | 28 | #include "bits/debug.hfa"
|
|---|
| 29 | #include "bits/defs.hfa"
|
|---|
| 30 | #include "bits/signal.hfa" // sigHandler_?
|
|---|
| 31 | #include "startup.hfa" // STARTUP_PRIORITY_CORE
|
|---|
| [1d94116] | 32 | #include <assert.h>
|
|---|
| [9d944b2] | 33 |
|
|---|
| [3d5f2ef1] | 34 | //=============================================================================================
|
|---|
| 35 | // Interposing helpers
|
|---|
| 36 | //=============================================================================================
|
|---|
| 37 |
|
|---|
| [032234bd] | 38 | static void preload_libgcc(void) {
|
|---|
| [ad64520] | 39 | dlopen( "libgcc_s.so.1", RTLD_NOW );
|
|---|
| 40 | if ( const char * error = dlerror() ) abort( "interpose_symbol : internal error pre-loading libgcc, %s\n", error );
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| [67db067] | 43 | typedef void (* generic_fptr_t)(void);
|
|---|
| [95dab9e] | 44 | static generic_fptr_t do_interpose_symbol( void * library, const char symbol[], const char version[] ) {
|
|---|
| 45 | const char * error;
|
|---|
| 46 |
|
|---|
| 47 | union { generic_fptr_t fptr; void * ptr; } originalFunc;
|
|---|
| 48 |
|
|---|
| 49 | #if defined( _GNU_SOURCE )
|
|---|
| 50 | if ( version ) {
|
|---|
| 51 | originalFunc.ptr = dlvsym( library, symbol, version );
|
|---|
| 52 | } else {
|
|---|
| 53 | originalFunc.ptr = dlsym( library, symbol );
|
|---|
| 54 | }
|
|---|
| 55 | #else
|
|---|
| 56 | originalFunc.ptr = dlsym( library, symbol );
|
|---|
| 57 | #endif // _GNU_SOURCE
|
|---|
| 58 |
|
|---|
| 59 | error = dlerror();
|
|---|
| 60 | if ( error ) abort( "interpose_symbol : internal error, %s\n", error );
|
|---|
| 61 |
|
|---|
| 62 | return originalFunc.fptr;
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| [032234bd] | 65 | static generic_fptr_t interpose_symbol( const char symbol[], const char version[] ) {
|
|---|
| [9d944b2] | 66 | const char * error;
|
|---|
| 67 |
|
|---|
| 68 | static void * library;
|
|---|
| [a7d696f] | 69 | static void * pthread_library;
|
|---|
| [9d944b2] | 70 | if ( ! library ) {
|
|---|
| 71 | #if defined( RTLD_NEXT )
|
|---|
| 72 | library = RTLD_NEXT;
|
|---|
| 73 | #else
|
|---|
| 74 | // missing RTLD_NEXT => must hard-code library name, assuming libstdc++
|
|---|
| 75 | library = dlopen( "libc.so.6", RTLD_LAZY );
|
|---|
| 76 | error = dlerror();
|
|---|
| 77 | if ( error ) {
|
|---|
| [169d944] | 78 | abort( "interpose_symbol : failed to open libc, %s\n", error );
|
|---|
| [9d944b2] | 79 | }
|
|---|
| 80 | #endif
|
|---|
| 81 | } // if
|
|---|
| [a7d696f] | 82 | if ( ! pthread_library ) {
|
|---|
| 83 | #if defined( RTLD_NEXT )
|
|---|
| 84 | pthread_library = RTLD_NEXT;
|
|---|
| 85 | #else
|
|---|
| 86 | // missing RTLD_NEXT => must hard-code library name, assuming libstdc++
|
|---|
| 87 | pthread_library = dlopen( "libpthread.so", RTLD_LAZY );
|
|---|
| 88 | error = dlerror();
|
|---|
| 89 | if ( error ) {
|
|---|
| 90 | abort( "interpose_symbol : failed to open libpthread, %s\n", error );
|
|---|
| 91 | }
|
|---|
| 92 | #endif
|
|---|
| 93 | } // if
|
|---|
| [9d944b2] | 94 |
|
|---|
| [95dab9e] | 95 | return do_interpose_symbol(library, symbol, version);
|
|---|
| [9d944b2] | 96 | }
|
|---|
| 97 |
|
|---|
| [67db067] | 98 | #define INTERPOSE_LIBC( x, ver ) __cabi_libc.x = (typeof(__cabi_libc.x))interpose_symbol( #x, ver )
|
|---|
| [3d5f2ef1] | 99 |
|
|---|
| 100 | //=============================================================================================
|
|---|
| [67db067] | 101 | // Interposition Startup logic
|
|---|
| [3d5f2ef1] | 102 | //=============================================================================================
|
|---|
| [9d944b2] | 103 |
|
|---|
| [032234bd] | 104 | static void sigHandler_segv( __CFA_SIGPARMS__ );
|
|---|
| 105 | static void sigHandler_ill ( __CFA_SIGPARMS__ );
|
|---|
| 106 | static void sigHandler_fpe ( __CFA_SIGPARMS__ );
|
|---|
| 107 | static void sigHandler_abrt( __CFA_SIGPARMS__ );
|
|---|
| 108 | static void sigHandler_term( __CFA_SIGPARMS__ );
|
|---|
| [dbe9b08] | 109 |
|
|---|
| [032234bd] | 110 | static struct {
|
|---|
| [d7312ac] | 111 | void (* exit)( int ) __attribute__(( __noreturn__ ));
|
|---|
| 112 | void (* abort)( void ) __attribute__(( __noreturn__ ));
|
|---|
| [95dab9e] | 113 | int (*pthread_create)(pthread_t *_thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
|
|---|
| 114 | int (*pthread_join)(pthread_t _thread, void **retval);
|
|---|
| 115 | pthread_t (*pthread_self)(void);
|
|---|
| 116 | int (*pthread_attr_init)(pthread_attr_t *attr);
|
|---|
| 117 | int (*pthread_attr_destroy)(pthread_attr_t *attr);
|
|---|
| 118 | int (*pthread_attr_setstack)( pthread_attr_t *attr, void *stackaddr, size_t stacksize );
|
|---|
| 119 | int (*pthread_attr_getstacksize)( const pthread_attr_t *attr, size_t *stacksize );
|
|---|
| 120 | int (*pthread_sigmask)(int how, const sigset_t *set, sigset_t *oldset);
|
|---|
| 121 | int (*pthread_sigqueue)(pthread_t _thread, int sig, const union sigval value);
|
|---|
| [3d5f2ef1] | 122 | } __cabi_libc;
|
|---|
| 123 |
|
|---|
| [032234bd] | 124 | libcfa_public int cfa_main_returned;
|
|---|
| [7dd98b6] | 125 |
|
|---|
| [6bfe5cc] | 126 | extern "C" {
|
|---|
| [95dab9e] | 127 | void __cfathreadabi_interpose_startup( generic_fptr_t (*do_interpose_symbol)( void * library, const char symbol[], const char version[] ) ) __attribute__((weak));
|
|---|
| [6bfe5cc] | 128 | void __cfaabi_interpose_startup( void ) {
|
|---|
| [8a13c47] | 129 | const char *version = 0p;
|
|---|
| [7dd98b6] | 130 | cfa_main_returned = 0;
|
|---|
| [9d944b2] | 131 |
|
|---|
| [ad64520] | 132 | preload_libgcc();
|
|---|
| 133 |
|
|---|
| [d7312ac] | 134 | #pragma GCC diagnostic push
|
|---|
| 135 | #pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
|
|---|
| [3d5f2ef1] | 136 | INTERPOSE_LIBC( abort, version );
|
|---|
| 137 | INTERPOSE_LIBC( exit , version );
|
|---|
| [d7312ac] | 138 | #pragma GCC diagnostic pop
|
|---|
| [dbe9b08] | 139 |
|
|---|
| [95dab9e] | 140 | if(__cfathreadabi_interpose_startup) __cfathreadabi_interpose_startup( do_interpose_symbol );
|
|---|
| 141 |
|
|---|
| [8a13c47] | 142 | // As a precaution (and necessity), errors that result in termination are delivered on a separate stack because
|
|---|
| 143 | // task stacks might be very small (4K) and the signal delivery corrupts memory to the point that a clean
|
|---|
| 144 | // shutdown is impossible. Also, when a stack overflow encounters the non-accessible sentinel page (debug only)
|
|---|
| 145 | // and generates a segment fault, the signal cannot be delivered on the sentinel page. Finally, calls to abort
|
|---|
| 146 | // print a stack trace that uses substantial stack space.
|
|---|
| 147 |
|
|---|
| 148 | #define MINSTKSZ SIGSTKSZ * 8
|
|---|
| 149 | static char stack[MINSTKSZ] __attribute__(( aligned (16) ));
|
|---|
| 150 | static stack_t ss;
|
|---|
| 151 |
|
|---|
| 152 | ss.ss_sp = stack;
|
|---|
| 153 | ss.ss_size = MINSTKSZ;
|
|---|
| 154 | ss.ss_flags = 0;
|
|---|
| 155 | if ( sigaltstack( &ss, 0p ) == -1 ) {
|
|---|
| 156 | abort( "__cfaabi_interpose_startup : internal error, sigaltstack error(%d) %s.", errno, strerror( errno ) );
|
|---|
| 157 | } // if
|
|---|
| 158 |
|
|---|
| [de94a60] | 159 | // Failure handler
|
|---|
| [92bfda0] | 160 | // internal errors
|
|---|
| 161 | __cfaabi_sigaction( SIGSEGV, sigHandler_segv, SA_SIGINFO | SA_ONSTACK ); // Invalid memory reference (default: Core)
|
|---|
| 162 | __cfaabi_sigaction( SIGBUS , sigHandler_segv, SA_SIGINFO | SA_ONSTACK ); // Bus error, bad memory access (default: Core)
|
|---|
| 163 | __cfaabi_sigaction( SIGILL , sigHandler_ill , SA_SIGINFO | SA_ONSTACK ); // Illegal Instruction (default: Core)
|
|---|
| 164 | __cfaabi_sigaction( SIGFPE , sigHandler_fpe , SA_SIGINFO | SA_ONSTACK ); // Floating-point exception (default: Core)
|
|---|
| 165 |
|
|---|
| 166 | // handlers to outside errors
|
|---|
| 167 | // reset in-case they insist and send it over and over
|
|---|
| 168 | __cfaabi_sigaction( SIGTERM, sigHandler_term, SA_SIGINFO | SA_ONSTACK | SA_RESETHAND ); // Termination signal (default: Term)
|
|---|
| 169 | __cfaabi_sigaction( SIGINT , sigHandler_term, SA_SIGINFO | SA_ONSTACK | SA_RESETHAND ); // Interrupt from keyboard (default: Term)
|
|---|
| 170 | __cfaabi_sigaction( SIGHUP , sigHandler_term, SA_SIGINFO | SA_ONSTACK | SA_RESETHAND ); // Hangup detected on controlling terminal or death of controlling process (default: Term)
|
|---|
| 171 | __cfaabi_sigaction( SIGQUIT, sigHandler_term, SA_SIGINFO | SA_ONSTACK | SA_RESETHAND ); // Quit from keyboard (default: Core)
|
|---|
| 172 | __cfaabi_sigaction( SIGABRT, sigHandler_term, SA_SIGINFO | SA_ONSTACK | SA_RESETHAND ); // Abort signal from abort(3) (default: Core)
|
|---|
| [6bfe5cc] | 173 | }
|
|---|
| [9d944b2] | 174 | }
|
|---|
| 175 |
|
|---|
| [dbe9b08] | 176 | //=============================================================================================
|
|---|
| 177 | // Terminating Signals logic
|
|---|
| 178 | //=============================================================================================
|
|---|
| 179 |
|
|---|
| [3d5f2ef1] | 180 | // Forward declare abort after the __typeof__ call to avoid ambiguities
|
|---|
| [032234bd] | 181 | libcfa_public void exit( int status, const char fmt[], ... ) __attribute__(( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ ));
|
|---|
| 182 | libcfa_public void abort( const char fmt[], ... ) __attribute__(( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
|
|---|
| 183 | libcfa_public void abort( bool signalAbort, const char fmt[], ... ) __attribute__(( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ ));
|
|---|
| 184 | libcfa_public void __abort( bool signalAbort, const char fmt[], va_list args ) __attribute__(( __nothrow__, __leaf__, __noreturn__ ));
|
|---|
| [3d5f2ef1] | 185 |
|
|---|
| [9d944b2] | 186 | extern "C" {
|
|---|
| [032234bd] | 187 | libcfa_public void abort( void ) __attribute__(( __nothrow__, __leaf__, __noreturn__ )) {
|
|---|
| [1d94116] | 188 | abort( false, "%s", "" );
|
|---|
| [9d944b2] | 189 | }
|
|---|
| 190 |
|
|---|
| [032234bd] | 191 | libcfa_public void __cabi_abort( const char fmt[], ... ) __attribute__(( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ )) {
|
|---|
| [3d5f2ef1] | 192 | va_list argp;
|
|---|
| 193 | va_start( argp, fmt );
|
|---|
| [d870df3] | 194 | __abort( false, fmt, argp );
|
|---|
| [3d5f2ef1] | 195 | va_end( argp );
|
|---|
| [9d944b2] | 196 | }
|
|---|
| 197 |
|
|---|
| [032234bd] | 198 | libcfa_public void exit( int status ) __attribute__(( __nothrow__, __leaf__, __noreturn__ )) {
|
|---|
| [169d944] | 199 | __cabi_libc.exit( status );
|
|---|
| [3d5f2ef1] | 200 | }
|
|---|
| [9d944b2] | 201 | }
|
|---|
| 202 |
|
|---|
| [92bfda0] | 203 | // See concurrency/kernel.cfa and concurrency/preemption.cfa for strong definition used in multi-processor mode.
|
|---|
| 204 | void __kernel_abort_lock( void ) __attribute__(( __nothrow__, __leaf__, __weak__ )) {}
|
|---|
| 205 | void __kernel_abort_msg( char buffer[], int size ) __attribute__(( __nothrow__, __leaf__, __weak__ )) {}
|
|---|
| 206 | int __kernel_abort_lastframe( void ) __attribute__(( __nothrow__, __leaf__, __weak__ )) { return 4; }
|
|---|
| [9d944b2] | 207 |
|
|---|
| 208 | enum { abort_text_size = 1024 };
|
|---|
| 209 | static char abort_text[ abort_text_size ];
|
|---|
| 210 |
|
|---|
| [8a13c47] | 211 | static void __cfaabi_backtrace( int start ) {
|
|---|
| [74330e7] | 212 | enum { Frames = 50, }; // maximum number of stack frames
|
|---|
| [92bfda0] | 213 | int last = __kernel_abort_lastframe(); // skip last N stack frames
|
|---|
| [dbe9b08] | 214 |
|
|---|
| 215 | void * array[Frames];
|
|---|
| [6bfe5cc] | 216 | size_t size = backtrace( array, Frames );
|
|---|
| [74330e7] | 217 | char ** messages = backtrace_symbols( array, size ); // does not demangle names
|
|---|
| [dbe9b08] | 218 |
|
|---|
| [8a13c47] | 219 | *index( messages[0], '(' ) = '\0'; // find executable name
|
|---|
| [1c40091] | 220 | __cfaabi_bits_print_nolock( STDERR_FILENO, "Stack back trace for: %s\n", messages[0]);
|
|---|
| [dbe9b08] | 221 |
|
|---|
| [8a13c47] | 222 | for ( unsigned int i = start; i < size - last && messages != 0p; i += 1 ) {
|
|---|
| [524627e] | 223 | char * name = 0p, * offset_begin = 0p, * offset_end = 0p;
|
|---|
| [dbe9b08] | 224 |
|
|---|
| [74330e7] | 225 | for ( char * p = messages[i]; *p; p += 1 ) { // find parantheses and +offset
|
|---|
| [1c40091] | 226 | //__cfaabi_bits_print_nolock( "X %s\n", p);
|
|---|
| [dbe9b08] | 227 | if ( *p == '(' ) {
|
|---|
| 228 | name = p;
|
|---|
| [4f37255] | 229 | } else if ( *p == '+' ) {
|
|---|
| [dbe9b08] | 230 | offset_begin = p;
|
|---|
| [4f37255] | 231 | } else if ( *p == ')' ) {
|
|---|
| [dbe9b08] | 232 | offset_end = p;
|
|---|
| 233 | break;
|
|---|
| 234 | }
|
|---|
| 235 | }
|
|---|
| 236 |
|
|---|
| [8a13c47] | 237 | // if line contains symbol, print it
|
|---|
| 238 | int frameNo = i - start;
|
|---|
| [dbe9b08] | 239 | if ( name && offset_begin && offset_end && name < offset_begin ) {
|
|---|
| [8a13c47] | 240 | *name++ = '\0'; // delimit strings
|
|---|
| [dbe9b08] | 241 | *offset_begin++ = '\0';
|
|---|
| 242 | *offset_end++ = '\0';
|
|---|
| 243 |
|
|---|
| [1c40091] | 244 | __cfaabi_bits_print_nolock( STDERR_FILENO, "(%i) %s : %s + %s %s\n", frameNo, messages[i], name, offset_begin, offset_end);
|
|---|
| [4f37255] | 245 | } else { // otherwise, print the whole line
|
|---|
| [1c40091] | 246 | __cfaabi_bits_print_nolock( STDERR_FILENO, "(%i) %s\n", frameNo, messages[i] );
|
|---|
| [dbe9b08] | 247 | }
|
|---|
| 248 | }
|
|---|
| 249 | free( messages );
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| [8a13c47] | 252 | void exit( int status, const char fmt[], ... ) {
|
|---|
| 253 | va_list args;
|
|---|
| 254 | va_start( args, fmt );
|
|---|
| 255 | vfprintf( stderr, fmt, args );
|
|---|
| 256 | va_end( args );
|
|---|
| 257 | __cabi_libc.exit( status );
|
|---|
| 258 | }
|
|---|
| 259 |
|
|---|
| [92bfda0] | 260 | static volatile bool __abort_first = 0;
|
|---|
| [6011658] | 261 |
|
|---|
| [d870df3] | 262 | // Cannot forward va_list.
|
|---|
| 263 | void __abort( bool signalAbort, const char fmt[], va_list args ) {
|
|---|
| [92bfda0] | 264 | // Multiple threads can come here from multiple paths
|
|---|
| 265 | // To make sure this is safe any concurrent/subsequent call to abort is redirected to libc-abort
|
|---|
| 266 | bool first = ! __atomic_test_and_set( &__abort_first, __ATOMIC_SEQ_CST);
|
|---|
| [8a13c47] | 267 |
|
|---|
| [92bfda0] | 268 | // Prevent preemption from kicking-in and messing with the abort
|
|---|
| 269 | __kernel_abort_lock();
|
|---|
| [8a13c47] | 270 |
|
|---|
| [92bfda0] | 271 | // first to abort ?
|
|---|
| 272 | if ( !first ) {
|
|---|
| 273 | // We aren't the first to abort just let C handle it
|
|---|
| 274 | signal( SIGABRT, SIG_DFL ); // restore default in case we came here through the function.
|
|---|
| 275 | __cabi_libc.abort();
|
|---|
| 276 | }
|
|---|
| [8a13c47] | 277 |
|
|---|
| [92bfda0] | 278 | int len = snprintf( abort_text, abort_text_size, "Cforall Runtime error (UNIX pid:%ld) ", (long int)getpid() ); // use UNIX pid (versus getPid)
|
|---|
| 279 | __cfaabi_bits_write( STDERR_FILENO, abort_text, len );
|
|---|
| [8a13c47] | 280 |
|
|---|
| [92bfda0] | 281 | // print the cause of the error
|
|---|
| 282 | assert( fmt );
|
|---|
| 283 | len = vsnprintf( abort_text, abort_text_size, fmt, args );
|
|---|
| 284 | __cfaabi_bits_write( STDERR_FILENO, abort_text, len );
|
|---|
| [6011658] | 285 |
|
|---|
| [92bfda0] | 286 | // add optional newline if missing at the end of the format text
|
|---|
| 287 | if ( fmt[strlen( fmt ) - 1] != '\n' ) {
|
|---|
| 288 | __cfaabi_bits_write( STDERR_FILENO, "\n", 1 );
|
|---|
| 289 | } // if
|
|---|
| [6011658] | 290 |
|
|---|
| [92bfda0] | 291 | // Give the kernel the chance to add some data in here
|
|---|
| 292 | __kernel_abort_msg( abort_text, abort_text_size );
|
|---|
| [6011658] | 293 |
|
|---|
| [92bfda0] | 294 | // print stack trace in handler
|
|---|
| 295 | __cfaabi_backtrace( signalAbort ? 4 : 2 );
|
|---|
| [6011658] | 296 |
|
|---|
| [92bfda0] | 297 | // Finally call abort
|
|---|
| 298 | __cabi_libc.abort();
|
|---|
| [5ccee64] | 299 |
|
|---|
| [8a13c47] | 300 | }
|
|---|
| 301 |
|
|---|
| 302 | void abort( const char fmt[], ... ) {
|
|---|
| 303 | va_list args;
|
|---|
| 304 | va_start( args, fmt );
|
|---|
| [d870df3] | 305 | __abort( false, fmt, args );
|
|---|
| 306 | // CONTROL NEVER REACHES HERE!
|
|---|
| [8a13c47] | 307 | va_end( args );
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| [d870df3] | 310 | void abort( bool signalAbort, const char fmt[], ... ) {
|
|---|
| 311 | va_list args;
|
|---|
| 312 | va_start( args, fmt );
|
|---|
| 313 | __abort( signalAbort, fmt, args );
|
|---|
| 314 | // CONTROL NEVER REACHES HERE!
|
|---|
| 315 | va_end( args );
|
|---|
| 316 | }
|
|---|
| 317 |
|
|---|
| [dbe9b08] | 318 | void sigHandler_segv( __CFA_SIGPARMS__ ) {
|
|---|
| [8a13c47] | 319 | if ( sfp->si_addr == 0p ) {
|
|---|
| 320 | abort( true, "Null pointer (0p) dereference.\n" );
|
|---|
| [1469a8a] | 321 | } else {
|
|---|
| [8a13c47] | 322 | abort( true, "%s at memory location %p.\n"
|
|---|
| [1469a8a] | 323 | "Possible cause is reading outside the address space or writing to a protected area within the address space with an invalid pointer or subscript.\n",
|
|---|
| 324 | (sig == SIGSEGV ? "Segment fault" : "Bus error"), sfp->si_addr );
|
|---|
| 325 | }
|
|---|
| [2b8bc41] | 326 | }
|
|---|
| 327 |
|
|---|
| 328 | void sigHandler_ill( __CFA_SIGPARMS__ ) {
|
|---|
| [8a13c47] | 329 | abort( true, "Executing illegal instruction at location %p.\n"
|
|---|
| [2b8bc41] | 330 | "Possible cause is stack corruption.\n",
|
|---|
| 331 | sfp->si_addr );
|
|---|
| 332 | }
|
|---|
| 333 |
|
|---|
| 334 | void sigHandler_fpe( __CFA_SIGPARMS__ ) {
|
|---|
| 335 | const char * msg;
|
|---|
| 336 |
|
|---|
| [a424315d] | 337 | choose( sfp->si_code ) {
|
|---|
| 338 | case FPE_INTDIV, FPE_FLTDIV: msg = "divide by zero";
|
|---|
| 339 | case FPE_FLTOVF: msg = "overflow";
|
|---|
| 340 | case FPE_FLTUND: msg = "underflow";
|
|---|
| 341 | case FPE_FLTRES: msg = "inexact result";
|
|---|
| 342 | case FPE_FLTINV: msg = "invalid operation";
|
|---|
| [2b8bc41] | 343 | default: msg = "unknown";
|
|---|
| [a424315d] | 344 | } // choose
|
|---|
| [8a13c47] | 345 | abort( true, "Computation error %s at location %p.\n", msg, sfp->si_addr );
|
|---|
| [dbe9b08] | 346 | }
|
|---|
| 347 |
|
|---|
| [94dea96] | 348 | void sigHandler_term( __CFA_SIGPARMS__ ) {
|
|---|
| [8a13c47] | 349 | abort( true, "Application interrupted by signal: %s.\n", strsignal( sig ) );
|
|---|
| [94dea96] | 350 | }
|
|---|
| 351 |
|
|---|
| [6b0b624] | 352 | // Local Variables: //
|
|---|
| 353 | // mode: c //
|
|---|
| 354 | // tab-width: 4 //
|
|---|
| 355 | // End: //
|
|---|