Skip to content
Snippets Groups Projects
Select Git revision
  • wip/smcv/library-cmp
  • master default
  • wip/smcv/longer-fallback-search
  • wip/smcv/config-fallback-search
  • revert-65a6e3e1
  • v0.20240916.0
  • v0.20240806.0
  • v0.20240520.0
  • v0.20230928.0
  • v0.20230802.0
  • v0.20221006.0
  • v0.20220623.0
  • v0.20211026.0
  • v0.20210906.0
  • v0.20210728.0
  • v0.20210114.0
  • v0.20210104.0
  • v0.20201120.0
  • v0.20201022.0
  • v0.20200921.0
  • v0.20200908.0
  • v0.20200708.0
  • v0.20200624.0
  • v0.20190926.0
  • v0.20190724.0
25 results

capsule-wrappers.c

Blame
  • capsule-wrappers.c 10.64 KiB
    #include "capsule/capsule.h"
    #include "capsule/capsule-private.h"
    #include "capsule/capsule-malloc.h"
    #include "utils/utils.h"
    #include "utils/ld-libs.h"
    
    #include <stddef.h>
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>
    #include <errno.h>
    #include <unistd.h>
    #include <malloc.h>
    
    static int
    dso_is_exported (const char *dsopath, char **exported)
    {
        for( char **ex = exported; ex && *ex; ex++ )
            if( soname_matches_path( *ex, dsopath ) )
                return 1;
    
        return 0;
    }
    
    static void *
    _dlsym_from_capsules (const char *symbol)
    {
        void *addr = NULL;
    
        for( size_t n = 0; n < _capsule_list->next; n++ )
        {
            capsule cap = ptr_list_nth_ptr( _capsule_list, n );
    
            if( !cap )
                continue;
    
            // TODO: If handle != cap->dl_handle, should we skip it?
            // TODO: RTLD_NEXT isn't implemented (is it implementable?)
            addr = _capsule_original_dlsym ( cap->dl_handle, symbol );
    
            if( addr )
            {
                Dl_info dso = { 0 };
    
                // only keep addr from the capsule if it's from an exported DSO:
                // or if we are unable to determine where it came from (what?)
                if( dladdr( addr, &dso ) )
                {
                    if( !dso_is_exported( dso.dli_fname, cap->ns->combined_export ) )
                        addr = NULL;
    
                    DEBUG( DEBUG_DLFUNC|DEBUG_WRAPPERS,
                           "symbol %s is from soname %s - %s",
                           symbol, dso.dli_fname, addr ? "OK" : "Ignored" );
    
                    if( addr )
                        break;
                }
            }
        }
    
        return addr;
    }
    
    static int
    _dlsymbol_is_encapsulated (const void *addr)
    {
        Dl_info dso = { 0 };
    
        // no info, symbol may not even be valid: