Changes in src/libcfa/interpose.c [de94a60:94dea96]
- File:
-
- 1 edited
-
src/libcfa/interpose.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/interpose.c
rde94a60 r94dea96 10 10 // Created On : Wed Mar 29 16:10:31 2017 11 11 // Last Modified By : Peter A. Buhr 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 12 // Last Modified On : Tue May 1 15:05:35 2018 13 // Update Count : 83 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> 19 24 #define __USE_GNU 20 25 #include <signal.h> 21 26 #undef __USE_GNU 22 extern "C" { 23 #include <dlfcn.h> // dlopen, dlsym 24 #include <execinfo.h> // backtrace, messages 27 #include <execinfo.h> 25 28 } 26 29 27 30 #include "bits/debug.h" 28 31 #include "bits/defs.h" 29 #include "bits/signal.h" // sigHandler_?30 #include "startup.h" // STARTUP_PRIORITY_CORE32 #include "bits/signal.h" 33 #include "startup.h" 31 34 32 35 //============================================================================================= … … 34 37 //============================================================================================= 35 38 36 typedef void (* generic_fptr_t)(void);37 generic_fptr_t interpose_symbol( const char * symbol, const char *version ) {39 typedef void (*generic_fptr_t)(void); 40 generic_fptr_t interpose_symbol( const char* symbol, const char *version ) { 38 41 const char * error; 39 42 … … 52 55 } // if 53 56 54 union { generic_fptr_t fptr; void * ptr; } originalFunc;57 union { generic_fptr_t fptr; void* ptr; } originalFunc; 55 58 56 59 #if defined( _GNU_SOURCE ) … … 70 73 } 71 74 72 #define INTERPOSE_LIBC( x, ver ) __cabi_libc.x = (typeof(__cabi_libc.x))interpose_symbol( #x, ver ) 73 74 //============================================================================================= 75 // Interposition Startup logic 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 76 91 //============================================================================================= 77 92 … … 83 98 84 99 struct { 85 void (* exit)( int ) __attribute__ (( __noreturn__ ));86 void (* abort)( void ) __attribute__ (( __noreturn__ ));100 void (* exit)( int ) __attribute__ (( __noreturn__ )); 101 void (* abort)( void ) __attribute__ (( __noreturn__ )); 87 102 } __cabi_libc; 88 103 … … 92 107 const char *version = NULL; 93 108 94 #pragma GCC diagnostic push95 #pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"96 109 INTERPOSE_LIBC( abort, version ); 97 110 INTERPOSE_LIBC( exit , version ); 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 ); 111 112 __cfaabi_sigaction( SIGSEGV, sigHandler_segv , SA_SIGINFO ); // Failure handler 113 __cfaabi_sigaction( SIGBUS , sigHandler_segv , SA_SIGINFO ); // Failure handler 114 __cfaabi_sigaction( SIGILL , sigHandler_ill , SA_SIGINFO ); // Failure handler 115 __cfaabi_sigaction( SIGFPE , sigHandler_fpe , SA_SIGINFO ); // Failure handler 116 __cfaabi_sigaction( SIGABRT, sigHandler_abort, SA_SIGINFO ); // Failure handler 117 __cfaabi_sigaction( SIGTERM, sigHandler_term , SA_SIGINFO ); // Failure handler 118 __cfaabi_sigaction( SIGINT , sigHandler_term , SA_SIGINFO ); // Failure handler 108 119 } 109 120 } … … 114 125 115 126 // Forward declare abort after the __typeof__ call to avoid ambiguities 116 void exit( int status, const char fmt[], ... ) __attribute__ (( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ ));117 void abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));127 void exit( int status, const char fmt[], ... ) __attribute__ (( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ )); 128 void abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ )); 118 129 119 130 extern "C" { 120 void abort( void ) __attribute__ (( __nothrow__, __leaf__, __noreturn__ )) {131 void abort( void ) __attribute__ (( __nothrow__, __leaf__, __noreturn__ )) { 121 132 abort( NULL ); 122 133 } 123 134 124 void __cabi_abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ )) {135 void __cabi_abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ )) { 125 136 va_list argp; 126 137 va_start( argp, fmt ); … … 129 140 } 130 141 131 void exit( int status ) __attribute__ (( __nothrow__, __leaf__, __noreturn__ )) {142 void exit( int status ) __attribute__ (( __nothrow__, __leaf__, __noreturn__ )) { 132 143 __cabi_libc.exit( status ); 133 144 } 134 145 } 135 146 136 void * kernel_abort ( void ) __attribute__ (( __nothrow__, __leaf__, __weak__ )) { return NULL; }137 void kernel_abort_msg( void * data, char * buffer, int size ) __attribute__ (( __nothrow__, __leaf__, __weak__ )) {}138 int kernel_abort_lastframe( void ) __attribute__ (( __nothrow__, __leaf__, __weak__ )) { return 4; }147 void * kernel_abort ( void ) __attribute__ (( __nothrow__, __leaf__, __weak__ )) { return NULL; } 148 void kernel_abort_msg( void * data, char * buffer, int size ) __attribute__ (( __nothrow__, __leaf__, __weak__ )) {} 149 int kernel_abort_lastframe( void ) __attribute__ (( __nothrow__, __leaf__, __weak__ )) { return 4; } 139 150 140 151 enum { abort_text_size = 1024 }; … … 142 153 static int abort_lastframe; 143 154 144 void exit( int status, const char fmt[], ... ) __attribute__ (( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ )) {155 void exit( int status, const char fmt[], ... ) __attribute__ (( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ )) { 145 156 va_list args; 146 157 va_start( args, fmt ); … … 150 161 } 151 162 152 void abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ )) {163 void abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ )) { 153 164 void * kernel_data = kernel_abort(); // must be done here to lock down kernel 154 165 int len;
Note:
See TracChangeset
for help on using the changeset viewer.