Ignore:
Timestamp:
Feb 9, 2018, 4:39:52 PM (6 years ago)
Author:
Peter A. Buhr <pabuhr@…>
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:
298ed08
Parents:
381fdee (diff), a722c7a (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:

fix conflicts

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/interpose.c

    r381fdee rbede27b  
    1010// Created On       : Wed Mar 29 16:10:31 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Tue Feb  6 17:57:56 2018
    13 // Update Count     : 49
     12// Last Modified On : Thu Feb  8 16:18:09 2018
     13// Update Count     : 75
    1414//
    1515
     
    3333#include "startup.h"
    3434
     35//=============================================================================================
     36// Interposing helpers
     37//=============================================================================================
     38
    3539typedef void (*generic_fptr_t)(void);
    3640generic_fptr_t interpose_symbol( const char* symbol, const char *version ) {
     
    4650                        error = dlerror();
    4751                        if ( error ) {
    48                                 abortf( "interpose_symbol : failed to open libc, %s\n", error );
     52                                abort( "interpose_symbol : failed to open libc, %s\n", error );
    4953                        }
    5054                #endif
     
    6468
    6569        error = dlerror();
    66         if ( error ) abortf( "interpose_symbol : internal error, %s\n", error );
     70        if ( error ) abort( "interpose_symbol : internal error, %s\n", error );
    6771
    6872        return originalFunc.fptr;
    6973}
    7074
    71 
    72 __typeof__( exit ) libc_exit __attribute__(( noreturn ));
    73 __typeof__( abort ) libc_abort __attribute__(( noreturn ));
    74 
    7575forall(dtype T)
    76 static inline void assign_ptr( T** symbol_ptr, const char * symbol_name, const char * version) {
     76static inline void ptr_from_symbol( T** symbol_ptr, const char * symbol_name, const char * version) {
    7777        union {
    7878                generic_fptr_t gp;
     
    8585}
    8686
    87 #define INIT_REALRTN( x, ver ) assign_ptr( (void**)&libc_##x, #x, ver)
     87#define INTERPOSE_LIBC( x, ver ) ptr_from_symbol( (void**)&__cabi_libc.x, #x, ver)
     88
     89//=============================================================================================
     90// Terminating Signals logic
     91//=============================================================================================
    8892
    8993void sigHandler_segv ( __CFA_SIGPARMS__ );
     
    9296void sigHandler_abort( __CFA_SIGPARMS__ );
    9397
     98struct {
     99        void (* exit)( int ) __attribute__ (( __noreturn__ ));
     100        void (* abort)( void ) __attribute__ (( __noreturn__ ));
     101} __cabi_libc;
     102
    94103extern "C" {
    95104        void __cfaabi_interpose_startup(void)  __attribute__(( constructor( STARTUP_PRIORITY_CORE ) ));
     
    97106                const char *version = NULL;
    98107
    99                 INIT_REALRTN( abort, version );
    100                 INIT_REALRTN( exit, version );
     108                INTERPOSE_LIBC( abort, version );
     109                INTERPOSE_LIBC( exit , version );
    101110
    102111                __cfaabi_sigaction( SIGSEGV, sigHandler_segv , SA_SIGINFO ); // Failure handler
     
    112121//=============================================================================================
    113122
     123// Forward declare abort after the __typeof__ call to avoid ambiguities
     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__ ));
     126
    114127extern "C" {
    115         void abort( void ) __attribute__ ((__nothrow__, __leaf__, __noreturn__)) {
    116                 abortf( NULL );
    117         }
    118 
    119         void exit( int __status ) __attribute__ ((__nothrow__, __leaf__, __noreturn__)) {
    120                 libc_exit(__status);
    121         }
    122 }
    123 
    124 void abort( const char fmt[], ... ) __attribute__ ((__nothrow__, __leaf__, __noreturn__)) {
    125         va_list argp;
    126         va_start( argp, fmt );
    127         abortf( fmt, argp );
    128         va_end( argp );
    129 }
    130 
    131 void * kernel_abort    ( void ) __attribute__ ((__nothrow__, __leaf__, __weak__)) { return NULL; }
    132 void   kernel_abort_msg( void * data, char * buffer, int size ) __attribute__ ((__nothrow__, __leaf__, __weak__)) {}
    133 int kernel_abort_lastframe( void ) __attribute__ ((__nothrow__, __leaf__, __weak__)) { return 4; }
     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__ )) {
     133                va_list argp;
     134                va_start( argp, fmt );
     135                abort( fmt, argp );
     136                va_end( argp );
     137        }
     138
     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; }
    134147
    135148enum { abort_text_size = 1024 };
     
    137150static int abort_lastframe;
    138151
    139 extern "C" {
    140         void abortf( const char fmt[], ... ) __attribute__ ((__nothrow__, __leaf__, __noreturn__)) {
    141                 void * kernel_data = kernel_abort();                    // must be done here to lock down kernel
    142                 int len;
    143 
    144                 abort_lastframe = kernel_abort_lastframe();
    145                 len = snprintf( abort_text, abort_text_size, "Cforall Runtime error (UNIX pid:%ld) ", (long int)getpid() ); // use UNIX pid (versus getPid)
     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__ )) {
     161        void * kernel_data = kernel_abort();                    // must be done here to lock down kernel
     162        int len;
     163
     164        abort_lastframe = kernel_abort_lastframe();
     165        len = snprintf( abort_text, abort_text_size, "Cforall Runtime error (UNIX pid:%ld) ", (long int)getpid() ); // use UNIX pid (versus getPid)
     166        __cfaabi_dbg_bits_write( abort_text, len );
     167
     168        if ( fmt ) {
     169                va_list args;
     170                va_start( args, fmt );
     171
     172                len = vsnprintf( abort_text, abort_text_size, fmt, args );
     173                va_end( args );
    146174                __cfaabi_dbg_bits_write( abort_text, len );
    147175
    148                 if ( fmt ) {
    149                         va_list args;
    150                         va_start( args, fmt );
    151 
    152                         len = vsnprintf( abort_text, abort_text_size, fmt, args );
    153                         va_end( args );
    154                         __cfaabi_dbg_bits_write( abort_text, len );
    155 
    156                         if ( fmt[strlen( fmt ) - 1] != '\n' ) {         // add optional newline if missing at the end of the format text
    157                                 __cfaabi_dbg_bits_write( "\n", 1 );
    158                         }
    159                 }
    160 
    161                 kernel_abort_msg( kernel_data, abort_text, abort_text_size );
    162                 libc_abort();
    163         }
     176                if ( fmt[strlen( fmt ) - 1] != '\n' ) {         // add optional newline if missing at the end of the format text
     177                        __cfaabi_dbg_bits_write( "\n", 1 );
     178                }
     179        }
     180
     181        kernel_abort_msg( kernel_data, abort_text, abort_text_size );
     182        __cabi_libc.abort();
    164183}
    165184
     
    215234
    216235void sigHandler_segv( __CFA_SIGPARMS__ ) {
    217         abortf( "Attempt to address location %p\n"
     236        abort( "Addressing invalid memory at location %p\n"
    218237                        "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",
    219238                        sfp->si_addr );
     
    221240
    222241void sigHandler_ill( __CFA_SIGPARMS__ ) {
    223         abortf( "Attempt to execute code at location %p.\n"
     242        abort( "Executing illegal instruction at location %p.\n"
    224243                        "Possible cause is stack corruption.\n",
    225244                        sfp->si_addr );
     
    229248        const char * msg;
    230249
    231         switch ( sfp->si_code ) {
    232           case FPE_INTDIV:
    233           case FPE_FLTDIV: msg = "divide by zero"; break;
    234           case FPE_FLTOVF: msg = "overflow"; break;
    235           case FPE_FLTUND: msg = "underflow"; break;
    236           case FPE_FLTRES: msg = "inexact result"; break;
    237           case FPE_FLTINV: msg = "invalid operation"; break;
     250        choose( sfp->si_code ) {
     251          case FPE_INTDIV, FPE_FLTDIV: msg = "divide by zero";
     252          case FPE_FLTOVF: msg = "overflow";
     253          case FPE_FLTUND: msg = "underflow";
     254          case FPE_FLTRES: msg = "inexact result";
     255          case FPE_FLTINV: msg = "invalid operation";
    238256          default: msg = "unknown";
    239         } // switch
    240         abortf( "Floating point error.\n"
    241                         "Cause is %s.\n", msg );
     257        } // choose
     258        abort( "Computation error %s at location %p.\n", msg, sfp->si_addr );
    242259}
    243260
Note: See TracChangeset for help on using the changeset viewer.