Changeset 7416d46a for src/libcfa
- Timestamp:
- Jan 30, 2018, 3:54:32 PM (8 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:
- 633a642
- Parents:
- f792cb8 (diff), 42be3c3 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Location:
- src/libcfa
- Files:
-
- 2 added
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/bits/locks.h
rf792cb8 r7416d46a 9 9 // Author : Thierry Delisle 10 10 // Created On : Tue Oct 31 15:14:38 2017 11 // Last Modified By : --12 // Last Modified On : --13 // Update Count : 011 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Dec 8 16:02:22 2017 13 // Update Count : 1 14 14 // 15 15 … … 24 24 #elif defined( __i386 ) || defined( __x86_64 ) 25 25 #define Pause() __asm__ __volatile__ ( "pause" : : : ) 26 #elif defined( __ARM_ARCH ) 27 #define Pause() __asm__ __volatile__ ( "nop" : : : ) 26 28 #else 27 29 #error unsupported architecture 28 30 #endif 29 31 30 #if defined( __i386 ) || defined( __x86_64 ) 32 #if defined( __i386 ) || defined( __x86_64 ) || defined( __ARM_ARCH ) 31 33 // Intel recommendation 32 34 #define __ALIGN__ __attribute__(( aligned (128) )) … … 37 39 #endif 38 40 39 #if defined( __x86_64 )41 #if __SIZEOF_SIZE_T__ == 8 40 42 #define __lock_test_and_test_and_set( lock ) (lock) == 0 && __sync_lock_test_and_set_8( &(lock), 1 ) == 0 41 43 #define __lock_release( lock ) __sync_lock_release_8( &(lock) ); 42 #elif defined( __i386 )44 #elif __SIZEOF_SIZE_T__ == 4 43 45 #define __lock_test_and_test_and_set( lock ) (lock) == 0 && __sync_lock_test_and_set_4( &(lock), 1 ) == 0 44 46 #define __lock_release( lock ) __sync_lock_release_4( &(lock) ); … … 48 50 49 51 struct __spinlock_t { 50 __ALIGN__ volatile uintptr_t lock;52 __ALIGN__ volatile size_t lock; 51 53 #ifdef __CFA_DEBUG__ 52 54 const char * prev_name; … … 56 58 57 59 #ifdef __cforall 60 extern "C" { 61 extern void disable_interrupts(); 62 extern void enable_interrupts_noPoll(); 63 } 64 58 65 extern void yield( unsigned int ); 59 66 extern thread_local struct thread_desc * volatile this_thread; 67 extern thread_local struct processor * volatile this_processor; 60 68 61 69 static inline void ?{}( __spinlock_t & this ) { … … 66 74 static inline _Bool try_lock ( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) { 67 75 _Bool result = __lock_test_and_test_and_set( this.lock ); 68 __cfaabi_dbg_debug_do( 69 if( result ) { 76 if( result ) { 77 disable_interrupts(); 78 __cfaabi_dbg_debug_do( 70 79 this.prev_name = caller; 71 80 this.prev_thrd = this_thread; 72 }73 )81 ) 82 } 74 83 return result; 75 84 } … … 97 106 #endif 98 107 } 108 disable_interrupts(); 99 109 __cfaabi_dbg_debug_do( 100 110 this.prev_name = caller; … … 103 113 } 104 114 105 // Lock the spinlock, spin if already acquired 106 static inline void lock_yield( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) { 107 for ( unsigned int i = 1;; i += 1 ) { 108 if ( __lock_test_and_test_and_set( this.lock ) ) break; 109 yield( i ); 110 } 111 __cfaabi_dbg_debug_do( 112 this.prev_name = caller; 113 this.prev_thrd = this_thread; 114 ) 115 } 115 // // Lock the spinlock, yield if already acquired 116 // static inline void lock_yield( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) { 117 // for ( unsigned int i = 1;; i += 1 ) { 118 // if ( __lock_test_and_test_and_set( this.lock ) ) break; 119 // yield( i ); 120 // } 121 // disable_interrupts(); 122 // __cfaabi_dbg_debug_do( 123 // this.prev_name = caller; 124 // this.prev_thrd = this_thread; 125 // ) 126 // } 116 127 117 128 static inline void unlock( __spinlock_t & this ) { 129 enable_interrupts_noPoll(); 118 130 __lock_release( this.lock ); 119 131 } -
src/libcfa/concurrency/invoke.c
rf792cb8 r7416d46a 10 10 // Created On : Tue Jan 17 12:27:26 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 21 22:28:33 201713 // Update Count : 112 // Last Modified On : Tue Jan 23 14:04:56 2018 13 // Update Count : 2 14 14 // 15 15 … … 133 133 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520 134 134 ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F; //Vol. 1 8-7 135 136 #elif defined( __ARM_ARCH ) 137 138 struct FakeStack { 139 float fpRegs[16]; // floating point registers 140 void *intRegs[9]; // integer/pointer registers 141 void *arg[2]; // placeholder for this pointer 142 }; 143 144 ((struct machine_context_t *)stack->context)->SP = (char *)stack->base - sizeof( struct FakeStack ); 145 ((struct machine_context_t *)stack->context)->FP = NULL; 146 147 struct FakeStack *fs = (struct FakeStack *)((struct machine_context_t *)stack->context)->SP; 148 149 fs->intRegs[8] = CtxInvokeStub; 150 fs->arg[0] = this; 151 fs->arg[1] = invoke; 135 152 #else 136 153 #error Only __i386__ and __x86_64__ is supported for threads in cfa -
src/libcfa/concurrency/invoke.h
rf792cb8 r7416d46a 10 10 // Created On : Tue Jan 17 12:27:26 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 21 22:28:56 201713 // Update Count : 112 // Last Modified On : Tue Jan 23 14:55:46 2018 13 // Update Count : 3 14 14 // 15 15 … … 134 134 // instrusive link field for threads 135 135 struct thread_desc * next; 136 137 __cfaabi_dbg_debug_do( 138 // instrusive link field for debugging 139 struct thread_desc * dbg_next; 140 struct thread_desc * dbg_prev; 141 ) 136 142 }; 137 143 … … 203 209 "movl %%ebp,%1\n" \ 204 210 : "=rm" (ctx.SP), "=rm" (ctx.FP) ) 211 #elif defined( __ARM_ARCH ) 212 #define CtxGet( ctx ) __asm__ ( \ 213 "mov %0,%%sp\n" \ 214 "mov %1,%%r11\n" \ 215 : "=rm" (ctx.SP), "=rm" (ctx.FP) ) 205 216 #endif 206 217 -
src/libcfa/concurrency/kernel.c
rf792cb8 r7416d46a 10 10 // Created On : Tue Jan 17 12:27:26 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 21 22:33:18201713 // Update Count : 212 // Last Modified On : Fri Dec 8 16:23:33 2017 13 // Update Count : 3 14 14 // 15 15 16 16 //C Includes 17 17 #include <stddef.h> 18 #define ftype `ftype` 18 19 extern "C" { 19 20 #include <stdio.h> … … 23 24 #include <unistd.h> 24 25 } 26 #undef ftype 25 27 26 28 //CFA Includes … … 240 242 void finishRunning(processor * this) with( this->finish ) { 241 243 if( action_code == Release ) { 244 verify( disable_preempt_count > 1 ); 242 245 unlock( *lock ); 243 246 } … … 246 249 } 247 250 else if( action_code == Release_Schedule ) { 251 verify( disable_preempt_count > 1 ); 248 252 unlock( *lock ); 249 253 ScheduleThread( thrd ); 250 254 } 251 255 else if( action_code == Release_Multi ) { 256 verify( disable_preempt_count > lock_count ); 252 257 for(int i = 0; i < lock_count; i++) { 253 258 unlock( *locks[i] ); … … 363 368 this_processor->finish.lock = lock; 364 369 365 verify( disable_preempt_count > 0);370 verify( disable_preempt_count > 1 ); 366 371 suspend(); 367 372 verify( disable_preempt_count > 0 ); … … 389 394 this_processor->finish.thrd = thrd; 390 395 391 verify( disable_preempt_count > 0);396 verify( disable_preempt_count > 1 ); 392 397 suspend(); 393 398 verify( disable_preempt_count > 0 ); … … 514 519 } 515 520 521 //============================================================================================= 522 // Unexpected Terminating logic 523 //============================================================================================= 524 525 516 526 static __spinlock_t kernel_abort_lock; 517 527 static __spinlock_t kernel_debug_lock; … … 609 619 } 610 620 621 //----------------------------------------------------------------------------- 622 // Debug 623 __cfaabi_dbg_debug_do( 624 struct { 625 thread_desc * tail; 626 } __cfaabi_dbg_thread_list = { NULL }; 627 628 void __cfaabi_dbg_thread_register( thread_desc * thrd ) { 629 if( !__cfaabi_dbg_thread_list.tail ) { 630 __cfaabi_dbg_thread_list.tail = thrd; 631 return; 632 } 633 __cfaabi_dbg_thread_list.tail->dbg_next = thrd; 634 thrd->dbg_prev = __cfaabi_dbg_thread_list.tail; 635 __cfaabi_dbg_thread_list.tail = thrd; 636 } 637 638 void __cfaabi_dbg_thread_unregister( thread_desc * thrd ) { 639 thread_desc * prev = thrd->dbg_prev; 640 thread_desc * next = thrd->dbg_next; 641 642 if( next ) { next->dbg_prev = prev; } 643 else { 644 assert( __cfaabi_dbg_thread_list.tail == thrd ); 645 __cfaabi_dbg_thread_list.tail = prev; 646 } 647 648 if( prev ) { prev->dbg_next = next; } 649 650 thrd->dbg_prev = NULL; 651 thrd->dbg_next = NULL; 652 } 653 ) 611 654 // Local Variables: // 612 655 // mode: c // -
src/libcfa/concurrency/kernel_private.h
rf792cb8 r7416d46a 85 85 extern void ThreadCtxSwitch(coroutine_desc * src, coroutine_desc * dst); 86 86 87 __cfaabi_dbg_debug_do( 88 extern void __cfaabi_dbg_thread_register ( thread_desc * thrd ); 89 extern void __cfaabi_dbg_thread_unregister( thread_desc * thrd ); 90 ) 91 87 92 //----------------------------------------------------------------------------- 88 93 // Utils -
src/libcfa/concurrency/monitor.c
rf792cb8 r7416d46a 53 53 static inline __lock_size_t aggregate ( monitor_desc * storage [], const __waitfor_mask_t & mask ); 54 54 55 #ifndef __CFA_LOCK_NO_YIELD56 #define DO_LOCK lock_yield57 #else58 #define DO_LOCK lock59 #endif60 61 55 //----------------------------------------------------------------------------- 62 56 // Useful defines … … 90 84 static void __enter_monitor_desc( monitor_desc * this, const __monitor_group_t & group ) { 91 85 // Lock the monitor spinlock 92 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );86 lock( this->lock __cfaabi_dbg_ctx2 ); 93 87 thread_desc * thrd = this_thread; 88 89 verify( disable_preempt_count > 0 ); 94 90 95 91 __cfaabi_dbg_print_safe("Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner); … … 121 117 // Some one else has the monitor, wait in line for it 122 118 append( this->entry_queue, thrd ); 119 120 verify( disable_preempt_count > 0 ); 121 123 122 BlockInternal( &this->lock ); 124 123 … … 138 137 static void __enter_monitor_dtor( monitor_desc * this, fptr_t func ) { 139 138 // Lock the monitor spinlock 140 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );139 lock( this->lock __cfaabi_dbg_ctx2 ); 141 140 thread_desc * thrd = this_thread; 142 141 … … 201 200 // Leave single monitor 202 201 void __leave_monitor_desc( monitor_desc * this ) { 203 // Lock the monitor spinlock , DO_LOCK to reduce contention204 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );202 // Lock the monitor spinlock 203 lock( this->lock __cfaabi_dbg_ctx2 ); 205 204 206 205 __cfaabi_dbg_print_safe("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner); … … 248 247 249 248 // Lock the monitor now 250 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );249 lock( this->lock __cfaabi_dbg_ctx2 ); 251 250 252 251 disable_interrupts(); … … 397 396 append( this.blocked, &waiter ); 398 397 398 verify( disable_preempt_count == 0 ); 399 399 400 // Lock all monitors (aggregates the locks as well) 400 401 lock_all( monitors, locks, count ); 402 403 // verifyf( disable_preempt_count == count, "Got %d, expected %d\n", disable_preempt_count, count ); 404 if(disable_preempt_count != count) { __cfaabi_dbg_print_buffer_decl("----------Gonna crash\n"); } 401 405 402 406 // Find the next thread(s) to run … … 473 477 monitor_ctx( this.monitors, this.monitor_count ); 474 478 479 verify( disable_preempt_count == 0 ); 480 475 481 // Lock all monitors (aggregates the locks them as well) 476 482 lock_all( monitors, locks, count ); 483 484 // verify( disable_preempt_count == count ); 485 if(disable_preempt_count != count) { __cfaabi_dbg_print_buffer_decl("----------Gonna crash\n"); } 486 477 487 478 488 // Create the node specific to this wait operation … … 737 747 static inline void lock_all( __spinlock_t * locks [], __lock_size_t count ) { 738 748 for( __lock_size_t i = 0; i < count; i++ ) { 739 DO_LOCK( *locks[i] __cfaabi_dbg_ctx2 );749 lock( *locks[i] __cfaabi_dbg_ctx2 ); 740 750 } 741 751 } … … 744 754 for( __lock_size_t i = 0; i < count; i++ ) { 745 755 __spinlock_t * l = &source[i]->lock; 746 DO_LOCK( *l __cfaabi_dbg_ctx2 );756 lock( *l __cfaabi_dbg_ctx2 ); 747 757 if(locks) locks[i] = l; 748 758 } -
src/libcfa/concurrency/preemption.c
rf792cb8 r7416d46a 10 10 // Created On : Mon Jun 5 14:20:42 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Jul 21 22:36:05 201713 // Update Count : 212 // Last Modified On : Tue Jan 23 17:59:30 2018 13 // Update Count : 7 14 14 // 15 15 16 16 #include "preemption.h" 17 17 18 #define ftype `ftype` 18 19 extern "C" { 19 20 #include <errno.h> 20 #include <execinfo.h>21 #define __USE_GNU22 #include <signal.h>23 #undef __USE_GNU24 21 #include <stdio.h> 25 22 #include <string.h> 26 23 #include <unistd.h> 27 24 } 28 29 30 #ifdef __USE_STREAM__ 31 #include "fstream" 32 #endif 25 #undef ftype 26 27 #include "bits/signal.h" 33 28 34 29 //TODO move to defaults … … 39 34 return __CFA_DEFAULT_PREEMPTION__; 40 35 } 41 42 // Short hands for signal context information43 #define __CFA_SIGCXT__ ucontext_t *44 #define __CFA_SIGPARMS__ __attribute__((unused)) int sig, __attribute__((unused)) siginfo_t *sfp, __attribute__((unused)) __CFA_SIGCXT__ cxt45 36 46 37 // FwdDeclarations : timeout handlers … … 53 44 void sigHandler_abort ( __CFA_SIGPARMS__ ); 54 45 55 // FwdDeclarations : sigaction wrapper56 static void __kernel_sigaction( int sig, void (*handler)(__CFA_SIGPARMS__), int flags );57 58 46 // FwdDeclarations : alarm thread main 59 47 void * alarm_loop( __attribute__((unused)) void * args ); 60 48 61 49 // Machine specific register name 62 #if def __x86_64__50 #if defined(__x86_64__) 63 51 #define CFA_REG_IP REG_RIP 64 #el se52 #elif defined(__i386__) 65 53 #define CFA_REG_IP REG_EIP 54 #elif defined(__ARM_ARCH__) 55 #define CFA_REG_IP REG_R15 66 56 #endif 67 57 … … 179 169 void enable_interrupts_noPoll() { 180 170 __attribute__((unused)) unsigned short prev = __atomic_fetch_add_2( &disable_preempt_count, -1, __ATOMIC_SEQ_CST ); 181 verify ( prev != 0u); // If this triggers someone is enabled already enabled interrupts171 verifyf( prev != 0u, "Incremented from %u\n", prev ); // If this triggers someone is enabled already enabled interrupts 182 172 } 183 173 } … … 243 233 // Setup proper signal handlers 244 234 __kernel_sigaction( SIGUSR1, sigHandler_ctxSwitch, SA_SIGINFO | SA_RESTART ); // CtxSwitch handler 245 // __kernel_sigaction( SIGSEGV, sigHandler_segv , SA_SIGINFO ); // Failure handler246 // __kernel_sigaction( SIGBUS , sigHandler_segv , SA_SIGINFO ); // Failure handler247 235 248 236 signal_block( SIGALRM ); … … 296 284 // Receives SIGUSR1 signal and causes the current thread to yield 297 285 void sigHandler_ctxSwitch( __CFA_SIGPARMS__ ) { 286 #if defined( __ARM_ARCH ) 287 __cfaabi_dbg_debug_do( last_interrupt = (void *)(cxt->uc_mcontext.arm_pc); ) 288 #else 298 289 __cfaabi_dbg_debug_do( last_interrupt = (void *)(cxt->uc_mcontext.gregs[CFA_REG_IP]); ) 299 300 // Check if it is safe to preempt here 290 #endif 291 292 // Check if it is safe to preempt here 301 293 if( !preemption_ready() ) { return; } 294 295 __cfaabi_dbg_print_buffer_decl(" KERNEL: preempting core %p (%p).\n", this_processor, this_thread); 302 296 303 297 preemption_in_progress = true; // Sync flag : prevent recursive calls to the signal handler … … 371 365 } 372 366 373 // Sigaction wrapper : register an signal handler374 static void __kernel_sigaction( int sig, void (*handler)(__CFA_SIGPARMS__), int flags ) {375 struct sigaction act;376 377 act.sa_sigaction = (void (*)(int, siginfo_t *, void *))handler;378 act.sa_flags = flags;379 380 if ( sigaction( sig, &act, NULL ) == -1 ) {381 __cfaabi_dbg_print_buffer_decl(382 " __kernel_sigaction( sig:%d, handler:%p, flags:%d ), problem installing signal handler, error(%d) %s.\n",383 sig, handler, flags, errno, strerror( errno )384 );385 _exit( EXIT_FAILURE );386 }387 }388 389 // Sigaction wrapper : restore default handler390 static void __kernel_sigdefault( int sig ) {391 struct sigaction act;392 393 act.sa_handler = SIG_DFL;394 act.sa_flags = 0;395 sigemptyset( &act.sa_mask );396 397 if ( sigaction( sig, &act, NULL ) == -1 ) {398 __cfaabi_dbg_print_buffer_decl(399 " __kernel_sigdefault( sig:%d ), problem reseting signal handler, error(%d) %s.\n",400 sig, errno, strerror( errno )401 );402 _exit( EXIT_FAILURE );403 }404 }405 406 //=============================================================================================407 // Terminating Signals logic408 //=============================================================================================409 410 __cfaabi_dbg_debug_do(411 static void __kernel_backtrace( int start ) {412 // skip first N stack frames413 414 enum { Frames = 50 };415 void * array[Frames];416 int size = backtrace( array, Frames );417 char ** messages = backtrace_symbols( array, size );418 419 // find executable name420 *index( messages[0], '(' ) = '\0';421 #ifdef __USE_STREAM__422 serr | "Stack back trace for:" | messages[0] | endl;423 #else424 fprintf( stderr, "Stack back trace for: %s\n", messages[0]);425 #endif426 427 // skip last 2 stack frames after main428 for ( int i = start; i < size && messages != NULL; i += 1 ) {429 char * name = NULL;430 char * offset_begin = NULL;431 char * offset_end = NULL;432 433 for ( char *p = messages[i]; *p; ++p ) {434 // find parantheses and +offset435 if ( *p == '(' ) {436 name = p;437 }438 else if ( *p == '+' ) {439 offset_begin = p;440 }441 else if ( *p == ')' ) {442 offset_end = p;443 break;444 }445 }446 447 // if line contains symbol print it448 int frameNo = i - start;449 if ( name && offset_begin && offset_end && name < offset_begin ) {450 // delimit strings451 *name++ = '\0';452 *offset_begin++ = '\0';453 *offset_end++ = '\0';454 455 #ifdef __USE_STREAM__456 serr | "(" | frameNo | ")" | messages[i] | ":"457 | name | "+" | offset_begin | offset_end | endl;458 #else459 fprintf( stderr, "(%i) %s : %s + %s %s\n", frameNo, messages[i], name, offset_begin, offset_end);460 #endif461 }462 // otherwise, print the whole line463 else {464 #ifdef __USE_STREAM__465 serr | "(" | frameNo | ")" | messages[i] | endl;466 #else467 fprintf( stderr, "(%i) %s\n", frameNo, messages[i] );468 #endif469 }470 }471 472 free( messages );473 }474 )475 476 // void sigHandler_segv( __CFA_SIGPARMS__ ) {477 // __cfaabi_dbg_debug_do(478 // #ifdef __USE_STREAM__479 // serr | "*CFA runtime error* program cfa-cpp terminated with"480 // | (sig == SIGSEGV ? "segment fault." : "bus error.")481 // | endl;482 // #else483 // fprintf( stderr, "*CFA runtime error* program cfa-cpp terminated with %s\n", sig == SIGSEGV ? "segment fault." : "bus error." );484 // #endif485 486 // // skip first 2 stack frames487 // __kernel_backtrace( 1 );488 // )489 // exit( EXIT_FAILURE );490 // }491 492 // void sigHandler_abort( __CFA_SIGPARMS__ ) {493 // // skip first 6 stack frames494 // __cfaabi_dbg_debug_do( __kernel_backtrace( 6 ); )495 496 // // reset default signal handler497 // __kernel_sigdefault( SIGABRT );498 499 // raise( SIGABRT );500 // }501 502 367 // Local Variables: // 503 368 // mode: c // -
src/libcfa/concurrency/thread.c
rf792cb8 r7416d46a 38 38 self_mon_p = &self_mon; 39 39 next = NULL; 40 __cfaabi_dbg_debug_do( 41 dbg_next = NULL; 42 dbg_prev = NULL; 43 __cfaabi_dbg_thread_register(&this); 44 ) 40 45 41 46 monitors{ &self_mon_p, 1, (fptr_t)0 }; -
src/libcfa/interpose.c
rf792cb8 r7416d46a 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 30 void interpose_startup(void) __attribute__(( constructor( STARTUP_PRIORITY_CORE ) ));35 void __cfaabi_interpose_startup(void) __attribute__(( constructor( STARTUP_PRIORITY_CORE ) )); 31 36 32 37 typedef void (*generic_fptr_t)(void); … … 84 89 #define INIT_REALRTN( x, ver ) assign_ptr( (void**)&libc_##x, #x, ver) 85 90 86 void interpose_startup() { 91 void sigHandler_segv ( __CFA_SIGPARMS__ ); 92 void sigHandler_abort( __CFA_SIGPARMS__ ); 93 94 void __cfaabi_interpose_startup() { 87 95 const char *version = NULL; 88 96 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 __kernel_sigaction( SIGABRT, sigHandler_abort, SA_SIGINFO ); // Failure handler 103 } 104 105 //============================================================================================= 106 // Terminating Signals logic 107 //============================================================================================= 92 108 93 109 extern "C" { … … 137 153 libc_abort(); 138 154 } 155 } 156 157 // skip first 6 stack frames by default 158 static void __kernel_backtrace() { 159 // skip first N stack frames 160 int start = 6; 161 162 enum { Frames = 50 }; 163 void * array[Frames]; 164 int size = backtrace( array, Frames ); 165 char ** messages = backtrace_symbols( array, size ); 166 167 // find executable name 168 *index( messages[0], '(' ) = '\0'; 169 __cfaabi_dbg_bits_print_nolock( "Stack back trace for: %s\n", messages[0]); 170 171 // skip last 2 stack frames after main 172 for ( int i = start; i < size && messages != NULL; i += 1 ) { 173 char * name = NULL; 174 char * offset_begin = NULL; 175 char * offset_end = NULL; 176 177 for ( char *p = messages[i]; *p; ++p ) { 178 // find parantheses and +offset 179 if ( *p == '(' ) { 180 name = p; 181 } 182 else if ( *p == '+' ) { 183 offset_begin = p; 184 } 185 else if ( *p == ')' ) { 186 offset_end = p; 187 break; 188 } 189 } 190 191 // if line contains symbol print it 192 int frameNo = i - start; 193 if ( name && offset_begin && offset_end && name < offset_begin ) { 194 // delimit strings 195 *name++ = '\0'; 196 *offset_begin++ = '\0'; 197 *offset_end++ = '\0'; 198 199 __cfaabi_dbg_bits_print_nolock( "(%i) %s : %s + %s %s\n", frameNo, messages[i], name, offset_begin, offset_end); 200 } 201 // otherwise, print the whole line 202 else { 203 __cfaabi_dbg_bits_print_nolock( "(%i) %s\n", frameNo, messages[i] ); 204 } 205 } 206 207 free( messages ); 208 } 209 210 void sigHandler_segv( __CFA_SIGPARMS__ ) { 211 // skip first only 1 stack frames in case of segfault. 212 abortf( "*CFA runtime error* program cfa-cpp terminated with %s\n", sig == SIGSEGV ? "segment fault." : "bus error." ); 213 } 214 215 void sigHandler_abort( __CFA_SIGPARMS__ ) { 216 __kernel_backtrace(); 217 218 // reset default signal handler 219 __kernel_sigdefault( SIGABRT ); 220 221 raise( SIGABRT ); 139 222 } 140 223 -
src/libcfa/iostream
rf792cb8 r7416d46a 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Dec 21 13:55:41 201713 // Update Count : 14 512 // Last Modified On : Thu Jan 25 13:08:39 2018 13 // Update Count : 149 14 14 // 15 15 … … 124 124 }; // readable 125 125 126 forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Bool & ); 127 126 128 forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, char & ); 127 129 forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, signed char & ); … … 145 147 forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, long double _Complex & ); 146 148 149 // manipulators 150 forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, istype & (*)( istype & ) ); 151 forall( dtype istype | istream( istype ) ) istype & endl( istype & is ); 152 147 153 struct _Istream_cstrUC { char * s; }; 148 154 _Istream_cstrUC cstr( char * ); -
src/libcfa/iostream.c
rf792cb8 r7416d46a 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Dec 21 13:55:09 201713 // Update Count : 4 2712 // Last Modified On : Thu Jan 25 13:09:28 2018 13 // Update Count : 467 14 14 // 15 15 … … 19 19 #include <stdio.h> 20 20 #include <stdbool.h> // true/false 21 #include <string.h> // strlen 21 //#include <string.h> // strlen, strcmp 22 extern int strcmp (const char *__s1, const char *__s2) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2))); 23 extern size_t strlen (const char *__s) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1))); 22 24 #include <float.h> // DBL_DIG, LDBL_DIG 23 25 #include <complex.h> // creal, cimag … … 301 303 302 304 forall( dtype istype | istream( istype ) ) 305 istype & ?|?( istype & is, _Bool & b ) { 306 char val[6]; 307 fmt( is, "%5s", val ); 308 if ( strcmp( val, "true" ) == 0 ) b = true; 309 else if ( strcmp( val, "false" ) == 0 ) b = false; 310 else { 311 fprintf( stderr, "invalid _Bool constant\n" ); 312 abort(); 313 } // if 314 return is; 315 } // ?|? 316 317 forall( dtype istype | istream( istype ) ) 303 318 istype & ?|?( istype & is, char & c ) { 304 319 fmt( is, "%c", &c ); // must pass pointer through varg to fmt … … 410 425 } // ?|? 411 426 427 forall( dtype istype | istream( istype ) ) 428 istype & ?|?( istype & is, istype & (* manip)( istype & ) ) { 429 return manip( is ); 430 } // ?|? 431 432 forall( dtype istype | istream( istype ) ) 433 istype & endl( istype & is ) { 434 fmt( is, "%*[ \t\f\n\r\v]" ); // ignore whitespace 435 return is; 436 } // endl 437 412 438 _Istream_cstrUC cstr( char * str ) { return (_Istream_cstrUC){ str }; } 413 439 forall( dtype istype | istream( istype ) ) -
src/libcfa/stdlib.c
rf792cb8 r7416d46a 5 5 // file "LICENCE" distributed with Cforall. 6 6 // 7 // algorithm.c --7 // stdlib.c -- 8 8 // 9 9 // Author : Peter A. Buhr 10 10 // Created On : Thu Jan 28 17:10:29 2016 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Jan 2 12:20:32201813 // Update Count : 44 112 // Last Modified On : Wed Jan 3 08:29:29 2018 13 // Update Count : 444 14 14 // 15 15 … … 24 24 #include <complex.h> // _Complex_I 25 25 #include <assert.h> 26 27 //--------------------------------------- 26 28 27 29 // resize, non-array types … … 257 259 //--------------------------------------- 258 260 259 extern "C" { void srandom( unsigned int seed ) { srand48( seed ); } } // override C version261 extern "C" { void srandom( unsigned int seed ) { srand48( (long int)seed ); } } // override C version 260 262 char random( void ) { return (unsigned long int)random(); } 261 263 char random( char u ) { return random( (unsigned long int)u ); }
Note:
See TracChangeset
for help on using the changeset viewer.