Ignore:
Timestamp:
Sep 21, 2022, 11:56:16 AM (2 years ago)
Author:
Thierry Delisle <tdelisle@…>
Branches:
ADT, ast-experimental, master, pthread-emulation
Children:
9cd5bd2
Parents:
7f6a7c9
Message:

Changed real_pthread symbols (now cfaabi_pthread) to be protected in libcfathread

File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/interpose.cfa

    r7f6a7c9 r95dab9e  
    4242
    4343typedef void (* generic_fptr_t)(void);
     44static generic_fptr_t do_interpose_symbol( void * library, const char symbol[], const char version[] ) {
     45        const char * error;
     46
     47        union { generic_fptr_t fptr; void * ptr; } originalFunc;
     48
     49        #if defined( _GNU_SOURCE )
     50                if ( version ) {
     51                        originalFunc.ptr = dlvsym( library, symbol, version );
     52                } else {
     53                        originalFunc.ptr = dlsym( library, symbol );
     54                }
     55        #else
     56                originalFunc.ptr = dlsym( library, symbol );
     57        #endif // _GNU_SOURCE
     58
     59        error = dlerror();
     60        if ( error ) abort( "interpose_symbol : internal error, %s\n", error );
     61
     62        return originalFunc.fptr;
     63}
     64
    4465static generic_fptr_t interpose_symbol( const char symbol[], const char version[] ) {
    4566        const char * error;
     
    7293        } // if
    7394
    74         union { generic_fptr_t fptr; void * ptr; } originalFunc;
    75 
    76         #if defined( _GNU_SOURCE )
    77                 if ( version ) {
    78                         originalFunc.ptr = dlvsym( library, symbol, version );
    79                 } else {
    80                         originalFunc.ptr = dlsym( library, symbol );
    81                 }
    82         #else
    83                 originalFunc.ptr = dlsym( library, symbol );
    84         #endif // _GNU_SOURCE
    85 
    86         error = dlerror();
    87         if ( error ) {
    88                 originalFunc.ptr = dlsym( pthread_library, symbol );
    89                 error = dlerror();
    90                 if (error){
    91                         abort( "interpose_symbol : internal error, %s\n", error );
    92                 }       // if
    93         }       // if
    94 
    95         return originalFunc.fptr;
     95        return do_interpose_symbol(library, symbol, version);
    9696}
    9797
     
    111111        void (* exit)( int ) __attribute__(( __noreturn__ ));
    112112        void (* abort)( void ) __attribute__(( __noreturn__ ));
    113         typeof(pthread_create) pthread_create;
    114         typeof(pthread_join) pthread_join;
    115         typeof(pthread_self) pthread_self;
    116         typeof(pthread_attr_init) pthread_attr_init;
    117         typeof(pthread_attr_setstack ) pthread_attr_setstack;
    118         typeof(pthread_attr_destroy) pthread_attr_destroy;
    119         typeof(pthread_attr_getstacksize) pthread_attr_getstacksize;
    120         typeof(pthread_sigmask) pthread_sigmask;
    121         typeof(pthread_sigqueue) pthread_sigqueue;
     113        int (*pthread_create)(pthread_t *_thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
     114        int (*pthread_join)(pthread_t _thread, void **retval);
     115        pthread_t (*pthread_self)(void);
     116        int (*pthread_attr_init)(pthread_attr_t *attr);
     117        int (*pthread_attr_destroy)(pthread_attr_t *attr);
     118        int (*pthread_attr_setstack)( pthread_attr_t *attr, void *stackaddr, size_t stacksize );
     119        int (*pthread_attr_getstacksize)( const pthread_attr_t *attr, size_t *stacksize );
     120        int (*pthread_sigmask)(int how, const sigset_t *set, sigset_t *oldset);
     121        int (*pthread_sigqueue)(pthread_t _thread, int sig, const union sigval value);
    122122} __cabi_libc;
    123123
     
    125125
    126126extern "C" {
     127        void __cfathreadabi_interpose_startup( generic_fptr_t (*do_interpose_symbol)( void * library, const char symbol[], const char version[] ) ) __attribute__((weak));
    127128        void __cfaabi_interpose_startup( void ) {
    128129                const char *version = 0p;
     
    135136                INTERPOSE_LIBC( abort, version );
    136137                INTERPOSE_LIBC( exit , version );
    137                 INTERPOSE_LIBC( pthread_create , version );
    138                 INTERPOSE_LIBC( pthread_join , version );
    139                 INTERPOSE_LIBC( pthread_self , version );
    140                 INTERPOSE_LIBC( pthread_attr_init , version );
    141                 INTERPOSE_LIBC( pthread_attr_destroy , version );
    142                 INTERPOSE_LIBC( pthread_attr_setstack , version );
    143                 INTERPOSE_LIBC( pthread_attr_getstacksize , version );
    144                 INTERPOSE_LIBC( pthread_sigmask , version );
    145                 INTERPOSE_LIBC( pthread_sigqueue , version );
    146138#pragma GCC diagnostic pop
     139
     140                if(__cfathreadabi_interpose_startup) __cfathreadabi_interpose_startup( do_interpose_symbol );
    147141
    148142                // As a precaution (and necessity), errors that result in termination are delivered on a separate stack because
     
    204198        libcfa_public void exit( int status ) __attribute__(( __nothrow__, __leaf__, __noreturn__ )) {
    205199                __cabi_libc.exit( status );
    206         }
    207 
    208         libcfa_public int real_pthread_create(pthread_t *_thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg){
    209                 return __cabi_libc.pthread_create(_thread, attr, start_routine, arg);
    210         }
    211 
    212         libcfa_public int real_pthread_join(pthread_t _thread, void **retval){
    213                 return __cabi_libc.pthread_join(_thread, retval);
    214         }
    215 
    216         libcfa_public pthread_t real_pthread_self(void){
    217                 return __cabi_libc.pthread_self();
    218         }
    219         libcfa_public int real_pthread_attr_init(pthread_attr_t *attr){
    220                 return __cabi_libc.pthread_attr_init(attr);
    221         }
    222         libcfa_public int real_pthread_attr_destroy(pthread_attr_t *attr){
    223                 return __cabi_libc.pthread_attr_destroy(attr);
    224         }
    225         libcfa_public int real_pthread_attr_setstack( pthread_attr_t *attr, void *stackaddr, size_t stacksize ){
    226                 return __cabi_libc.pthread_attr_setstack(attr, stackaddr, stacksize);
    227         }
    228         libcfa_public int read_pthread_attr_getstacksize( const pthread_attr_t *attr, size_t *stacksize ){
    229                 return __cabi_libc.pthread_attr_getstacksize(attr, stacksize);
    230         }
    231         libcfa_public int real_pthread_sigmask(int how, const sigset_t *set, sigset_t *oldset){
    232                 return __cabi_libc.pthread_sigmask(how, set, oldset);
    233         }
    234         libcfa_public int real_pthread_sigqueue(pthread_t _thread, int sig, const union sigval value){
    235                 return __cabi_libc.pthread_sigqueue(_thread, sig, value);
    236200        }
    237201}
Note: See TracChangeset for help on using the changeset viewer.