Changeset 089a0d7 for libcfa/src
- Timestamp:
- Mar 14, 2023, 11:12:35 AM (20 months ago)
- Branches:
- ADT, ast-experimental, master
- Children:
- 15596d7
- Parents:
- a0a949c
- Location:
- libcfa/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/interpose.cfa
ra0a949c r089a0d7 10 10 // Created On : Wed Mar 29 16:10:31 2017 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Thu Mar 2 13:56:26 2023 13 // Update Count : 191 14 // 15 16 #include <stdarg.h> // va_start, va_end 12 // Last Modified On : Mon Mar 13 22:39:12 2023 13 // Update Count : 193 14 // 15 17 16 #include <stdio.h> 18 #include <string.h> // strlen19 17 #include <unistd.h> // _exit, getpid 20 #include <signal.h>21 18 extern "C" { 22 19 #include <dlfcn.h> // dlopen, dlsym … … 24 21 } 25 22 26 #include "bits/debug.hfa"27 23 #include "bits/defs.hfa" 28 24 #include "bits/signal.hfa" // sigHandler_? … … 40 36 41 37 typedef void (* generic_fptr_t)(void); 38 42 39 static generic_fptr_t do_interpose_symbol( void * library, const char symbol[], const char version[] ) { 43 const char * error;44 45 40 union { generic_fptr_t fptr; void * ptr; } originalFunc; 46 41 47 42 originalFunc.ptr = dlsym( library, symbol ); 48 error = dlerror();49 if ( error ) abort( "interpose_symbol : internal error, %s\n", error);50 43 if ( ! originalFunc.ptr ) { // == nullptr 44 abort( "interpose_symbol : internal error, %s\n", dlerror() ); 45 } // if 51 46 return originalFunc.fptr; 52 47 } … … 57 52 library = RTLD_NEXT; 58 53 #else 54 // missing RTLD_NEXT => must hard-code library name, assuming libstdc++ 59 55 library = dlopen( "libc.so.6", RTLD_LAZY ); 60 if ( ! library ) { 61 const char * error = dlerror(); 62 if ( error ) { 63 abort( "interpose_symbol : failed to open libc, %s\n", error ); 64 } // if 56 if ( ! library ) { // == nullptr 57 abort( "interpose_symbol : failed to open libc, %s\n", dlerror() ); 65 58 } // if 66 #endif 67 68 return do_interpose_symbol( library, symbol, version);59 #endif // RTLD_NEXT 60 61 return do_interpose_symbol( library, symbol, version ); 69 62 } 70 63 -
libcfa/src/interpose_thread.cfa
ra0a949c r089a0d7 14 14 // 15 15 16 #include <stdarg.h> // va_start, va_end 17 #include <stdio.h> 18 #include <string.h> // strlen 16 #ifdef __i386__ // 32-bit architecture 17 #undef _GNU_SOURCE 18 #endif // __i386__ 19 19 20 #include <signal.h> 20 21 #include <pthread.h> 22 #include <signal.h> 21 23 extern "C" { 22 24 #include <dlfcn.h> // dlopen, dlsym 23 #include <execinfo.h> // backtrace, messages24 25 } 25 26 26 #include "bits/debug.hfa"27 27 #include "bits/defs.hfa" 28 #include <assert.h>29 28 30 29 //============================================================================================= … … 40 39 ) libcfa_public { 41 40 void * library; 41 42 42 #if defined( RTLD_NEXT ) 43 43 library = RTLD_NEXT; 44 44 #else 45 45 // missing RTLD_NEXT => must hard-code library name, assuming libstdc++ 46 library = dlopen( "libthread_db.so", RTLD_LAZY ); 47 if ( ! library ) { 48 const char * error = dlerror(); 49 if ( error ) { 50 abort( "interpose_symbol : failed to open libpthread, %s\n", error ); 51 } 46 library = dlopen( "libpthread.so", RTLD_LAZY ); 47 if ( ! library ) { // == nullptr 48 abort( "interpose_symbol : failed to open libpthread, %s\n", dlerror() ); 52 49 } // if 53 50 #endif // RTLD_NEXT 54 51 55 return do_interpose_symbol( library, symbol, version);52 return do_interpose_symbol( library, symbol, version ); 56 53 } 57 54 … … 81 78 #pragma GCC diagnostic push 82 79 #pragma GCC diagnostic ignored "-Wdiscarded-qualifiers" 83 INTERPOSE( pthread_create 84 INTERPOSE( pthread_join 85 INTERPOSE( pthread_self 86 INTERPOSE( pthread_attr_init 87 INTERPOSE( pthread_attr_destroy 88 INTERPOSE( pthread_attr_setstack 89 INTERPOSE( pthread_attr_getstacksize 90 INTERPOSE( pthread_sigmask 91 INTERPOSE( pthread_sigqueue 92 INTERPOSE( pthread_once 80 INTERPOSE( pthread_create, version ); 81 INTERPOSE( pthread_join, version ); 82 INTERPOSE( pthread_self, version ); 83 INTERPOSE( pthread_attr_init, version ); 84 INTERPOSE( pthread_attr_destroy, version ); 85 INTERPOSE( pthread_attr_setstack, version ); 86 INTERPOSE( pthread_attr_getstacksize, version ); 87 INTERPOSE( pthread_sigmask, version ); 88 INTERPOSE( pthread_sigqueue, version ); 89 INTERPOSE( pthread_once, version ); 93 90 #pragma GCC diagnostic pop 94 91 }
Note: See TracChangeset
for help on using the changeset viewer.