Changeset dbe9b08
- Timestamp:
- Jan 25, 2018, 5:02:09 PM (7 years ago)
- Branches:
- ADT, aaron-thesis, arm-eh, ast-experimental, cleanup-dtors, deferred_resn, demangler, enum, forall-pointer-decay, jacob/cs343-translation, jenkins-sandbox, master, new-ast, new-ast-unique-expr, new-env, no_list, persistent-indexer, pthread-emulation, qualifiedEnum, resolv-new, with_gc
- Children:
- 91496f3
- Parents:
- 6e0f4bd
- Location:
- src/libcfa
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/bits/locks.h
r6e0f4bd rdbe9b08 58 58 59 59 #ifdef __cforall 60 extern "C" { 61 extern void disable_interrupts(); 62 extern void enable_interrupts_noPoll(); 63 } 64 60 65 extern void yield( unsigned int ); 61 66 extern thread_local struct thread_desc * volatile this_thread; … … 68 73 static inline _Bool try_lock ( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) { 69 74 _Bool result = __lock_test_and_test_and_set( this.lock ); 70 __cfaabi_dbg_debug_do( 71 if( result ) { 75 if( result ) { 76 disable_interrupts(); 77 __cfaabi_dbg_debug_do( 72 78 this.prev_name = caller; 73 79 this.prev_thrd = this_thread; 74 }75 )80 ) 81 } 76 82 return result; 77 83 } … … 99 105 #endif 100 106 } 107 disable_interrupts(); 101 108 __cfaabi_dbg_debug_do( 102 109 this.prev_name = caller; … … 111 118 yield( i ); 112 119 } 120 disable_interrupts(); 113 121 __cfaabi_dbg_debug_do( 114 122 this.prev_name = caller; … … 119 127 static inline void unlock( __spinlock_t & this ) { 120 128 __lock_release( this.lock ); 129 enable_interrupts_noPoll(); 121 130 } 122 131 #endif -
src/libcfa/concurrency/kernel.c
r6e0f4bd rdbe9b08 516 516 } 517 517 518 //============================================================================================= 519 // Unexpected Terminating logic 520 //============================================================================================= 521 522 518 523 static __spinlock_t kernel_abort_lock; 519 524 static __spinlock_t kernel_debug_lock; -
src/libcfa/concurrency/preemption.c
r6e0f4bd rdbe9b08 19 19 extern "C" { 20 20 #include <errno.h> 21 #include <execinfo.h>22 #define __USE_GNU23 #include <signal.h>24 #undef __USE_GNU25 21 #include <stdio.h> 26 22 #include <string.h> … … 29 25 #undef ftype 30 26 31 #ifdef __USE_STREAM__ 32 #include "fstream" 33 #endif 27 #include "bits/signal.h" 34 28 35 29 //TODO move to defaults … … 40 34 return __CFA_DEFAULT_PREEMPTION__; 41 35 } 42 43 // Short hands for signal context information44 #define __CFA_SIGCXT__ ucontext_t *45 #define __CFA_SIGPARMS__ __attribute__((unused)) int sig, __attribute__((unused)) siginfo_t *sfp, __attribute__((unused)) __CFA_SIGCXT__ cxt46 36 47 37 // FwdDeclarations : timeout handlers … … 53 43 void sigHandler_segv ( __CFA_SIGPARMS__ ); 54 44 void sigHandler_abort ( __CFA_SIGPARMS__ ); 55 56 // FwdDeclarations : sigaction wrapper57 static void __kernel_sigaction( int sig, void (*handler)(__CFA_SIGPARMS__), int flags );58 45 59 46 // FwdDeclarations : alarm thread main … … 246 233 // Setup proper signal handlers 247 234 __kernel_sigaction( SIGUSR1, sigHandler_ctxSwitch, SA_SIGINFO | SA_RESTART ); // CtxSwitch handler 248 // __kernel_sigaction( SIGSEGV, sigHandler_segv , SA_SIGINFO ); // Failure handler249 // __kernel_sigaction( SIGBUS , sigHandler_segv , SA_SIGINFO ); // Failure handler250 235 251 236 signal_block( SIGALRM ); … … 380 365 } 381 366 382 // Sigaction wrapper : register an signal handler383 static void __kernel_sigaction( int sig, void (*handler)(__CFA_SIGPARMS__), int flags ) {384 struct sigaction act;385 386 act.sa_sigaction = (void (*)(int, siginfo_t *, void *))handler;387 act.sa_flags = flags;388 389 if ( sigaction( sig, &act, NULL ) == -1 ) {390 __cfaabi_dbg_print_buffer_decl(391 " __kernel_sigaction( sig:%d, handler:%p, flags:%d ), problem installing signal handler, error(%d) %s.\n",392 sig, handler, flags, errno, strerror( errno )393 );394 _exit( EXIT_FAILURE );395 }396 }397 398 // Sigaction wrapper : restore default handler399 static void __kernel_sigdefault( int sig ) {400 struct sigaction act;401 402 act.sa_handler = SIG_DFL;403 act.sa_flags = 0;404 sigemptyset( &act.sa_mask );405 406 if ( sigaction( sig, &act, NULL ) == -1 ) {407 __cfaabi_dbg_print_buffer_decl(408 " __kernel_sigdefault( sig:%d ), problem reseting signal handler, error(%d) %s.\n",409 sig, errno, strerror( errno )410 );411 _exit( EXIT_FAILURE );412 }413 }414 415 //=============================================================================================416 // Terminating Signals logic417 //=============================================================================================418 419 __cfaabi_dbg_debug_do(420 static void __kernel_backtrace( int start ) {421 // skip first N stack frames422 423 enum { Frames = 50 };424 void * array[Frames];425 int size = backtrace( array, Frames );426 char ** messages = backtrace_symbols( array, size );427 428 // find executable name429 *index( messages[0], '(' ) = '\0';430 #ifdef __USE_STREAM__431 serr | "Stack back trace for:" | messages[0] | endl;432 #else433 fprintf( stderr, "Stack back trace for: %s\n", messages[0]);434 #endif435 436 // skip last 2 stack frames after main437 for ( int i = start; i < size && messages != NULL; i += 1 ) {438 char * name = NULL;439 char * offset_begin = NULL;440 char * offset_end = NULL;441 442 for ( char *p = messages[i]; *p; ++p ) {443 // find parantheses and +offset444 if ( *p == '(' ) {445 name = p;446 }447 else if ( *p == '+' ) {448 offset_begin = p;449 }450 else if ( *p == ')' ) {451 offset_end = p;452 break;453 }454 }455 456 // if line contains symbol print it457 int frameNo = i - start;458 if ( name && offset_begin && offset_end && name < offset_begin ) {459 // delimit strings460 *name++ = '\0';461 *offset_begin++ = '\0';462 *offset_end++ = '\0';463 464 #ifdef __USE_STREAM__465 serr | "(" | frameNo | ")" | messages[i] | ":"466 | name | "+" | offset_begin | offset_end | endl;467 #else468 fprintf( stderr, "(%i) %s : %s + %s %s\n", frameNo, messages[i], name, offset_begin, offset_end);469 #endif470 }471 // otherwise, print the whole line472 else {473 #ifdef __USE_STREAM__474 serr | "(" | frameNo | ")" | messages[i] | endl;475 #else476 fprintf( stderr, "(%i) %s\n", frameNo, messages[i] );477 #endif478 }479 }480 481 free( messages );482 }483 )484 485 // void sigHandler_segv( __CFA_SIGPARMS__ ) {486 // __cfaabi_dbg_debug_do(487 // #ifdef __USE_STREAM__488 // serr | "*CFA runtime error* program cfa-cpp terminated with"489 // | (sig == SIGSEGV ? "segment fault." : "bus error.")490 // | endl;491 // #else492 // fprintf( stderr, "*CFA runtime error* program cfa-cpp terminated with %s\n", sig == SIGSEGV ? "segment fault." : "bus error." );493 // #endif494 495 // // skip first 2 stack frames496 // __kernel_backtrace( 1 );497 // )498 // exit( EXIT_FAILURE );499 // }500 501 // void sigHandler_abort( __CFA_SIGPARMS__ ) {502 // // skip first 6 stack frames503 // __cfaabi_dbg_debug_do( __kernel_backtrace( 6 ); )504 505 // // reset default signal handler506 // __kernel_sigdefault( SIGABRT );507 508 // raise( SIGABRT );509 // }510 511 367 // Local Variables: // 512 368 // mode: c // -
src/libcfa/interpose.c
r6e0f4bd rdbe9b08 22 22 #include <dlfcn.h> 23 23 #include <unistd.h> 24 #define __USE_GNU 25 #include <signal.h> 26 #undef __USE_GNU 27 #include <execinfo.h> 24 28 } 25 29 26 30 #include "bits/debug.h" 27 31 #include "bits/defs.h" 32 #include "bits/signal.h" 28 33 #include "startup.h" 29 34 … … 84 89 #define INIT_REALRTN( x, ver ) assign_ptr( (void**)&libc_##x, #x, ver) 85 90 91 void sigHandler_segv ( __CFA_SIGPARMS__ ); 92 void sigHandler_abort( __CFA_SIGPARMS__ ); 93 86 94 void interpose_startup() { 87 95 const char *version = NULL; … … 89 97 INIT_REALRTN( abort, version ); 90 98 INIT_REALRTN( exit, version ); 91 } 99 100 __kernel_sigaction( SIGSEGV, sigHandler_segv , SA_SIGINFO ); // Failure handler 101 __kernel_sigaction( SIGBUS , sigHandler_segv , SA_SIGINFO ); // Failure handler 102 } 103 104 //============================================================================================= 105 // Terminating Signals logic 106 //============================================================================================= 92 107 93 108 extern "C" { … … 137 152 libc_abort(); 138 153 } 154 } 155 156 // skip first 6 stack frames by default 157 static void __kernel_backtrace() { 158 // skip first N stack frames 159 int start = 6; 160 161 enum { Frames = 50 }; 162 void * array[Frames]; 163 int size = backtrace( array, Frames ); 164 char ** messages = backtrace_symbols( array, size ); 165 166 // find executable name 167 *index( messages[0], '(' ) = '\0'; 168 __cfaabi_dbg_bits_print_nolock( "Stack back trace for: %s\n", messages[0]); 169 170 // skip last 2 stack frames after main 171 for ( int i = start; i < size && messages != NULL; i += 1 ) { 172 char * name = NULL; 173 char * offset_begin = NULL; 174 char * offset_end = NULL; 175 176 for ( char *p = messages[i]; *p; ++p ) { 177 // find parantheses and +offset 178 if ( *p == '(' ) { 179 name = p; 180 } 181 else if ( *p == '+' ) { 182 offset_begin = p; 183 } 184 else if ( *p == ')' ) { 185 offset_end = p; 186 break; 187 } 188 } 189 190 // if line contains symbol print it 191 int frameNo = i - start; 192 if ( name && offset_begin && offset_end && name < offset_begin ) { 193 // delimit strings 194 *name++ = '\0'; 195 *offset_begin++ = '\0'; 196 *offset_end++ = '\0'; 197 198 __cfaabi_dbg_bits_print_nolock( "(%i) %s : %s + %s %s\n", frameNo, messages[i], name, offset_begin, offset_end); 199 } 200 // otherwise, print the whole line 201 else { 202 __cfaabi_dbg_bits_print_nolock( "(%i) %s\n", frameNo, messages[i] ); 203 } 204 } 205 206 free( messages ); 207 } 208 209 void sigHandler_segv( __CFA_SIGPARMS__ ) { 210 // skip first only 1 stack frames in case of segfault. 211 abortf( "*CFA runtime error* program cfa-cpp terminated with %s\n", sig == SIGSEGV ? "segment fault." : "bus error." ); 212 } 213 214 void sigHandler_abort( __CFA_SIGPARMS__ ) { 215 __kernel_backtrace(); 216 217 // reset default signal handler 218 __kernel_sigdefault( SIGABRT ); 219 220 raise( SIGABRT ); 139 221 } 140 222
Note: See TracChangeset
for help on using the changeset viewer.