Ignore:
Timestamp:
May 18, 2018, 2:09:21 PM (6 years ago)
Author:
Aaron Moss <a3moss@…>
Branches:
new-env, with_gc
Children:
2472a19
Parents:
f6f0cca3 (diff), c7d8100c (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 remote-tracking branch 'origin/master' into with_gc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/libcfa/interpose.c

    rf6f0cca3 rff29f08  
    1010// Created On       : Wed Mar 29 16:10:31 2017
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Thu Feb  8 16:18:09 2018
    13 // Update Count     : 75
    14 //
    15 
    16 #include <stdarg.h>
    17 #include <stddef.h>
    18 
    19 extern "C" {
    20 #include <stdio.h>
    21 #include <string.h>
    22 #include <dlfcn.h>
    23 #include <unistd.h>
     12// Last Modified On : Sat May  5 11:37:35 2018
     13// Update Count     : 111
     14//
     15
     16#include <stdarg.h>                                                                             // va_start, va_end
     17#include <string.h>                                                                             // strlen
     18#include <unistd.h>                                                                             // _exit, getpid
    2419#define __USE_GNU
    2520#include <signal.h>
    2621#undef __USE_GNU
    27 #include <execinfo.h>
     22extern "C" {
     23#include <dlfcn.h>                                                                              // dlopen, dlsym
     24#include <execinfo.h>                                                                   // backtrace, messages
    2825}
    2926
    3027#include "bits/debug.h"
    3128#include "bits/defs.h"
    32 #include "bits/signal.h"
    33 #include "startup.h"
     29#include "bits/signal.h"                                                                // sigHandler_?
     30#include "startup.h"                                                                    // STARTUP_PRIORITY_CORE
    3431
    3532//=============================================================================================
     
    3734//=============================================================================================
    3835
    39 typedef void (*generic_fptr_t)(void);
    40 generic_fptr_t interpose_symbol( const char* symbol, const char *version ) {
     36typedef void (* generic_fptr_t)(void);
     37generic_fptr_t interpose_symbol( const char * symbol, const char * version ) {
    4138        const char * error;
    4239
     
    5552        } // if
    5653
    57         union { generic_fptr_t fptr; void* ptr; } originalFunc;
     54        union { generic_fptr_t fptr; void * ptr; } originalFunc;
    5855
    5956        #if defined( _GNU_SOURCE )
     
    7370}
    7471
    75 forall(dtype T)
    76 static inline void ptr_from_symbol( T** symbol_ptr, const char * symbol_name, const char * version) {
    77         union {
    78                 generic_fptr_t gp;
    79                 T* tp;
    80         } u;
    81 
    82         u.gp = interpose_symbol( symbol_name, version );
    83 
    84         *symbol_ptr = u.tp;
    85 }
    86 
    87 #define INTERPOSE_LIBC( x, ver ) ptr_from_symbol( (void**)&__cabi_libc.x, #x, ver)
    88 
    89 //=============================================================================================
    90 // Terminating Signals logic
     72#define INTERPOSE_LIBC( x, ver ) __cabi_libc.x = (typeof(__cabi_libc.x))interpose_symbol( #x, ver )
     73
     74//=============================================================================================
     75// Interposition Startup logic
    9176//=============================================================================================
    9277
     
    9580void sigHandler_fpe  ( __CFA_SIGPARMS__ );
    9681void sigHandler_abort( __CFA_SIGPARMS__ );
     82void sigHandler_term ( __CFA_SIGPARMS__ );
    9783
    9884struct {
    99         void (* exit)( int ) __attribute__ (( __noreturn__ ));
    100         void (* abort)( void ) __attribute__ (( __noreturn__ ));
     85        void (* exit)( int ) __attribute__(( __noreturn__ ));
     86        void (* abort)( void ) __attribute__(( __noreturn__ ));
    10187} __cabi_libc;
    10288
     
    10692                const char *version = NULL;
    10793
     94#pragma GCC diagnostic push
     95#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
    10896                INTERPOSE_LIBC( abort, version );
    10997                INTERPOSE_LIBC( exit , version );
    110 
    111                 __cfaabi_sigaction( SIGSEGV, sigHandler_segv , SA_SIGINFO ); // Failure handler
    112                 __cfaabi_sigaction( SIGBUS , sigHandler_segv , SA_SIGINFO ); // Failure handler
    113                 __cfaabi_sigaction( SIGILL , sigHandler_ill  , SA_SIGINFO ); // Failure handler
    114                 __cfaabi_sigaction( SIGFPE , sigHandler_fpe  , SA_SIGINFO ); // Failure handler
    115                 __cfaabi_sigaction( SIGABRT, sigHandler_abort, SA_SIGINFO ); // Failure handler
     98#pragma GCC diagnostic pop
     99
     100                // Failure handler
     101                __cfaabi_sigaction( SIGSEGV, sigHandler_segv , SA_SIGINFO );
     102                __cfaabi_sigaction( SIGBUS , sigHandler_segv , SA_SIGINFO );
     103                __cfaabi_sigaction( SIGILL , sigHandler_ill  , SA_SIGINFO );
     104                __cfaabi_sigaction( SIGFPE , sigHandler_fpe  , SA_SIGINFO );
     105                __cfaabi_sigaction( SIGABRT, sigHandler_abort, SA_SIGINFO | SA_RESETHAND);
     106                __cfaabi_sigaction( SIGTERM, sigHandler_term , SA_SIGINFO );
     107                __cfaabi_sigaction( SIGINT , sigHandler_term , SA_SIGINFO );
    116108        }
    117109}
     
    122114
    123115// Forward declare abort after the __typeof__ call to avoid ambiguities
    124 void exit( int status, const char fmt[], ... ) __attribute__ (( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ ));
    125 void abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
     116void exit( int status, const char fmt[], ... ) __attribute__(( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ ));
     117void abort( const char fmt[], ... ) __attribute__(( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
    126118
    127119extern "C" {
    128         void abort( void ) __attribute__ (( __nothrow__, __leaf__, __noreturn__ )) {
     120        void abort( void ) __attribute__(( __nothrow__, __leaf__, __noreturn__ )) {
    129121                abort( NULL );
    130122        }
    131123
    132         void __cabi_abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ )) {
     124        void __cabi_abort( const char fmt[], ... ) __attribute__(( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ )) {
    133125                va_list argp;
    134126                va_start( argp, fmt );
     
    137129        }
    138130
    139         void exit( int status ) __attribute__ (( __nothrow__, __leaf__, __noreturn__ )) {
     131        void exit( int status ) __attribute__(( __nothrow__, __leaf__, __noreturn__ )) {
    140132                __cabi_libc.exit( status );
    141133        }
    142134}
    143135
    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; }
     136void * kernel_abort    ( void ) __attribute__(( __nothrow__, __leaf__, __weak__ )) { return NULL; }
     137void   kernel_abort_msg( void * data, char * buffer, int size ) __attribute__(( __nothrow__, __leaf__, __weak__ )) {}
     138int kernel_abort_lastframe( void ) __attribute__(( __nothrow__, __leaf__, __weak__ )) { return 4; }
    147139
    148140enum { abort_text_size = 1024 };
     
    150142static int abort_lastframe;
    151143
    152 void exit( int status, const char fmt[], ... ) __attribute__ (( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ )) {
     144void exit( int status, const char fmt[], ... ) __attribute__(( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ )) {
    153145    va_list args;
    154146    va_start( args, fmt );
     
    158150}
    159151
    160 void abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ )) {
     152void abort( const char fmt[], ... ) __attribute__(( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ )) {
    161153        void * kernel_data = kernel_abort();                    // must be done here to lock down kernel
    162154        int len;
     
    268260}
    269261
     262void sigHandler_term( __CFA_SIGPARMS__ ) {
     263        abort( "Application stopped by %s signal.", sig == SIGINT ? "an interrupt (SIGINT)" : "a terminate (SIGTERM)" );
     264}
     265
    270266// Local Variables: //
    271267// mode: c //
Note: See TracChangeset for help on using the changeset viewer.