Changeset 95dab9e


Ignore:
Timestamp:
Sep 21, 2022, 11:56:16 AM (19 months 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

Location:
libcfa/src
Files:
1 added
9 edited

Legend:

Unmodified
Added
Removed
  • libcfa/src/Makefile.am

    r7f6a7c9 r95dab9e  
    124124        concurrency/monitor.hfa \
    125125        concurrency/mutex.hfa \
    126         concurrency/thread.hfa 
     126        concurrency/thread.hfa
    127127
    128128thread_libsrc = ${inst_thread_headers_src} ${inst_thread_headers_src:.hfa=.cfa} \
     129        interpose_thread.cfa \
    129130        bits/signal.hfa \
    130131        concurrency/clib/cfathread.cfa \
  • libcfa/src/bits/defs.hfa

    r7f6a7c9 r95dab9e  
    5959void abort( bool signalAbort, const char fmt[], ... ) __attribute__ (( format(printf, 2, 3), __nothrow__, __leaf__, __noreturn__ ));
    6060extern "C" {
    61         #include <pthread.h>
    62         void __cabi_abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
    63         int real_pthread_create(pthread_t *_thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
    64         int real_pthread_join(pthread_t _thread, void **retval);
    65         pthread_t real_pthread_self(void);
    66         int real_pthread_attr_init(pthread_attr_t *attr);
    67         int real_pthread_attr_destroy(pthread_attr_t *attr);
    68         int real_pthread_attr_setstack( pthread_attr_t *attr, void *stackaddr, size_t stacksize );
    69         int real_pthread_attr_getstacksize( const pthread_attr_t *attr, size_t *stacksize );
    70         int real_pthread_sigqueue(pthread_t _thread, int sig, const union sigval value);
    71         int real_pthread_sigmask( int how, const sigset_t *set, sigset_t *oset);
     61void __cabi_abort( const char fmt[], ... ) __attribute__ (( format(printf, 1, 2), __nothrow__, __leaf__, __noreturn__ ));
    7262}
    7363#endif
  • libcfa/src/concurrency/clib/cfathread.cfa

    r7f6a7c9 r95dab9e  
    172172
    173173                pthread_attr_t attr;
    174                 if (int ret = real_pthread_attr_init(&attr); 0 != ret) {
     174                if (int ret = __cfaabi_pthread_attr_init(&attr); 0 != ret) {
    175175                        abort | "failed to create master epoll thread attr: " | ret | strerror(ret);
    176176                }
    177177
    178                 if (int ret = real_pthread_create(&master_poller, &attr, master_epoll, 0p); 0 != ret) {
     178                if (int ret = __cfaabi_pthread_create(&master_poller, &attr, master_epoll, 0p); 0 != ret) {
    179179                        abort | "failed to create master epoll thread: " | ret | strerror(ret);
    180180                }
  • libcfa/src/concurrency/io.cfa

    r7f6a7c9 r95dab9e  
    610610                if( we ) {
    611611                        sigval_t value = { PREEMPT_IO };
    612                         real_pthread_sigqueue(ctx->proc->kernel_thread, SIGUSR1, value);
     612                        __cfaabi_pthread_sigqueue(ctx->proc->kernel_thread, SIGUSR1, value);
    613613                }
    614614
  • libcfa/src/concurrency/io/setup.cfa

    r7f6a7c9 r95dab9e  
    344344        //      iopoll.run = false;
    345345        //      sigval val = { 1 };
    346         //      real_pthread_sigqueue( iopoll.thrd, SIGUSR1, val );
     346        //      __cfaabi_pthread_sigqueue( iopoll.thrd, SIGUSR1, val );
    347347
    348348        //      // Make sure all this is done
  • libcfa/src/concurrency/kernel/private.hfa

    r7f6a7c9 r95dab9e  
    4949#endif
    5050
     51extern "C" {
     52        __attribute__((visibility("protected"))) int __cfaabi_pthread_create(pthread_t *_thread, const pthread_attr_t *attr, void *(*start_routine) (void *), void *arg);
     53        __attribute__((visibility("protected"))) int __cfaabi_pthread_join(pthread_t _thread, void **retval);
     54        __attribute__((visibility("protected"))) pthread_t __cfaabi_pthread_self(void);
     55        __attribute__((visibility("protected"))) int __cfaabi_pthread_attr_init(pthread_attr_t *attr);
     56        __attribute__((visibility("protected"))) int __cfaabi_pthread_attr_destroy(pthread_attr_t *attr);
     57        __attribute__((visibility("protected"))) int __cfaabi_pthread_attr_setstack( pthread_attr_t *attr, void *stackaddr, size_t stacksize );
     58        __attribute__((visibility("protected"))) int __cfaabi_pthread_attr_getstacksize( const pthread_attr_t *attr, size_t *stacksize );
     59        __attribute__((visibility("protected"))) int __cfaabi_pthread_sigqueue(pthread_t _thread, int sig, const union sigval value);
     60        __attribute__((visibility("protected"))) int __cfaabi_pthread_sigmask( int how, const sigset_t *set, sigset_t *oset);
     61}
     62
    5163//-----------------------------------------------------------------------------
    5264// Scheduler
  • libcfa/src/concurrency/kernel/startup.cfa

    r7f6a7c9 r95dab9e  
    219219                ( this.runner ){};
    220220                init( this, "Main Processor", *mainCluster, 0p );
    221                 kernel_thread = real_pthread_self();
     221                kernel_thread = __cfaabi_pthread_self();
    222222
    223223                runner{ &this };
     
    779779        pthread_attr_t attr;
    780780
    781         check( real_pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute
     781        check( __cfaabi_pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute
    782782
    783783        size_t stacksize = max( PTHREAD_STACK_MIN, DEFAULT_STACK_SIZE );
     
    806806        #endif
    807807
    808         check( real_pthread_attr_setstack( &attr, stack, stacksize ), "pthread_attr_setstack" );
    809         check( real_pthread_create( pthread, &attr, start, arg ), "pthread_create" );
     808        check( __cfaabi_pthread_attr_setstack( &attr, stack, stacksize ), "pthread_attr_setstack" );
     809        check( __cfaabi_pthread_create( pthread, &attr, start, arg ), "pthread_create" );
    810810        return stack;
    811811}
    812812
    813813void __destroy_pthread( pthread_t pthread, void * stack, void ** retval ) {
    814         int err = real_pthread_join( pthread, retval );
     814        int err = __cfaabi_pthread_join( pthread, retval );
    815815        if( err != 0 ) abort("KERNEL ERROR: joining pthread %p caused error %s\n", (void*)pthread, strerror(err));
    816816
     
    818818                pthread_attr_t attr;
    819819
    820                 check( real_pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute
     820                check( __cfaabi_pthread_attr_init( &attr ), "pthread_attr_init" ); // initialize attribute
    821821
    822822                size_t stacksize;
    823823                // default stack size, normally defined by shell limit
    824                 check( real_pthread_attr_getstacksize( &attr, &stacksize ), "pthread_attr_getstacksize" );
     824                check( __cfaabi_pthread_attr_getstacksize( &attr, &stacksize ), "pthread_attr_getstacksize" );
    825825                assert( stacksize >= PTHREAD_STACK_MIN );
    826826                stacksize += __page_size;
  • libcfa/src/concurrency/preemption.cfa

    r7f6a7c9 r95dab9e  
    406406        sigset_t oldset;
    407407        int ret;
    408         ret = real_pthread_sigmask(0, ( const sigset_t * ) 0p, &oldset);  // workaround trac#208: cast should be unnecessary
     408        ret = __cfaabi_pthread_sigmask(0, ( const sigset_t * ) 0p, &oldset);  // workaround trac#208: cast should be unnecessary
    409409        if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); }
    410410
     
    439439        sigaddset( &mask, sig );
    440440
    441         if ( real_pthread_sigmask( SIG_UNBLOCK, &mask, 0p ) == -1 ) {
     441        if ( __cfaabi_pthread_sigmask( SIG_UNBLOCK, &mask, 0p ) == -1 ) {
    442442            abort( "internal error, pthread_sigmask" );
    443443        }
     
    450450        sigaddset( &mask, sig );
    451451
    452         if ( real_pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) {
     452        if ( __cfaabi_pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) {
    453453                abort( "internal error, pthread_sigmask" );
    454454        }
     
    458458static void preempt( processor * this ) {
    459459        sigval_t value = { PREEMPT_NORMAL };
    460         real_pthread_sigqueue( this->kernel_thread, SIGUSR1, value );
     460        __cfaabi_pthread_sigqueue( this->kernel_thread, SIGUSR1, value );
    461461}
    462462
     
    469469        sigset_t oldset;
    470470        int ret;
    471         ret = real_pthread_sigmask(0, ( const sigset_t * ) 0p, &oldset);  // workaround trac#208: cast should be unnecessary
     471        ret = __cfaabi_pthread_sigmask(0, ( const sigset_t * ) 0p, &oldset);  // workaround trac#208: cast should be unnecessary
    472472        if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); }
    473473
     
    488488        sigset_t oldset;
    489489        int ret;
    490         ret = real_pthread_sigmask(0, ( const sigset_t * ) 0p, &oldset);  // workaround trac#208: cast should be unnecessary
     490        ret = __cfaabi_pthread_sigmask(0, ( const sigset_t * ) 0p, &oldset);  // workaround trac#208: cast should be unnecessary
    491491        if(ret != 0) { abort("ERROR sigprocmask returned %d", ret); }
    492492
     
    559559        sigval val;
    560560        val.sival_int = 0;
    561         real_pthread_sigqueue( alarm_thread, SIGALRM, val );
     561        __cfaabi_pthread_sigqueue( alarm_thread, SIGALRM, val );
    562562
    563563        // Wait for the preemption thread to finish
     
    633633        static_assert( sizeof( sigset_t ) == sizeof( cxt->uc_sigmask ), "Expected cxt->uc_sigmask to be of sigset_t" );
    634634        #endif
    635         if ( real_pthread_sigmask( SIG_SETMASK, (sigset_t *)&(cxt->uc_sigmask), 0p ) == -1 ) {
     635        if ( __cfaabi_pthread_sigmask( SIG_SETMASK, (sigset_t *)&(cxt->uc_sigmask), 0p ) == -1 ) {
    636636                abort( "internal error, sigprocmask" );
    637637        }
     
    661661        sigset_t mask;
    662662        sigfillset(&mask);
    663         if ( real_pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) {
     663        if ( __cfaabi_pthread_sigmask( SIG_BLOCK, &mask, 0p ) == -1 ) {
    664664            abort( "internal error, pthread_sigmask" );
    665665        }
  • 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.