Changeset eef8dfb for libcfa/src/interpose.cfa
- Timestamp:
- Jan 7, 2021, 2:55:57 PM (5 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- 58fe85a
- Parents:
- bdfc032 (diff), 44e37ef (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/interpose.cfa
rbdfc032 reef8dfb 10 10 // Created On : Wed Mar 29 16:10:31 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Jan 30 17:47:32202013 // Update Count : 1 5612 // Last Modified On : Fri Mar 13 17:35:37 2020 13 // Update Count : 178 14 14 // 15 15 16 16 #include <stdarg.h> // va_start, va_end 17 #include <stdio.h> 17 18 #include <string.h> // strlen 18 19 #include <unistd.h> // _exit, getpid … … 29 30 #include "bits/signal.hfa" // sigHandler_? 30 31 #include "startup.hfa" // STARTUP_PRIORITY_CORE 32 #include <assert.h> 31 33 32 34 //============================================================================================= … … 40 42 41 43 typedef void (* generic_fptr_t)(void); 42 generic_fptr_t interpose_symbol( const char * symbol, const char * version) {44 generic_fptr_t interpose_symbol( const char symbol[], const char version[] ) { 43 45 const char * error; 44 46 … … 142 144 void abort( const char fmt[], ... ) __attribute__(( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ )); 143 145 void abort( bool signalAbort, const char fmt[], ... ) __attribute__(( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ )); 146 void __abort( bool signalAbort, const char fmt[], va_list args ) __attribute__(( __nothrow__, __leaf__, __noreturn__ )); 144 147 145 148 extern "C" { 146 149 void abort( void ) __attribute__(( __nothrow__, __leaf__, __noreturn__ )) { 147 abort( false, NULL ); // FIX ME: 0p does not work150 abort( false, "%s", "" ); 148 151 } 149 152 … … 151 154 va_list argp; 152 155 va_start( argp, fmt ); 153 abort( false, fmt, argp );156 __abort( false, fmt, argp ); 154 157 va_end( argp ); 155 158 } … … 161 164 162 165 void * kernel_abort( void ) __attribute__(( __nothrow__, __leaf__, __weak__ )) { return 0p; } 163 void kernel_abort_msg( void * data, char * buffer, int size ) __attribute__(( __nothrow__, __leaf__, __weak__ )) {}166 void kernel_abort_msg( void * data, char buffer[], int size ) __attribute__(( __nothrow__, __leaf__, __weak__ )) {} 164 167 // See concurrency/kernel.cfa for strong definition used in multi-processor mode. 165 168 int kernel_abort_lastframe( void ) __attribute__(( __nothrow__, __leaf__, __weak__ )) { return 4; } … … 169 172 170 173 static void __cfaabi_backtrace( int start ) { 171 enum { 172 Frames = 50, // maximum number of stack frames 173 }; 174 enum { Frames = 50, }; // maximum number of stack frames 174 175 int last = kernel_abort_lastframe(); // skip last N stack frames 175 176 176 177 void * array[Frames]; 177 178 size_t size = backtrace( array, Frames ); 178 char ** messages = backtrace_symbols( array, size ); 179 char ** messages = backtrace_symbols( array, size ); // does not demangle names 179 180 180 181 *index( messages[0], '(' ) = '\0'; // find executable name … … 184 185 char * name = 0p, * offset_begin = 0p, * offset_end = 0p; 185 186 186 for ( char * p = messages[i]; *p; ++p ) {// find parantheses and +offset187 for ( char * p = messages[i]; *p; p += 1 ) { // find parantheses and +offset 187 188 //__cfaabi_bits_print_nolock( "X %s\n", p); 188 189 if ( *p == '(' ) { … … 219 220 } 220 221 221 void abort( bool signalAbort, const char fmt[], ... ) { 222 void * kernel_data = kernel_abort(); // must be done here to lock down kernel 223 int len; 224 225 signal( SIGABRT, SIG_DFL ); // prevent final "real" abort from recursing to handler 226 227 len = snprintf( abort_text, abort_text_size, "Cforall Runtime error (UNIX pid:%ld) ", (long int)getpid() ); // use UNIX pid (versus getPid) 228 __cfaabi_bits_write( STDERR_FILENO, abort_text, len ); 229 230 if ( fmt ) { 231 va_list args; 232 va_start( args, fmt ); 233 222 static volatile int __abort_stage = 0; 223 224 // Cannot forward va_list. 225 void __abort( bool signalAbort, const char fmt[], va_list args ) { 226 int stage = __atomic_add_fetch( &__abort_stage, 1, __ATOMIC_SEQ_CST ); 227 228 // First stage: stop the cforall kernel and print 229 if(stage == 1) { 230 // increment stage 231 stage = __atomic_add_fetch( &__abort_stage, 1, __ATOMIC_SEQ_CST ); 232 233 // must be done here to lock down kernel 234 void * kernel_data = kernel_abort(); 235 int len; 236 237 signal( SIGABRT, SIG_DFL ); // prevent final "real" abort from recursing to handler 238 239 len = snprintf( abort_text, abort_text_size, "Cforall Runtime error (UNIX pid:%ld) ", (long int)getpid() ); // use UNIX pid (versus getPid) 240 __cfaabi_bits_write( STDERR_FILENO, abort_text, len ); 241 242 assert( fmt ); 234 243 len = vsnprintf( abort_text, abort_text_size, fmt, args ); 235 va_end( args );236 244 __cfaabi_bits_write( STDERR_FILENO, abort_text, len ); 237 245 238 if ( fmt[strlen( fmt ) - 1] != '\n' ) { // add optional newline if missing at the end of the format text 239 __cfaabi_dbg_write( "\n", 1 ); 240 } 241 } 242 243 kernel_abort_msg( kernel_data, abort_text, abort_text_size ); 244 __cfaabi_backtrace( signalAbort ? 4 : 3 ); 245 246 __cabi_libc.abort(); // print stack trace in handler 246 // add optional newline if missing at the end of the format text 247 if ( fmt[strlen( fmt ) - 1] != '\n' ) { 248 __cfaabi_bits_write( STDERR_FILENO, "\n", 1 ); 249 } // if 250 kernel_abort_msg( kernel_data, abort_text, abort_text_size ); 251 } 252 253 // Second stage: print the backtrace 254 if(stage == 2) { 255 // increment stage 256 stage = __atomic_add_fetch( &__abort_stage, 1, __ATOMIC_SEQ_CST ); 257 258 // print stack trace in handler 259 __cfaabi_backtrace( signalAbort ? 4 : 2 ); 260 } 261 262 do { 263 // Finally call abort 264 __cabi_libc.abort(); 265 266 // Loop so that we never return 267 } while(true); 247 268 } 248 269 … … 250 271 va_list args; 251 272 va_start( args, fmt ); 252 abort( false, fmt, args ); 273 __abort( false, fmt, args ); 274 // CONTROL NEVER REACHES HERE! 253 275 va_end( args ); 276 } 277 278 void abort( bool signalAbort, const char fmt[], ... ) { 279 va_list args; 280 va_start( args, fmt ); 281 __abort( signalAbort, fmt, args ); 282 // CONTROL NEVER REACHES HERE! 283 va_end( args ); 254 284 } 255 285
Note:
See TracChangeset
for help on using the changeset viewer.