Select Git revision
capsule-wrappers.c
-
Vivek Das Mohapatra authored
We also need to wrap realloc() to dispatch pointers to the correct free/alloc implementation.
Vivek Das Mohapatra authoredWe also need to wrap realloc() to dispatch pointers to the correct free/alloc implementation.
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: