Changes in src/libcfa/interpose.c [2b8bc41:169d944]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/interpose.c
r2b8bc41 r169d944 10 10 // Created On : Wed Mar 29 16:10:31 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : T ue Feb 6 17:57:56201813 // Update Count : 4912 // Last Modified On : Thu Feb 8 16:18:09 2018 13 // Update Count : 75 14 14 // 15 15 … … 33 33 #include "startup.h" 34 34 35 //============================================================================================= 36 // Interposing helpers 37 //============================================================================================= 38 35 39 typedef void (*generic_fptr_t)(void); 36 40 generic_fptr_t interpose_symbol( const char* symbol, const char *version ) { … … 46 50 error = dlerror(); 47 51 if ( error ) { 48 abort f( "interpose_symbol : failed to open libc, %s\n", error );52 abort( "interpose_symbol : failed to open libc, %s\n", error ); 49 53 } 50 54 #endif … … 64 68 65 69 error = dlerror(); 66 if ( error ) abort f( "interpose_symbol : internal error, %s\n", error );70 if ( error ) abort( "interpose_symbol : internal error, %s\n", error ); 67 71 68 72 return originalFunc.fptr; 69 73 } 70 74 71 72 __typeof__( exit ) libc_exit __attribute__(( noreturn ));73 __typeof__( abort ) libc_abort __attribute__(( noreturn ));74 75 75 forall(dtype T) 76 static inline void assign_ptr( T** symbol_ptr, const char * symbol_name, const char * version) {76 static inline void ptr_from_symbol( T** symbol_ptr, const char * symbol_name, const char * version) { 77 77 union { 78 78 generic_fptr_t gp; … … 85 85 } 86 86 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 //============================================================================================= 88 92 89 93 void sigHandler_segv ( __CFA_SIGPARMS__ ); … … 92 96 void sigHandler_abort( __CFA_SIGPARMS__ ); 93 97 98 struct { 99 void (* exit)( int ) __attribute__ (( __noreturn__ )); 100 void (* abort)( void ) __attribute__ (( __noreturn__ )); 101 } __cabi_libc; 102 94 103 extern "C" { 95 104 void __cfaabi_interpose_startup(void) __attribute__(( constructor( STARTUP_PRIORITY_CORE ) )); … … 97 106 const char *version = NULL; 98 107 99 IN IT_REALRTN( abort, version );100 IN IT_REALRTN( exit, version );108 INTERPOSE_LIBC( abort, version ); 109 INTERPOSE_LIBC( exit , version ); 101 110 102 111 __cfaabi_sigaction( SIGSEGV, sigHandler_segv , SA_SIGINFO ); // Failure handler … … 112 121 //============================================================================================= 113 122 123 // 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__ )); 126 114 127 extern "C" { 115 void abort( void ) __attribute__ (( __nothrow__, __leaf__, __noreturn__)) {116 abort f( 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 v a_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 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; } 134 147 135 148 enum { abort_text_size = 1024 }; … … 137 150 static int abort_lastframe; 138 151 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) 152 void 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 160 void 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 ); 146 174 __cfaabi_dbg_bits_write( abort_text, len ); 147 175 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(); 164 183 } 165 184 … … 215 234 216 235 void sigHandler_segv( __CFA_SIGPARMS__ ) { 217 abort f( "Attempt to addresslocation %p\n"236 abort( "Addressing invalid memory at location %p\n" 218 237 "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", 219 238 sfp->si_addr ); … … 221 240 222 241 void sigHandler_ill( __CFA_SIGPARMS__ ) { 223 abort f( "Attempt to execute codeat location %p.\n"242 abort( "Executing illegal instruction at location %p.\n" 224 243 "Possible cause is stack corruption.\n", 225 244 sfp->si_addr ); … … 229 248 const char * msg; 230 249 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"; 238 256 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 ); 242 259 } 243 260
Note:
See TracChangeset
for help on using the changeset viewer.