Changeset 7416d46a for src/libcfa


Ignore:
Timestamp:
Jan 30, 2018, 3:54:32 PM (8 years ago)
Author:
Thierry Delisle <tdelisle@…>
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.
Message:

Merge branch 'master' of plg.uwaterloo.ca:software/cfa/cfa-cc

Location:
src/libcfa
Files:
2 added
12 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/bits/locks.h

    rf792cb8 r7416d46a  
    99// Author           : Thierry Delisle
    1010// Created On       : Tue Oct 31 15:14:38 2017
    11 // Last Modified By : --
    12 // Last Modified On : --
    13 // Update Count     : 0
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Dec  8 16:02:22 2017
     13// Update Count     : 1
    1414//
    1515
     
    2424#elif defined( __i386 ) || defined( __x86_64 )
    2525        #define Pause() __asm__ __volatile__ ( "pause" : : : )
     26#elif defined( __ARM_ARCH )
     27        #define Pause() __asm__ __volatile__ ( "nop" : : : )
    2628#else
    2729        #error unsupported architecture
    2830#endif
    2931
    30 #if defined( __i386 ) || defined( __x86_64 )
     32#if defined( __i386 ) || defined( __x86_64 ) || defined( __ARM_ARCH )
    3133        // Intel recommendation
    3234        #define __ALIGN__ __attribute__(( aligned (128) ))
     
    3739#endif
    3840
    39 #if defined( __x86_64 )
     41#if __SIZEOF_SIZE_T__ == 8
    4042        #define __lock_test_and_test_and_set( lock ) (lock) == 0 && __sync_lock_test_and_set_8( &(lock), 1 ) == 0
    4143        #define __lock_release( lock ) __sync_lock_release_8( &(lock) );
    42 #elif defined( __i386 )
     44#elif __SIZEOF_SIZE_T__ == 4
    4345        #define __lock_test_and_test_and_set( lock ) (lock) == 0 && __sync_lock_test_and_set_4( &(lock), 1 ) == 0
    4446        #define __lock_release( lock ) __sync_lock_release_4( &(lock) );
     
    4850
    4951struct __spinlock_t {
    50         __ALIGN__ volatile uintptr_t lock;
     52        __ALIGN__ volatile size_t lock;
    5153        #ifdef __CFA_DEBUG__
    5254                const char * prev_name;
     
    5658
    5759#ifdef __cforall
     60        extern "C" {
     61                extern void disable_interrupts();
     62                extern void enable_interrupts_noPoll();
     63        }
     64
    5865        extern void yield( unsigned int );
    5966        extern thread_local struct thread_desc *    volatile this_thread;
     67        extern thread_local struct processor *      volatile this_processor;
    6068
    6169        static inline void ?{}( __spinlock_t & this ) {
     
    6674        static inline _Bool try_lock  ( __spinlock_t & this __cfaabi_dbg_ctx_param2 ) {
    6775                _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(
    7079                                this.prev_name = caller;
    7180                                this.prev_thrd = this_thread;
    72                         }
    73                 )
     81                        )
     82                }
    7483                return result;
    7584        }
     
    97106                        #endif
    98107                }
     108                disable_interrupts();
    99109                __cfaabi_dbg_debug_do(
    100110                        this.prev_name = caller;
     
    103113        }
    104114
    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        // }
    116127
    117128        static inline void unlock( __spinlock_t & this ) {
     129                enable_interrupts_noPoll();
    118130                __lock_release( this.lock );
    119131        }
  • src/libcfa/concurrency/invoke.c

    rf792cb8 r7416d46a  
    1010// Created On       : Tue Jan 17 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:28:33 2017
    13 // Update Count     : 1
     12// Last Modified On : Tue Jan 23 14:04:56 2018
     13// Update Count     : 2
    1414//
    1515
     
    133133        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->mxcr = 0x1F80; //Vol. 2A 3-520
    134134        ((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;
    135152#else
    136153        #error Only __i386__ and __x86_64__ is supported for threads in cfa
  • src/libcfa/concurrency/invoke.h

    rf792cb8 r7416d46a  
    1010// Created On       : Tue Jan 17 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:28:56 2017
    13 // Update Count     : 1
     12// Last Modified On : Tue Jan 23 14:55:46 2018
     13// Update Count     : 3
    1414//
    1515
     
    134134                // instrusive link field for threads
    135135                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                )
    136142     };
    137143
     
    203209                        "movl %%ebp,%1\n"   \
    204210                : "=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) )
    205216        #endif
    206217
  • src/libcfa/concurrency/kernel.c

    rf792cb8 r7416d46a  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:33:18 2017
    13 // Update Count     : 2
     12// Last Modified On : Fri Dec  8 16:23:33 2017
     13// Update Count     : 3
    1414//
    1515
    1616//C Includes
    1717#include <stddef.h>
     18#define ftype `ftype`
    1819extern "C" {
    1920#include <stdio.h>
     
    2324#include <unistd.h>
    2425}
     26#undef ftype
    2527
    2628//CFA Includes
     
    240242void finishRunning(processor * this) with( this->finish ) {
    241243        if( action_code == Release ) {
     244                verify( disable_preempt_count > 1 );
    242245                unlock( *lock );
    243246        }
     
    246249        }
    247250        else if( action_code == Release_Schedule ) {
     251                verify( disable_preempt_count > 1 );
    248252                unlock( *lock );
    249253                ScheduleThread( thrd );
    250254        }
    251255        else if( action_code == Release_Multi ) {
     256                verify( disable_preempt_count > lock_count );
    252257                for(int i = 0; i < lock_count; i++) {
    253258                        unlock( *locks[i] );
     
    363368        this_processor->finish.lock        = lock;
    364369
    365         verify( disable_preempt_count > 0 );
     370        verify( disable_preempt_count > 1 );
    366371        suspend();
    367372        verify( disable_preempt_count > 0 );
     
    389394        this_processor->finish.thrd        = thrd;
    390395
    391         verify( disable_preempt_count > 0 );
     396        verify( disable_preempt_count > 1 );
    392397        suspend();
    393398        verify( disable_preempt_count > 0 );
     
    514519}
    515520
     521//=============================================================================================
     522// Unexpected Terminating logic
     523//=============================================================================================
     524
     525
    516526static __spinlock_t kernel_abort_lock;
    517527static __spinlock_t kernel_debug_lock;
     
    609619}
    610620
     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)
    611654// Local Variables: //
    612655// mode: c //
  • src/libcfa/concurrency/kernel_private.h

    rf792cb8 r7416d46a  
    8585extern void ThreadCtxSwitch(coroutine_desc * src, coroutine_desc * dst);
    8686
     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
    8792//-----------------------------------------------------------------------------
    8893// Utils
  • src/libcfa/concurrency/monitor.c

    rf792cb8 r7416d46a  
    5353static inline __lock_size_t aggregate    ( monitor_desc * storage [], const __waitfor_mask_t & mask );
    5454
    55 #ifndef __CFA_LOCK_NO_YIELD
    56 #define DO_LOCK lock_yield
    57 #else
    58 #define DO_LOCK lock
    59 #endif
    60 
    6155//-----------------------------------------------------------------------------
    6256// Useful defines
     
    9084        static void __enter_monitor_desc( monitor_desc * this, const __monitor_group_t & group ) {
    9185                // Lock the monitor spinlock
    92                 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
     86                lock( this->lock __cfaabi_dbg_ctx2 );
    9387                thread_desc * thrd = this_thread;
     88
     89                verify( disable_preempt_count > 0 );
    9490
    9591                __cfaabi_dbg_print_safe("Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);
     
    121117                        // Some one else has the monitor, wait in line for it
    122118                        append( this->entry_queue, thrd );
     119
     120                        verify( disable_preempt_count > 0 );
     121
    123122                        BlockInternal( &this->lock );
    124123
     
    138137        static void __enter_monitor_dtor( monitor_desc * this, fptr_t func ) {
    139138                // Lock the monitor spinlock
    140                 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
     139                lock( this->lock __cfaabi_dbg_ctx2 );
    141140                thread_desc * thrd = this_thread;
    142141
     
    201200        // Leave single monitor
    202201        void __leave_monitor_desc( monitor_desc * this ) {
    203                 // Lock the monitor spinlock, DO_LOCK to reduce contention
    204                 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
     202                // Lock the monitor spinlock
     203                lock( this->lock __cfaabi_dbg_ctx2 );
    205204
    206205                __cfaabi_dbg_print_safe("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner);
     
    248247
    249248                // Lock the monitor now
    250                 DO_LOCK( this->lock __cfaabi_dbg_ctx2 );
     249                lock( this->lock __cfaabi_dbg_ctx2 );
    251250
    252251                disable_interrupts();
     
    397396        append( this.blocked, &waiter );
    398397
     398        verify( disable_preempt_count == 0 );
     399
    399400        // Lock all monitors (aggregates the locks as well)
    400401        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"); }
    401405
    402406        // Find the next thread(s) to run
     
    473477        monitor_ctx( this.monitors, this.monitor_count );
    474478
     479        verify( disable_preempt_count == 0 );
     480
    475481        // Lock all monitors (aggregates the locks them as well)
    476482        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
    477487
    478488        // Create the node specific to this wait operation
     
    737747static inline void lock_all( __spinlock_t * locks [], __lock_size_t count ) {
    738748        for( __lock_size_t i = 0; i < count; i++ ) {
    739                 DO_LOCK( *locks[i] __cfaabi_dbg_ctx2 );
     749                lock( *locks[i] __cfaabi_dbg_ctx2 );
    740750        }
    741751}
     
    744754        for( __lock_size_t i = 0; i < count; i++ ) {
    745755                __spinlock_t * l = &source[i]->lock;
    746                 DO_LOCK( *l __cfaabi_dbg_ctx2 );
     756                lock( *l __cfaabi_dbg_ctx2 );
    747757                if(locks) locks[i] = l;
    748758        }
  • src/libcfa/concurrency/preemption.c

    rf792cb8 r7416d46a  
    1010// Created On       : Mon Jun 5 14:20:42 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:36:05 2017
    13 // Update Count     : 2
     12// Last Modified On : Tue Jan 23 17:59:30 2018
     13// Update Count     : 7
    1414//
    1515
    1616#include "preemption.h"
    1717
     18#define ftype `ftype`
    1819extern "C" {
    1920#include <errno.h>
    20 #include <execinfo.h>
    21 #define __USE_GNU
    22 #include <signal.h>
    23 #undef __USE_GNU
    2421#include <stdio.h>
    2522#include <string.h>
    2623#include <unistd.h>
    2724}
    28 
    29 
    30 #ifdef __USE_STREAM__
    31 #include "fstream"
    32 #endif
     25#undef ftype
     26
     27#include "bits/signal.h"
    3328
    3429//TODO move to defaults
     
    3934        return __CFA_DEFAULT_PREEMPTION__;
    4035}
    41 
    42 // Short hands for signal context information
    43 #define __CFA_SIGCXT__ ucontext_t *
    44 #define __CFA_SIGPARMS__ __attribute__((unused)) int sig, __attribute__((unused)) siginfo_t *sfp, __attribute__((unused)) __CFA_SIGCXT__ cxt
    4536
    4637// FwdDeclarations : timeout handlers
     
    5344void sigHandler_abort    ( __CFA_SIGPARMS__ );
    5445
    55 // FwdDeclarations : sigaction wrapper
    56 static void __kernel_sigaction( int sig, void (*handler)(__CFA_SIGPARMS__), int flags );
    57 
    5846// FwdDeclarations : alarm thread main
    5947void * alarm_loop( __attribute__((unused)) void * args );
    6048
    6149// Machine specific register name
    62 #ifdef __x86_64__
     50#if   defined(__x86_64__)
    6351#define CFA_REG_IP REG_RIP
    64 #else
     52#elif defined(__i386__)
    6553#define CFA_REG_IP REG_EIP
     54#elif defined(__ARM_ARCH__)
     55#define CFA_REG_IP REG_R15
    6656#endif
    6757
     
    179169        void enable_interrupts_noPoll() {
    180170                __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 interrupts
     171                verifyf( prev != 0u, "Incremented from %u\n", prev );                     // If this triggers someone is enabled already enabled interrupts
    182172        }
    183173}
     
    243233        // Setup proper signal handlers
    244234        __kernel_sigaction( SIGUSR1, sigHandler_ctxSwitch, SA_SIGINFO | SA_RESTART );         // CtxSwitch handler
    245         // __kernel_sigaction( SIGSEGV, sigHandler_segv     , SA_SIGINFO );      // Failure handler
    246         // __kernel_sigaction( SIGBUS , sigHandler_segv     , SA_SIGINFO );      // Failure handler
    247235
    248236        signal_block( SIGALRM );
     
    296284// Receives SIGUSR1 signal and causes the current thread to yield
    297285void sigHandler_ctxSwitch( __CFA_SIGPARMS__ ) {
     286#if defined( __ARM_ARCH )
     287        __cfaabi_dbg_debug_do( last_interrupt = (void *)(cxt->uc_mcontext.arm_pc); )
     288#else
    298289        __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
    301293        if( !preemption_ready() ) { return; }
     294
     295        __cfaabi_dbg_print_buffer_decl(" KERNEL: preempting core %p (%p).\n", this_processor, this_thread);
    302296
    303297        preemption_in_progress = true;                      // Sync flag : prevent recursive calls to the signal handler
     
    371365}
    372366
    373 // Sigaction wrapper : register an signal handler
    374 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 handler
    390 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 logic
    408 //=============================================================================================
    409 
    410 __cfaabi_dbg_debug_do(
    411         static void __kernel_backtrace( int start ) {
    412                 // skip first N stack frames
    413 
    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 name
    420                 *index( messages[0], '(' ) = '\0';
    421                 #ifdef __USE_STREAM__
    422                 serr | "Stack back trace for:" | messages[0] | endl;
    423                 #else
    424                 fprintf( stderr, "Stack back trace for: %s\n", messages[0]);
    425                 #endif
    426 
    427                 // skip last 2 stack frames after main
    428                 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 +offset
    435                                 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 it
    448                         int frameNo = i - start;
    449                         if ( name && offset_begin && offset_end && name < offset_begin ) {
    450                                 // delimit strings
    451                                 *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                                 #else
    459                                 fprintf( stderr, "(%i) %s : %s + %s %s\n", frameNo, messages[i], name, offset_begin, offset_end);
    460                                 #endif
    461                         }
    462                         // otherwise, print the whole line
    463                         else {
    464                                 #ifdef __USE_STREAM__
    465                                 serr | "(" | frameNo | ")" | messages[i] | endl;
    466                                 #else
    467                                 fprintf( stderr, "(%i) %s\n", frameNo, messages[i] );
    468                                 #endif
    469                         }
    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 //              #else
    483 //              fprintf( stderr, "*CFA runtime error* program cfa-cpp terminated with %s\n", sig == SIGSEGV ? "segment fault." : "bus error." );
    484 //              #endif
    485 
    486 //              // skip first 2 stack frames
    487 //              __kernel_backtrace( 1 );
    488 //      )
    489 //      exit( EXIT_FAILURE );
    490 // }
    491 
    492 // void sigHandler_abort( __CFA_SIGPARMS__ ) {
    493 //      // skip first 6 stack frames
    494 //      __cfaabi_dbg_debug_do( __kernel_backtrace( 6 ); )
    495 
    496 //      // reset default signal handler
    497 //      __kernel_sigdefault( SIGABRT );
    498 
    499 //      raise( SIGABRT );
    500 // }
    501 
    502367// Local Variables: //
    503368// mode: c //
  • src/libcfa/concurrency/thread.c

    rf792cb8 r7416d46a  
    3838        self_mon_p = &self_mon;
    3939        next = NULL;
     40        __cfaabi_dbg_debug_do(
     41                dbg_next = NULL;
     42                dbg_prev = NULL;
     43                __cfaabi_dbg_thread_register(&this);
     44        )
    4045
    4146        monitors{ &self_mon_p, 1, (fptr_t)0 };
  • src/libcfa/interpose.c

    rf792cb8 r7416d46a  
    2222#include <dlfcn.h>
    2323#include <unistd.h>
     24#define __USE_GNU
     25#include <signal.h>
     26#undef __USE_GNU
     27#include <execinfo.h>
    2428}
    2529
    2630#include "bits/debug.h"
    2731#include "bits/defs.h"
     32#include "bits/signal.h"
    2833#include "startup.h"
    2934
    30 void interpose_startup(void)  __attribute__(( constructor( STARTUP_PRIORITY_CORE ) ));
     35void __cfaabi_interpose_startup(void)  __attribute__(( constructor( STARTUP_PRIORITY_CORE ) ));
    3136
    3237typedef void (*generic_fptr_t)(void);
     
    8489#define INIT_REALRTN( x, ver ) assign_ptr( (void**)&libc_##x, #x, ver)
    8590
    86 void interpose_startup() {
     91void sigHandler_segv ( __CFA_SIGPARMS__ );
     92void sigHandler_abort( __CFA_SIGPARMS__ );
     93
     94void __cfaabi_interpose_startup() {
    8795        const char *version = NULL;
    8896
    8997        INIT_REALRTN( abort, version );
    9098        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//=============================================================================================
    92108
    93109extern "C" {
     
    137153                libc_abort();
    138154        }
     155}
     156
     157// skip first 6 stack frames by default
     158static 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
     210void 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
     215void sigHandler_abort( __CFA_SIGPARMS__ ) {
     216        __kernel_backtrace();
     217
     218        // reset default signal handler
     219        __kernel_sigdefault( SIGABRT );
     220
     221        raise( SIGABRT );
    139222}
    140223
  • src/libcfa/iostream

    rf792cb8 r7416d46a  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Dec 21 13:55:41 2017
    13 // Update Count     : 145
     12// Last Modified On : Thu Jan 25 13:08:39 2018
     13// Update Count     : 149
    1414//
    1515
     
    124124}; // readable
    125125
     126forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, _Bool & );
     127
    126128forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, char & );
    127129forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, signed char & );
     
    145147forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, long double _Complex & );
    146148
     149// manipulators
     150forall( dtype istype | istream( istype ) ) istype & ?|?( istype &, istype & (*)( istype & ) );
     151forall( dtype istype | istream( istype ) ) istype & endl( istype & is );
     152
    147153struct _Istream_cstrUC { char * s; };
    148154_Istream_cstrUC cstr( char * );
  • src/libcfa/iostream.c

    rf792cb8 r7416d46a  
    1010// Created On       : Wed May 27 17:56:53 2015
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Dec 21 13:55:09 2017
    13 // Update Count     : 427
     12// Last Modified On : Thu Jan 25 13:09:28 2018
     13// Update Count     : 467
    1414//
    1515
     
    1919#include <stdio.h>
    2020#include <stdbool.h>                                                                    // true/false
    21 #include <string.h>                                                                             // strlen
     21//#include <string.h>                                                                           // strlen, strcmp
     22extern int strcmp (const char *__s1, const char *__s2) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1, 2)));
     23extern size_t strlen (const char *__s) __attribute__ ((__nothrow__ , __leaf__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
    2224#include <float.h>                                                                              // DBL_DIG, LDBL_DIG
    2325#include <complex.h>                                                                    // creal, cimag
     
    301303
    302304forall( dtype istype | istream( istype ) )
     305istype & ?|?( 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
     317forall( dtype istype | istream( istype ) )
    303318istype & ?|?( istype & is, char & c ) {
    304319        fmt( is, "%c", &c );                                                            // must pass pointer through varg to fmt
     
    410425} // ?|?
    411426
     427forall( dtype istype | istream( istype ) )
     428istype & ?|?( istype & is, istype & (* manip)( istype & ) ) {
     429        return manip( is );
     430} // ?|?
     431
     432forall( dtype istype | istream( istype ) )
     433istype & endl( istype & is ) {
     434        fmt( is, "%*[ \t\f\n\r\v]" );                                           // ignore whitespace
     435        return is;
     436} // endl
     437
    412438_Istream_cstrUC cstr( char * str ) { return (_Istream_cstrUC){ str }; }
    413439forall( dtype istype | istream( istype ) )
  • src/libcfa/stdlib.c

    rf792cb8 r7416d46a  
    55// file "LICENCE" distributed with Cforall.
    66//
    7 // algorithm.c --
     7// stdlib.c --
    88//
    99// Author           : Peter A. Buhr
    1010// Created On       : Thu Jan 28 17:10:29 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jan  2 12:20:32 2018
    13 // Update Count     : 441
     12// Last Modified On : Wed Jan  3 08:29:29 2018
     13// Update Count     : 444
    1414//
    1515
     
    2424#include <complex.h>                                                                    // _Complex_I
    2525#include <assert.h>
     26
     27//---------------------------------------
    2628
    2729// resize, non-array types
     
    257259//---------------------------------------
    258260
    259 extern "C" { void srandom( unsigned int seed ) { srand48( seed ); } } // override C version
     261extern "C" { void srandom( unsigned int seed ) { srand48( (long int)seed ); } } // override C version
    260262char random( void ) { return (unsigned long int)random(); }
    261263char random( char u ) { return random( (unsigned long int)u ); }
Note: See TracChangeset for help on using the changeset viewer.