Changeset 089a0d7


Ignore:
Timestamp:
Mar 14, 2023, 11:12:35 AM (13 months ago)
Author:
Peter A. Buhr <pabuhr@…>
Branches:
ADT, ast-experimental, master
Children:
15596d7
Parents:
a0a949c
Message:

formatting, rework interpose code (again), remove unnecessary #include files, temporary patch to fix 32-bit build problem using _GNU_SOURCE

Location:
libcfa/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/interpose.cfa

    ra0a949c r089a0d7  
    1010// Created On       : Wed Mar 29 16:10:31 2017
    1111// 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
    1716#include <stdio.h>
    18 #include <string.h>                                                                             // strlen
    1917#include <unistd.h>                                                                             // _exit, getpid
    20 #include <signal.h>
    2118extern "C" {
    2219#include <dlfcn.h>                                                                              // dlopen, dlsym
     
    2421}
    2522
    26 #include "bits/debug.hfa"
    2723#include "bits/defs.hfa"
    2824#include "bits/signal.hfa"                                                              // sigHandler_?
     
    4036
    4137typedef void (* generic_fptr_t)(void);
     38
    4239static generic_fptr_t do_interpose_symbol( void * library, const char symbol[], const char version[] ) {
    43         const char * error;
    44 
    4540        union { generic_fptr_t fptr; void * ptr; } originalFunc;
    4641
    4742        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
    5146        return originalFunc.fptr;
    5247}
     
    5752        library = RTLD_NEXT;
    5853        #else
     54        // missing RTLD_NEXT => must hard-code library name, assuming libstdc++
    5955        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() );
    6558        } // 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 );
    6962}
    7063
  • libcfa/src/interpose_thread.cfa

    ra0a949c r089a0d7  
    1414//
    1515
    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
    1920#include <signal.h>
    2021#include <pthread.h>
     22#include <signal.h>
    2123extern "C" {
    2224#include <dlfcn.h>                                                                              // dlopen, dlsym
    23 #include <execinfo.h>                                                                   // backtrace, messages
    2425}
    2526
    26 #include "bits/debug.hfa"
    2727#include "bits/defs.hfa"
    28 #include <assert.h>
    2928
    3029//=============================================================================================
     
    4039) libcfa_public {
    4140        void * library;
     41
    4242        #if defined( RTLD_NEXT )
    4343        library = RTLD_NEXT;
    4444        #else
    4545        // 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() );
    5249        } // if
    5350        #endif // RTLD_NEXT
    5451
    55         return do_interpose_symbol(library, symbol, version);
     52        return do_interpose_symbol( library, symbol, version );
    5653}
    5754
     
    8178#pragma GCC diagnostic push
    8279#pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
    83                 INTERPOSE( pthread_create , version );
    84                 INTERPOSE( pthread_join , version );
    85                 INTERPOSE( pthread_self , version );
    86                 INTERPOSE( pthread_attr_init , version );
    87                 INTERPOSE( pthread_attr_destroy , version );
    88                 INTERPOSE( pthread_attr_setstack , version );
    89                 INTERPOSE( pthread_attr_getstacksize , version );
    90                 INTERPOSE( pthread_sigmask , version );
    91                 INTERPOSE( pthread_sigqueue , version );
    92                 INTERPOSE( pthread_once , version );
     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 );
    9390#pragma GCC diagnostic pop
    9491        }
Note: See TracChangeset for help on using the changeset viewer.