Changes in src/libcfa/interpose.c [3d5f2ef1:a424315d]
- File:
-
- 1 edited
-
src/libcfa/interpose.c (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/libcfa/interpose.c
r3d5f2ef1 ra424315d 28 28 } 29 29 30 #define __NO_ABORT_OVERLOAD // no abort overload avoid ambiguities31 30 #include "bits/debug.h" 32 31 #include "bits/defs.h" 33 32 #include "bits/signal.h" 34 33 #include "startup.h" 35 36 //=============================================================================================37 // Interposing helpers38 //=============================================================================================39 34 40 35 typedef void (*generic_fptr_t)(void); … … 74 69 } 75 70 71 72 __typeof__( exit ) libc_exit __attribute__(( noreturn )); 73 __typeof__( abort ) libc_abort __attribute__(( noreturn )); 74 76 75 forall(dtype T) 77 static inline void ptr_from_symbol( T** symbol_ptr, const char * symbol_name, const char * version) {76 static inline void assign_ptr( T** symbol_ptr, const char * symbol_name, const char * version) { 78 77 union { 79 78 generic_fptr_t gp; … … 86 85 } 87 86 88 #define INTERPOSE_LIBC( x, ver ) ptr_from_symbol( (void**)&__cabi_libc.x, #x, ver) 89 90 //============================================================================================= 91 // Terminating Signals logic 92 //============================================================================================= 87 #define INIT_REALRTN( x, ver ) assign_ptr( (void**)&libc_##x, #x, ver) 93 88 94 89 void sigHandler_segv ( __CFA_SIGPARMS__ ); … … 97 92 void sigHandler_abort( __CFA_SIGPARMS__ ); 98 93 99 struct {100 __typeof__( exit ) exit __attribute__(( noreturn ));101 __typeof__( abort ) abort __attribute__(( noreturn ));102 } __cabi_libc;103 104 94 extern "C" { 105 95 void __cfaabi_interpose_startup(void) __attribute__(( constructor( STARTUP_PRIORITY_CORE ) )); … … 107 97 const char *version = NULL; 108 98 109 IN TERPOSE_LIBC( abort, version );110 IN TERPOSE_LIBC( exit, version );99 INIT_REALRTN( abort, version ); 100 INIT_REALRTN( exit, version ); 111 101 112 102 __cfaabi_sigaction( SIGSEGV, sigHandler_segv , SA_SIGINFO ); // Failure handler … … 122 112 //============================================================================================= 123 113 124 // Forward declare abort after the __typeof__ call to avoid ambiguities125 void abort ( const char fmt[], ... ) __attribute__ ((__nothrow__, __leaf__, __noreturn__));126 127 114 extern "C" { 128 115 void abort( void ) __attribute__ ((__nothrow__, __leaf__, __noreturn__)) { … … 130 117 } 131 118 132 void abortf( const char fmt[], ... ) __attribute__ ((__nothrow__, __leaf__, __noreturn__)) {133 va_list argp;134 va_start( argp, fmt );135 abort( fmt, argp );136 va_end( argp );137 }138 139 119 void exit( int __status ) __attribute__ ((__nothrow__, __leaf__, __noreturn__)) { 140 __cabi_libc.exit(__status); 141 } 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 ); 142 129 } 143 130 … … 150 137 static int abort_lastframe; 151 138 152 void abort( const char fmt[], ... ) __attribute__ ((__nothrow__, __leaf__, __noreturn__)) { 153 void * kernel_data = kernel_abort(); // must be done here to lock down kernel 154 int len; 155 156 abort_lastframe = kernel_abort_lastframe(); 157 len = snprintf( abort_text, abort_text_size, "Cforall Runtime error (UNIX pid:%ld) ", (long int)getpid() ); // use UNIX pid (versus getPid) 158 __cfaabi_dbg_bits_write( abort_text, len ); 159 160 if ( fmt ) { 161 va_list args; 162 va_start( args, fmt ); 163 164 len = vsnprintf( abort_text, abort_text_size, fmt, args ); 165 va_end( args ); 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) 166 146 __cfaabi_dbg_bits_write( abort_text, len ); 167 147 168 if ( fmt[strlen( fmt ) - 1] != '\n' ) { // add optional newline if missing at the end of the format text 169 __cfaabi_dbg_bits_write( "\n", 1 ); 170 } 171 } 172 173 kernel_abort_msg( kernel_data, abort_text, abort_text_size ); 174 __cabi_libc.abort(); 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 } 175 164 } 176 165
Note:
See TracChangeset
for help on using the changeset viewer.