Changeset d56ca354 for src/libcfa


Ignore:
Timestamp:
Feb 12, 2018, 11:57:55 AM (6 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:
fd062a66
Parents:
c40e7c5 (diff), cfe2f0a (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:
1 added
12 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/Makefile.am

    rc40e7c5 rd56ca354  
    1010## Author           : Peter A. Buhr
    1111## Created On       : Sun May 31 08:54:01 2015
    12 ## Last Modified By : Andrew Beach
    13 ## Last Modified On : Wed Jul 26 14:15:00 2017
    14 ## Update Count     : 221
     12## Last Modified By : Peter A. Buhr
     13## Last Modified On : Fri Feb  9 15:51:24 2018
     14## Update Count     : 223
    1515###############################################################################
    1616
     
    9292libcfa_d_a_CFLAGS = -debug -O0 #No need for __CFA_DEBUG__ since we pass -debug
    9393
    94 stdhdr = ${shell echo stdhdr/*}
     94stdhdr = ${shell find stdhdr -type f -printf "%p "}
    9595
    9696cfa_includedir = $(CFA_INCDIR)
  • src/libcfa/bits/debug.c

    rc40e7c5 rd56ca354  
    1111// Last Modified By :
    1212// Last Modified On :
    13 // Update Count     : 0
     13// Update Count     : 1
    1414//
    1515
     
    4747        void __cfaabi_dbg_bits_release() __attribute__((__weak__)) {}
    4848
    49         void __cfaabi_dbg_bits_print_safe  ( const char fmt[], ... ) __attribute__(( format (printf, 1, 2) )) {
     49        void __cfaabi_dbg_bits_print_safe  ( const char fmt[], ... ) __attribute__(( format(printf, 1, 2) )) {
    5050                va_list args;
    5151
     
    6060        }
    6161
    62         void __cfaabi_dbg_bits_print_nolock( const char fmt[], ... ) __attribute__(( format (printf, 1, 2) )) {
     62        void __cfaabi_dbg_bits_print_nolock( const char fmt[], ... ) __attribute__(( format(printf, 1, 2) )) {
    6363                va_list args;
    6464
     
    7676        }
    7777
    78         void __cfaabi_dbg_bits_print_buffer( char in_buffer[], int in_buffer_size, const char fmt[], ... ) __attribute__(( format (printf, 3, 4) )) {
     78        void __cfaabi_dbg_bits_print_buffer( char in_buffer[], int in_buffer_size, const char fmt[], ... ) __attribute__(( format(printf, 3, 4) )) {
    7979                va_list args;
    8080
  • src/libcfa/bits/debug.h

    rc40e7c5 rd56ca354  
    1010// Created On       : Mon Nov 28 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Sat Jul 22 10:02:24 2017
    13 // Update Count     : 1
     12// Last Modified On : Thu Feb  8 12:35:19 2018
     13// Update Count     : 2
    1414//
    1515
     
    4141      extern void __cfaabi_dbg_bits_acquire();
    4242      extern void __cfaabi_dbg_bits_release();
    43       extern void __cfaabi_dbg_bits_print_safe  ( const char fmt[], ... ) __attribute__(( format (printf, 1, 2) ));
    44       extern void __cfaabi_dbg_bits_print_nolock( const char fmt[], ... ) __attribute__(( format (printf, 1, 2) ));
     43      extern void __cfaabi_dbg_bits_print_safe  ( const char fmt[], ... ) __attribute__(( format(printf, 1, 2) ));
     44      extern void __cfaabi_dbg_bits_print_nolock( const char fmt[], ... ) __attribute__(( format(printf, 1, 2) ));
    4545      extern void __cfaabi_dbg_bits_print_vararg( const char fmt[], va_list arg );
    46       extern void __cfaabi_dbg_bits_print_buffer( char buffer[], int buffer_size, const char fmt[], ... ) __attribute__(( format (printf, 3, 4) ));
     46      extern void __cfaabi_dbg_bits_print_buffer( char buffer[], int buffer_size, const char fmt[], ... ) __attribute__(( format(printf, 3, 4) ));
    4747#ifdef __cforall
    4848}
  • src/libcfa/bits/defs.h

    rc40e7c5 rd56ca354  
    1010// Created On       : Thu Nov  9 13:24:10 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jan  2 09:17:06 2018
    13 // Update Count     : 2
     12// Last Modified On : Thu Feb  8 16:22:41 2018
     13// Update Count     : 8
    1414//
    1515
     
    3434
    3535#ifdef __cforall
    36 #ifndef __NO_ABORT_OVERLOAD
    37 void abort ( const char fmt[], ... ) __attribute__ ((__nothrow__, __leaf__, __noreturn__));
    38 #endif
     36void abort ( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
    3937extern "C" {
    4038#endif
    41 void abortf( const char fmt[], ... ) __attribute__ ((__nothrow__, __leaf__, __noreturn__));
     39void __cabi_abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
    4240#ifdef __cforall
    4341}
  • src/libcfa/concurrency/coroutine.c

    rc40e7c5 rd56ca354  
    1010// Created On       : Mon Nov 28 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Fri Jul 21 22:34:57 2017
    13 // Update Count     : 1
     12// Last Modified On : Thu Feb  8 16:10:31 2018
     13// Update Count     : 4
    1414//
    1515
     
    7777                __cfaabi_dbg_debug_do(
    7878                        if ( mprotect( this.storage, pageSize, PROT_READ | PROT_WRITE ) == -1 ) {
    79                                 abortf( "(coStack_t *)%p.^?{}() : internal error, mprotect failure, error(%d) %s.", &this, errno, strerror( errno ) );
     79                                abort( "(coStack_t *)%p.^?{}() : internal error, mprotect failure, error(%d) %s.", &this, errno, strerror( errno ) );
    8080                        }
    8181                );
     
    9999// Wrapper for co
    100100void CoroutineCtxSwitch(coroutine_desc* src, coroutine_desc* dst) {
    101         // THREAD_GETMEM( This )->disableInterrupts();
     101        disable_interrupts();
    102102
    103103        // set state of current coroutine to inactive
     
    115115        src->state = Active;
    116116
    117         // THREAD_GETMEM( This )->enableInterrupts();
     117        enable_interrupts( __cfaabi_dbg_ctx );
    118118} //ctxSwitchDirect
    119119
     
    135135                __cfaabi_dbg_debug_do(
    136136                        if ( mprotect( storage, pageSize, PROT_NONE ) == -1 ) {
    137                                 abortf( "(uMachContext &)%p.createContext() : internal error, mprotect failure, error(%d) %s.", this, (int)errno, strerror( (int)errno ) );
     137                                abort( "(uMachContext &)%p.createContext() : internal error, mprotect failure, error(%d) %s.", this, (int)errno, strerror( (int)errno ) );
    138138                        } // if
    139139                );
    140140
    141141                if ( (intptr_t)storage == 0 ) {
    142                         abortf( "Attempt to allocate %d bytes of storage for coroutine or task execution-state but insufficient memory available.", size );
     142                        abort( "Attempt to allocate %zd bytes of storage for coroutine or task execution-state but insufficient memory available.", size );
    143143                } // if
    144144
  • src/libcfa/concurrency/invoke.c

    rc40e7c5 rd56ca354  
    1010// Created On       : Tue Jan 17 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb  6 23:00:57 2018
    13 // Update Count     : 3
     12// Last Modified On : Fri Feb  9 16:37:42 2018
     13// Update Count     : 5
    1414//
    1515
     
    5151        //Final suspend, should never return
    5252        __leave_coroutine();
    53         abortf( "Resumed dead coroutine" );
     53        __cabi_abort( "Resumed dead coroutine" );
    5454}
    5555
     
    8181        //Final suspend, should never return
    8282        __leave_thread_monitor( thrd );
    83         abortf( "Resumed dead thread" );
     83        __cabi_abort( "Resumed dead thread" );
    8484}
    8585
     
    9393        struct coStack_t* stack = &get_coroutine( this )->stack;
    9494
    95 #if defined( __i386__ )
     95#if defined( __i386 )
    9696
    9797        struct FakeStack {
     
    114114        ((struct FakeStack *)(((struct machine_context_t *)stack->context)->SP))->fcw = 0x037F;  //Vol. 1 8-7
    115115
    116 #elif defined( __x86_64__ )
     116#elif defined( __x86_64 )
    117117
    118118        struct FakeStack {
     
    150150        fs->arg[0] = this;
    151151        fs->arg[1] = invoke;
     152
    152153#else
    153         #error Only __i386__ and __x86_64__ is supported for threads in cfa
     154        #error uknown hardware architecture
    154155#endif
    155156}
  • src/libcfa/concurrency/invoke.h

    rc40e7c5 rd56ca354  
    1010// Created On       : Tue Jan 17 12:27:26 2016
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Jan 23 14:55:46 2018
    13 // Update Count     : 3
     12// Last Modified On : Fri Feb  9 14:41:55 2018
     13// Update Count     : 6
    1414//
    1515
     
    202202        void CtxSwitch( void * from, void * to ) asm ("CtxSwitch");
    203203
    204         #if   defined( __x86_64__ )
     204        #if   defined( __i386 )
     205        #define CtxGet( ctx ) __asm__ ( \
     206                        "movl %%esp,%0\n"   \
     207                        "movl %%ebp,%1\n"   \
     208                : "=rm" (ctx.SP), "=rm" (ctx.FP) )
     209        #elif defined( __x86_64 )
    205210        #define CtxGet( ctx ) __asm__ ( \
    206211                        "movq %%rsp,%0\n"   \
    207212                        "movq %%rbp,%1\n"   \
    208                 : "=rm" (ctx.SP), "=rm" (ctx.FP) )
    209         #elif defined( __i386__ )
    210         #define CtxGet( ctx ) __asm__ ( \
    211                         "movl %%esp,%0\n"   \
    212                         "movl %%ebp,%1\n"   \
    213213                : "=rm" (ctx.SP), "=rm" (ctx.FP) )
    214214        #elif defined( __ARM_ARCH )
     
    217217                        "mov %1,%%r11\n"   \
    218218                : "=rm" (ctx.SP), "=rm" (ctx.FP) )
     219        #else
     220                #error unknown hardware architecture
    219221        #endif
    220222
  • src/libcfa/concurrency/kernel.c

    rc40e7c5 rd56ca354  
    1010// Created On       : Tue Jan 17 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb  6 21:51:26 2018
    13 // Update Count     : 4
     12// Last Modified On : Thu Feb  8 23:52:19 2018
     13// Update Count     : 5
    1414//
    1515
    1616//C Includes
    1717#include <stddef.h>
    18 #define ftype `ftype`
    1918extern "C" {
    2019#include <stdio.h>
     
    2423#include <unistd.h>
    2524}
    26 #undef ftype
    2725
    2826//CFA Includes
  • src/libcfa/concurrency/monitor.c

    rc40e7c5 rd56ca354  
    1010// Created On       : Thd Feb 23 12:27:26 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Mon Jul 31 14:59:05 2017
    13 // Update Count     : 3
     12// Last Modified On : Thu Feb  8 16:12:20 2018
     13// Update Count     : 4
    1414//
    1515
     
    8787                thread_desc * thrd = this_thread;
    8888
    89                 __cfaabi_dbg_print_safe("Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);
     89                __cfaabi_dbg_print_safe( "Kernel : %10p Entering mon %p (%p)\n", thrd, this, this->owner);
    9090
    9191                if( !this->owner ) {
     
    9393                        set_owner( this, thrd );
    9494
    95                         __cfaabi_dbg_print_safe("Kernel :  mon is free \n");
     95                        __cfaabi_dbg_print_safe( "Kernel :  mon is free \n" );
    9696                }
    9797                else if( this->owner == thrd) {
     
    9999                        this->recursion += 1;
    100100
    101                         __cfaabi_dbg_print_safe("Kernel :  mon already owned \n");
     101                        __cfaabi_dbg_print_safe( "Kernel :  mon already owned \n" );
    102102                }
    103103                else if( is_accepted( this, group) ) {
     
    108108                        reset_mask( this );
    109109
    110                         __cfaabi_dbg_print_safe("Kernel :  mon accepts \n");
     110                        __cfaabi_dbg_print_safe( "Kernel :  mon accepts \n" );
    111111                }
    112112                else {
    113                         __cfaabi_dbg_print_safe("Kernel :  blocking \n");
     113                        __cfaabi_dbg_print_safe( "Kernel :  blocking \n" );
    114114
    115115                        // Some one else has the monitor, wait in line for it
     
    118118                        BlockInternal( &this->lock );
    119119
    120                         __cfaabi_dbg_print_safe("Kernel : %10p Entered  mon %p\n", thrd, this);
     120                        __cfaabi_dbg_print_safe( "Kernel : %10p Entered  mon %p\n", thrd, this);
    121121
    122122                        // BlockInternal will unlock spinlock, no need to unlock ourselves
     
    124124                }
    125125
    126                 __cfaabi_dbg_print_safe("Kernel : %10p Entered  mon %p\n", thrd, this);
     126                __cfaabi_dbg_print_safe( "Kernel : %10p Entered  mon %p\n", thrd, this);
    127127
    128128                // Release the lock and leave
     
    136136                thread_desc * thrd = this_thread;
    137137
    138                 __cfaabi_dbg_print_safe("Kernel : %10p Entering dtor for mon %p (%p)\n", thrd, this, this->owner);
     138                __cfaabi_dbg_print_safe( "Kernel : %10p Entering dtor for mon %p (%p)\n", thrd, this, this->owner);
    139139
    140140
    141141                if( !this->owner ) {
    142                         __cfaabi_dbg_print_safe("Kernel : Destroying free mon %p\n", this);
     142                        __cfaabi_dbg_print_safe( "Kernel : Destroying free mon %p\n", this);
    143143
    144144                        // No one has the monitor, just take it
     
    151151                        // We already have the monitor... but where about to destroy it so the nesting will fail
    152152                        // Abort!
    153                         abortf("Attempt to destroy monitor %p by thread \"%.256s\" (%p) in nested mutex.");
     153                        abort( "Attempt to destroy monitor %p by thread \"%.256s\" (%p) in nested mutex." );
    154154                }
    155155
     
    158158                __monitor_group_t group = { &this, 1, func };
    159159                if( is_accepted( this, group) ) {
    160                         __cfaabi_dbg_print_safe("Kernel :  mon accepts dtor, block and signal it \n");
     160                        __cfaabi_dbg_print_safe( "Kernel :  mon accepts dtor, block and signal it \n" );
    161161
    162162                        // Wake the thread that is waiting for this
     
    177177                }
    178178                else {
    179                         __cfaabi_dbg_print_safe("Kernel :  blocking \n");
     179                        __cfaabi_dbg_print_safe( "Kernel :  blocking \n" );
    180180
    181181                        wait_ctx( this_thread, 0 )
     
    190190                }
    191191
    192                 __cfaabi_dbg_print_safe("Kernel : Destroying %p\n", this);
     192                __cfaabi_dbg_print_safe( "Kernel : Destroying %p\n", this);
    193193
    194194        }
     
    199199                lock( this->lock __cfaabi_dbg_ctx2 );
    200200
    201                 __cfaabi_dbg_print_safe("Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner);
     201                __cfaabi_dbg_print_safe( "Kernel : %10p Leaving mon %p (%p)\n", this_thread, this, this->owner);
    202202
    203203                verifyf( this_thread == this->owner, "Expected owner to be %p, got %p (r: %i, m: %p)", this_thread, this->owner, this->recursion, this );
     
    209209                // it means we don't need to do anything
    210210                if( this->recursion != 0) {
    211                         __cfaabi_dbg_print_safe("Kernel :  recursion still %d\n", this->recursion);
     211                        __cfaabi_dbg_print_safe( "Kernel :  recursion still %d\n", this->recursion);
    212212                        unlock( this->lock );
    213213                        return;
     
    228228                __cfaabi_dbg_debug_do(
    229229                        if( this_thread != this->owner ) {
    230                                 abortf("Destroyed monitor %p has inconsistent owner, expected %p got %p.\n", this, this_thread, this->owner);
     230                                abort( "Destroyed monitor %p has inconsistent owner, expected %p got %p.\n", this, this_thread, this->owner);
    231231                        }
    232232                        if( this->recursion != 1 ) {
    233                                 abortf("Destroyed monitor %p has %d outstanding nested calls.\n", this, this->recursion - 1);
     233                                abort( "Destroyed monitor %p has %d outstanding nested calls.\n", this, this->recursion - 1);
    234234                        }
    235235                )
     
    256256                // If we haven't left the last level of recursion
    257257                // it must mean there is an error
    258                 if( this->recursion != 0) { abortf("Thread internal monitor has unbalanced recursion"); }
     258                if( this->recursion != 0) { abort( "Thread internal monitor has unbalanced recursion" ); }
    259259
    260260                // Fetch the next thread, can be null
     
    302302        (this_thread->monitors){m, count, func};
    303303
    304         // __cfaabi_dbg_print_safe("MGUARD : enter %d\n", count);
     304        // __cfaabi_dbg_print_safe( "MGUARD : enter %d\n", count);
    305305
    306306        // Enter the monitors in order
     
    308308        enter( group );
    309309
    310         // __cfaabi_dbg_print_safe("MGUARD : entered\n");
     310        // __cfaabi_dbg_print_safe( "MGUARD : entered\n" );
    311311}
    312312
     
    314314// Dtor for monitor guard
    315315void ^?{}( monitor_guard_t & this ) {
    316         // __cfaabi_dbg_print_safe("MGUARD : leaving %d\n", this.count);
     316        // __cfaabi_dbg_print_safe( "MGUARD : leaving %d\n", this.count);
    317317
    318318        // Leave the monitors in order
    319319        leave( this.m, this.count );
    320320
    321         // __cfaabi_dbg_print_safe("MGUARD : left\n");
     321        // __cfaabi_dbg_print_safe( "MGUARD : left\n" );
    322322
    323323        // Restore thread context
     
    427427                thread_desc * this_thrd = this_thread;
    428428                if ( this.monitor_count != this_thrd->monitors.size ) {
    429                         abortf( "Signal on condition %p made with different number of monitor(s), expected %i got %i", &this, this.monitor_count, this_thrd->monitors.size );
     429                        abort( "Signal on condition %p made with different number of monitor(s), expected %i got %i", &this, this.monitor_count, this_thrd->monitors.size );
    430430                }
    431431
    432432                for(int i = 0; i < this.monitor_count; i++) {
    433433                        if ( this.monitors[i] != this_thrd->monitors[i] ) {
    434                                 abortf( "Signal on condition %p made with different monitor, expected %p got %i", &this, this.monitors[i], this_thrd->monitors[i] );
     434                                abort( "Signal on condition %p made with different monitor, expected %p got %i", &this, this.monitors[i], this_thrd->monitors[i] );
    435435                        }
    436436                }
     
    534534        if(actual_count == 0) return;
    535535
    536         __cfaabi_dbg_print_buffer_local( "Kernel : waitfor internal proceeding\n");
     536        __cfaabi_dbg_print_buffer_local( "Kernel : waitfor internal proceeding\n" );
    537537
    538538        // Create storage for monitor context
     
    551551                        __acceptable_t& accepted = mask[index];
    552552                        if( accepted.is_dtor ) {
    553                                 __cfaabi_dbg_print_buffer_local( "Kernel : dtor already there\n");
     553                                __cfaabi_dbg_print_buffer_local( "Kernel : dtor already there\n" );
    554554                                verifyf( accepted.size == 1,  "ERROR: Accepted dtor has more than 1 mutex parameter." );
    555555
     
    563563                        }
    564564                        else {
    565                                 __cfaabi_dbg_print_buffer_local( "Kernel : thread present, baton-passing\n");
     565                                __cfaabi_dbg_print_buffer_local( "Kernel : thread present, baton-passing\n" );
    566566
    567567                                // Create the node specific to this wait operation
     
    577577                                        }
    578578                                #endif
    579                                 __cfaabi_dbg_print_buffer_local( "\n");
     579                                __cfaabi_dbg_print_buffer_local( "\n" );
    580580
    581581                                // Set the owners to be the next thread
     
    588588                                monitor_restore;
    589589
    590                                 __cfaabi_dbg_print_buffer_local( "Kernel : thread present, returned\n");
     590                                __cfaabi_dbg_print_buffer_local( "Kernel : thread present, returned\n" );
    591591                        }
    592592
     
    598598
    599599        if( duration == 0 ) {
    600                 __cfaabi_dbg_print_buffer_local( "Kernel : non-blocking, exiting\n");
     600                __cfaabi_dbg_print_buffer_local( "Kernel : non-blocking, exiting\n" );
    601601
    602602                unlock_all( locks, count );
     
    607607
    608608
    609         verifyf( duration < 0, "Timeout on waitfor statments not supported yet.");
    610 
    611         __cfaabi_dbg_print_buffer_local( "Kernel : blocking waitfor\n");
     609        verifyf( duration < 0, "Timeout on waitfor statments not supported yet." );
     610
     611        __cfaabi_dbg_print_buffer_local( "Kernel : blocking waitfor\n" );
    612612
    613613        // Create the node specific to this wait operation
     
    631631        monitor_restore;
    632632
    633         __cfaabi_dbg_print_buffer_local( "Kernel : exiting\n");
     633        __cfaabi_dbg_print_buffer_local( "Kernel : exiting\n" );
    634634
    635635        __cfaabi_dbg_print_buffer_local( "Kernel : accepted %d\n", *mask.accepted);
     
    640640
    641641static inline void set_owner( monitor_desc * this, thread_desc * owner ) {
    642         // __cfaabi_dbg_print_safe("Kernal :   Setting owner of %p to %p ( was %p)\n", this, owner, this->owner );
     642        // __cfaabi_dbg_print_safe( "Kernal :   Setting owner of %p to %p ( was %p)\n", this, owner, this->owner );
    643643
    644644        //Pass the monitor appropriately
     
    672672static inline thread_desc * next_thread( monitor_desc * this ) {
    673673        //Check the signaller stack
    674         __cfaabi_dbg_print_safe("Kernel :  mon %p AS-stack top %p\n", this, this->signal_stack.top);
     674        __cfaabi_dbg_print_safe( "Kernel :  mon %p AS-stack top %p\n", this, this->signal_stack.top);
    675675        __condition_criterion_t * urgent = pop( this->signal_stack );
    676676        if( urgent ) {
     
    814814        thread_desc * thrd = this_thread;
    815815        if( !this.monitors ) {
    816                 // __cfaabi_dbg_print_safe("Branding\n");
     816                // __cfaabi_dbg_print_safe( "Branding\n" );
    817817                assertf( thrd->monitors.data != NULL, "No current monitor to brand condition %p", thrd->monitors.data );
    818818                this.monitor_count = thrd->monitors.size;
  • src/libcfa/concurrency/preemption.c

    rc40e7c5 rd56ca354  
    1010// Created On       : Mon Jun 5 14:20:42 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb  6 15:00:36 2018
    13 // Update Count     : 10
     12// Last Modified On : Fri Feb  9 16:38:13 2018
     13// Update Count     : 14
    1414//
    1515
    1616#include "preemption.h"
    1717
    18 #define ftype `ftype`
    1918extern "C" {
    2019#include <errno.h>
     
    2322#include <unistd.h>
    2423}
    25 #undef ftype
    2624
    2725#include "bits/signal.h"
     
    5048
    5149// Machine specific register name
    52 #if   defined(__x86_64__)
     50#if   defined( __i386 )
     51#define CFA_REG_IP gregs[REG_EIP]
     52#elif defined( __x86_64 )
    5353#define CFA_REG_IP gregs[REG_RIP]
    54 #elif defined(__i386__)
    55 #define CFA_REG_IP gregs[REG_EIP]
    56 #elif defined(__ARM_ARCH__)
     54#elif defined( __ARM_ARCH )
    5755#define CFA_REG_IP arm_pc
     56#else
     57#error unknown hardware architecture
    5858#endif
    5959
     
    197197
    198198        if ( pthread_sigmask( SIG_UNBLOCK, &mask, NULL ) == -1 ) {
    199             abortf( "internal error, pthread_sigmask" );
     199            abort( "internal error, pthread_sigmask" );
    200200        }
    201201}
     
    208208
    209209        if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) {
    210             abortf( "internal error, pthread_sigmask" );
     210            abort( "internal error, pthread_sigmask" );
    211211        }
    212212}
     
    247247// Called from kernel_startup
    248248void kernel_start_preemption() {
    249         __cfaabi_dbg_print_safe("Kernel : Starting preemption\n");
     249        __cfaabi_dbg_print_safe( "Kernel : Starting preemption\n" );
    250250
    251251        // Start with preemption disabled until ready
     
    268268// Called from kernel_shutdown
    269269void kernel_stop_preemption() {
    270         __cfaabi_dbg_print_safe("Kernel : Preemption stopping\n");
     270        __cfaabi_dbg_print_safe( "Kernel : Preemption stopping\n" );
    271271
    272272        // Block all signals since we are already shutting down
     
    284284        // Preemption is now fully stopped
    285285
    286         __cfaabi_dbg_print_safe("Kernel : Preemption stopped\n");
     286        __cfaabi_dbg_print_safe( "Kernel : Preemption stopped\n" );
    287287}
    288288
     
    322322                case PREEMPT_TERMINATE: verify(this_processor->do_terminate);
    323323                default:
    324                         abortf( "internal error, signal value is %d", sfp->si_value.sival_int );
     324                        abort( "internal error, signal value is %d", sfp->si_value.sival_int );
    325325        }
    326326
     
    328328        if( !preemption_ready() ) { return; }
    329329
    330         __cfaabi_dbg_print_buffer_decl(" KERNEL: preempting core %p (%p).\n", this_processor, this_thread);
     330        __cfaabi_dbg_print_buffer_decl( " KERNEL: preempting core %p (%p).\n", this_processor, this_thread);
    331331
    332332        preemption_in_progress = true;                      // Sync flag : prevent recursive calls to the signal handler
     
    348348
    349349        if ( pthread_sigmask( SIG_BLOCK, &mask, NULL ) == -1 ) {
    350             abortf( "internal error, pthread_sigmask" );
     350            abort( "internal error, pthread_sigmask" );
    351351        }
    352352
     
    365365                                        continue;
    366366                        case EINVAL :
    367                                         abortf("Timeout was invalid.");
     367                                        abort( "Timeout was invalid." );
    368368                                default:
    369                                         abortf("Unhandled error %d", err);
     369                                        abort( "Unhandled error %d", err);
    370370                        }
    371371                }
     
    374374                assertf(sig == SIGALRM, "Kernel Internal Error, sigwait: Unexpected signal %d (%d : %d)\n", sig, info.si_code, info.si_value.sival_int);
    375375
    376                 // __cfaabi_dbg_print_safe("Kernel : Caught alarm from %d with %d\n", info.si_code, info.si_value.sival_int );
     376                // __cfaabi_dbg_print_safe( "Kernel : Caught alarm from %d with %d\n", info.si_code, info.si_value.sival_int );
    377377                // Switch on the code (a.k.a. the sender) to
    378378                switch( info.si_code )
     
    382382                case SI_TIMER:
    383383                case SI_KERNEL:
    384                         // __cfaabi_dbg_print_safe("Kernel : Preemption thread tick\n");
     384                        // __cfaabi_dbg_print_safe( "Kernel : Preemption thread tick\n" );
    385385                        lock( event_kernel->lock __cfaabi_dbg_ctx2 );
    386386                        tick_preemption();
     
    396396
    397397EXIT:
    398         __cfaabi_dbg_print_safe("Kernel : Preemption thread stopping\n");
     398        __cfaabi_dbg_print_safe( "Kernel : Preemption thread stopping\n" );
    399399        return NULL;
    400400}
  • src/libcfa/exception.c

    rc40e7c5 rd56ca354  
    99// Author           : Andrew Beach
    1010// Created On       : Mon Jun 26 15:13:00 2017
    11 // Last Modified By : Andrew Beach
    12 // Last Modified On : Thr Aug 17 15:45:00 2017
    13 // Update Count     : 7
     11// Last Modified By : Peter A. Buhr
     12// Last Modified On : Fri Feb  9 14:41:55 2018
     13// Update Count     : 8
    1414//
    1515
     
    453453// match, which is no way generic.  Some more works need to be done if we want to have a single call to the try routine.
    454454
    455 #if defined( __x86_64__ ) || defined( __i386__ )
     455#if defined( __i386 ) || defined( __x86_64 )
    456456asm (
    457457        //HEADER
     
    476476//      "       .section        .note.GNU-stack,\"x\",@progbits\n"
    477477);
    478 #endif // __x86_64__ || __i386__
     478#endif // __i386 || __x86_64
  • src/libcfa/interpose.c

    rc40e7c5 rd56ca354  
    1010// Created On       : Wed Mar 29 16:10:31 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Feb  7 09:05:18 2018
    13 // Update Count     : 59
     12// Last Modified On : Thu Feb  8 16:18:09 2018
     13// Update Count     : 75
    1414//
    1515
     
    2828}
    2929
    30 #define __NO_ABORT_OVERLOAD // no abort overload avoid ambiguities
    3130#include "bits/debug.h"
    3231#include "bits/defs.h"
     
    5150                        error = dlerror();
    5251                        if ( error ) {
    53                                 abortf( "interpose_symbol : failed to open libc, %s\n", error );
     52                                abort( "interpose_symbol : failed to open libc, %s\n", error );
    5453                        }
    5554                #endif
     
    6968
    7069        error = dlerror();
    71         if ( error ) abortf( "interpose_symbol : internal error, %s\n", error );
     70        if ( error ) abort( "interpose_symbol : internal error, %s\n", error );
    7271
    7372        return originalFunc.fptr;
     
    9897
    9998struct {
    100         __typeof__( exit  ) exit  __attribute__(( noreturn ));
    101         __typeof__( abort ) abort __attribute__(( noreturn ));
     99        void (* exit)( int ) __attribute__ (( __noreturn__ ));
     100        void (* abort)( void ) __attribute__ (( __noreturn__ ));
    102101} __cabi_libc;
    103102
     
    123122
    124123// Forward declare abort after the __typeof__ call to avoid ambiguities
    125 void abort ( const char fmt[], ... ) __attribute__ ((__nothrow__, __leaf__, __noreturn__));
     124void exit( int status, const char fmt[], ... ) __attribute__ (( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ ));
     125void abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
    126126
    127127extern "C" {
    128         void abort( void ) __attribute__ ((__nothrow__, __leaf__, __noreturn__)) {
    129                 abortf( NULL );
    130         }
    131 
    132         void abortf( const char fmt[], ... ) __attribute__ ((__nothrow__, __leaf__, __noreturn__)) {
     128        void abort( void ) __attribute__ (( __nothrow__, __leaf__, __noreturn__ )) {
     129                abort( NULL );
     130        }
     131
     132        void __cabi_abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ )) {
    133133                va_list argp;
    134134                va_start( argp, fmt );
     
    137137        }
    138138
    139         void exit( int __status ) __attribute__ ((__nothrow__, __leaf__, __noreturn__)) {
    140                 __cabi_libc.exit(__status);
    141         }
    142 }
    143 
    144 void * kernel_abort    ( void ) __attribute__ ((__nothrow__, __leaf__, __weak__)) { return NULL; }
    145 void   kernel_abort_msg( void * data, char * buffer, int size ) __attribute__ ((__nothrow__, __leaf__, __weak__)) {}
    146 int kernel_abort_lastframe( void ) __attribute__ ((__nothrow__, __leaf__, __weak__)) { return 4; }
     139        void exit( int status ) __attribute__ (( __nothrow__, __leaf__, __noreturn__ )) {
     140                __cabi_libc.exit( status );
     141        }
     142}
     143
     144void * kernel_abort    ( void ) __attribute__ (( __nothrow__, __leaf__, __weak__ )) { return NULL; }
     145void   kernel_abort_msg( void * data, char * buffer, int size ) __attribute__ (( __nothrow__, __leaf__, __weak__ )) {}
     146int kernel_abort_lastframe( void ) __attribute__ (( __nothrow__, __leaf__, __weak__ )) { return 4; }
    147147
    148148enum { abort_text_size = 1024 };
     
    150150static int abort_lastframe;
    151151
    152 void abort( const char fmt[], ... ) __attribute__ ((__nothrow__, __leaf__, __noreturn__)) {
     152void exit( int status, const char fmt[], ... ) __attribute__ (( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ )) {
     153    va_list args;
     154    va_start( args, fmt );
     155    vfprintf( stderr, fmt, args );
     156    va_end( args );
     157        __cabi_libc.exit( status );
     158}
     159
     160void abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ )) {
    153161        void * kernel_data = kernel_abort();                    // must be done here to lock down kernel
    154162        int len;
     
    226234
    227235void sigHandler_segv( __CFA_SIGPARMS__ ) {
    228         abortf( "Addressing invalid memory at location %p\n"
     236        abort( "Addressing invalid memory at location %p\n"
    229237                        "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",
    230238                        sfp->si_addr );
     
    232240
    233241void sigHandler_ill( __CFA_SIGPARMS__ ) {
    234         abortf( "Executing illegal instruction at location %p.\n"
     242        abort( "Executing illegal instruction at location %p.\n"
    235243                        "Possible cause is stack corruption.\n",
    236244                        sfp->si_addr );
     
    248256          default: msg = "unknown";
    249257        } // choose
    250         abortf( "Computation error %s at location %p.\n", msg, sfp->si_addr );
     258        abort( "Computation error %s at location %p.\n", msg, sfp->si_addr );
    251259}
    252260
Note: See TracChangeset for help on using the changeset viewer.