Ejemplo n.º 1
0
DynamicLibrary::LIBRARY_SYMBOL DynamicLibrary::getSymbol(const String & symbolName)
{
    LIBRARY_SYMBOL func = 0;

    if(isLoaded())
    {
        CString cstr = symbolName.getCString();

        if(shl_findsym((shl_t *)&_handle, cstr, TYPE_UNDEFINED, &func) == 0)
        {
            return(func);
        }

        // NOTE: should the underscore be prepended by the caller or should
        // this be a compile time option?

        cstr = String(String("_") + symbolName).getCString();

        if(shl_findsym((shl_t *)_handle, cstr, TYPE_UNDEFINED, &func) == 0)
        {
            return(func);
        }
    }

    return(0);
}
Ejemplo n.º 2
0
void*   OSCodeFragment::GetSymbol(const char* inSymbolName)
{
    if (fFragmentP == NULL)
        return NULL;
        
#if defined(HPUX) || defined(HPUX10)
    void *symaddr = NULL;
    int status;

    errno = 0;
    status = shl_findsym((shl_t *)&fFragmentP, symname, TYPE_PROCEDURE, &symaddr);
    if (status == -1 && errno == 0) /* try TYPE_DATA instead */
        status = shl_findsym((shl_t *)&fFragmentP, inSymbolName, TYPE_DATA, &symaddr);
    return (status == -1 ? NULL : symaddr);
#elif defined(DLSYM_NEEDS_UNDERSCORE)
    char *symbol = (char*)malloc(sizeof(char)*(strlen(inSymbolName)+2));
    void *retval;
    qtss_sprintf(symbol, "_%s", inSymbolName);
    retval = dlsym(fFragmentP, symbol);
    free(symbol);
    return retval;
#elif defined(__Win32__)
    return ::GetProcAddress(fFragmentP, inSymbolName);
#elif defined(__MacOSX__)
    CFStringRef theString = CFStringCreateWithCString( kCFAllocatorDefault, inSymbolName, kCFStringEncodingASCII);
    void* theSymbol = (void*)CFBundleGetFunctionPointerForName( fFragmentP, theString );
    CFRelease(theString);
    return theSymbol;
#else
    return dlsym(fFragmentP, inSymbolName);
#endif  
}
Tcl_PackageInitProc *
TclpFindSymbol(
    Tcl_Interp *interp,
    Tcl_LoadHandle loadHandle,
    CONST char *symbol)
{
    Tcl_DString newName;
    Tcl_PackageInitProc *proc = NULL;
    shl_t handle = (shl_t)loadHandle;

    /*
     * Some versions of the HP system software still use "_" at the beginning
     * of exported symbols while others don't; try both forms of each name.
     */

    if (shl_findsym(&handle, symbol, (short) TYPE_PROCEDURE,
	    (void *) &proc) != 0) {
	Tcl_DStringInit(&newName);
	Tcl_DStringAppend(&newName, "_", 1);
	Tcl_DStringAppend(&newName, symbol, -1);
	if (shl_findsym(&handle, Tcl_DStringValue(&newName),
		(short) TYPE_PROCEDURE, (void *) &proc) != 0) {
	    proc = NULL;
	}
	Tcl_DStringFree(&newName);
    }
    return proc;
}
Ejemplo n.º 4
0
static int
xmlModulePlatformSymbol(void *handle, const char *name, void **symbol)
{
    int rc;

    errno = 0;
    rc = shl_findsym(handle, name, TYPE_PROCEDURE, symbol);
    if ((-1 == rc) && (0 == errno)) {
        rc = shl_findsym(handle, name, TYPE_DATA, symbol);
    }
    return rc;
}
Ejemplo n.º 5
0
int main ()
{
  shl_t  solib_handle;
  int  dummy;
  int  status;
  int  (*solib_main) (int);

  /* Load a shlib, with immediate binding of all symbols.

     Note that the pathname of the loaded shlib is assumed to be relative
     to the testsuite directory (from whence the tested GDB is run), not
     from dot/.
   */
  dummy = 1;  /* Put some code between shl_ calls... */
  solib_handle = shl_load ("gdb.base/solib1.sl", BIND_IMMEDIATE, 0);

  /* Find a function within the shlib, and call it. */
  status = shl_findsym (&solib_handle,
                        "solib_main",
                        TYPE_PROCEDURE,
                        (long *) &solib_main);
  status = (*solib_main) (dummy);

  /* Unload the shlib. */
  status = shl_unload (solib_handle);

  /* Load a different shlib, with deferred binding of all symbols. */
  dummy = 2;
  solib_handle = shl_load ("gdb.base/solib2.sl", BIND_DEFERRED, 0);

  /* Find a function within the shlib, and call it. */
  status = shl_findsym (&solib_handle,
                        "solib_main",
                        TYPE_PROCEDURE,
                        (long *) &solib_main);
  status = (*solib_main) (dummy);

  /* Unload the shlib. */
  status = shl_unload (solib_handle);

  /* Reload the first shlib again, with deferred symbol binding this time. */
  dummy = 3;
  solib_handle = shl_load ("gdb.base/solib1.sl", BIND_IMMEDIATE, 0);

  /* Unload it without trying to find any symbols in it. */
  status = shl_unload (solib_handle);

  /* All done. */
  dummy = -1;
  return 0;
}
Ejemplo n.º 6
0
GError GPlugLoader::ResolveSymbol(const GChar8 *SymbolName, GPlugSymbolAddress *ResolvedSymbol) const {

	void *result = NULL;

	if ((!SymbolName) || (!ResolvedSymbol))
		return G_INVALID_PARAMETER;
    if (!gPlugHandle)
		return G_PLUGIN_NOTLOADED;
	#if defined(G_OS_WIN) && !defined(__CYGWIN__)
		result = (GPlugSymbolAddress)GetProcAddress((HMODULE)gPlugHandle, SymbolName);
		if (!result)
			return G_PLUGIN_SYMBOL_UNRESOLVED;
		*ResolvedSymbol = result;
		return G_NO_ERROR;
	#elif defined(G_OS_HPUX)
		if (shl_findsym (reinterpret_cast<shl_t*>(&gPlugHandle), SymbolName, TYPE_PROCEDURE, result) == 0) {
			*ResolvedSymbol = result;
			return G_NO_ERROR;
		}
		return G_PLUGIN_SYMBOL_UNRESOLVED;
	#else // other unix (it works also on MacOSX and Tiger)
		result = dlsym(gPlugHandle,  SymbolName);
		if (!result)
			return G_PLUGIN_SYMBOL_UNRESOLVED;
		*ResolvedSymbol = result;
		return G_NO_ERROR;
	#endif
}
Ejemplo n.º 7
0
void *vmddlsym( void *handle, const char *sym ) {
    void *value=0;

    if ( shl_findsym( (shl_t*)&handle, sym, TYPE_UNDEFINED, &value ) != 0 )
        return 0;
    return value;
}
Ejemplo n.º 8
0
static void *dl_globallookup(const char *name)
{
    void *ret;
    shl_t h = NULL;

    return shl_findsym(&h, name, TYPE_UNDEFINED, &ret) ? NULL : ret;
}
Ejemplo n.º 9
0
//==========================================================================================
static DLL_EP dll_entrypoint( DLL *dll, const char *name )
{
#if defined(_WIN32) || defined(WIN32) || defined(__WIN32__)
    
    FARPROC proc;
    
    proc = GetProcAddress( (HMODULE) dll, (LPCSTR) name );
    if( proc == NULL )
    {
        printf( "Failed to load %s. Error code %d\n", name, GetLastError() );
    }
    return (DLL_EP) proc;
    
#else // UNIX

#if defined LINUX  || defined SUN || defined MACOSX
	void *handle = (void *) dll;
	DLL_EP ep;
	ep = (DLL_EP) dlsym(handle, name);
	return ( dlerror() == 0 ) ? ep : (DLL_EP) NULL;

#elif defined HP || defined HPUX
	shl_t handle = (shl_t) dll;
	DLL_EP ep;
	return shl_findsym(&handle, name, TYPE_PROCEDURE, &ep) == -1 ?
		(DLL_EP) NULL : ep;
#else

	void *handle = (void *) dll;
	DLL_EP ep;
	ep = (DLL_EP) dlsym(handle, name);
	return ( dlerror() == 0 ) ? ep : (DLL_EP) NULL;
#endif
#endif
}	
Ejemplo n.º 10
0
/**************************************************************************
 * Name: FindProcedure
 *
 * Description: Mapping functions to the matching one in libsend_to_ths library.
 *
 * Inputs:  procedure name
 *          Address of the mapping procedure
 * Outputs: None
 *
 * Returns:	SUUCESS/FAILURE
 ************************************************************************* */
int FindProcedure(const char* procedure, void* libPointer, void** procAddress, char* errstr)
{
   int err = 0;
   char procedure_err[128];
   *procAddress = NULL;
#if defined(WIN32)
   *procAddress = GetProcAddress( (HINSTANCE)libPointer, procedure);
#elif defined(SOLARIS) || defined(OSF1) || defined(HPUX_64) || defined(_AIX) || defined(LINUX)
   *procAddress = dlsym( libPointer, procedure);
#elif defined(HPUX)
  err = shl_findsym( (shl_t *)&libPointer, procedure, TYPE_PROCEDURE, procAddress);
  if ( err != 0)
  {
     *procAddress = NULL;
  }
#else
#error THSlibLoader not defined for this platform you must define it now FindProcedure
#endif
   if (NULL == *procAddress)
   {
      sprintf(procedure_err, "Could not load procedure %s, Please check your library ...", procedure);
      strcpy(errstr, procedure_err);
      /* emit(SHLIB_ERRLOC, MPS_GENERIC_DEBUG, procedure_err); */
      return FAILURE;
   }
   return SUCCESS; 
}
Ejemplo n.º 11
0
/* Look for an object with the given name in the named file and return a
   callable "<c-function>" object for it. */
obj_t find_c_function(obj_t /* <string> */ symbol, obj_t lookup)
{
    const char *string = string_chars(symbol);
    struct symtab *syms;
    int sym_count, i;
    obj_t retval = obj_False;

    if (lookup == obj_Unbound) {
        if (mindy_dynamic_syms == NULL)
            mindy_dynamic_syms = load_program_file();
        return find_c_function(symbol, mindy_dynamic_syms);
    } else if (lookup == obj_False)
        return obj_False;
    else if (!instancep(lookup, obj_ForeignFileClass)) {
        error("Keyword file: is not a <foreign-file>: %=", lookup);
        return retval;                /* make lint happy */
    } else if (instancep(lookup, obj_SharedFileClass)) {
        shl_t *files = obj_ptr(struct shared_file *, lookup)->handles;
        int file_count = obj_ptr(struct shared_file *, lookup)->file_count;
        void *ptr;

        for (i = 0; i < file_count; i++)
            if (shl_findsym(&files[i], string, &ptr) == 0)
                return(make_c_function(make_byte_string(string), ptr));
        return retval;
    } else {
Ejemplo n.º 12
0
static gpointer
_g_module_symbol (gpointer     handle,
                  const gchar *symbol_name)
{
    gpointer p = NULL;

    /* should we restrict lookups to TYPE_PROCEDURE?
     */
    if (handle == PROG_HANDLE)
    {
        /* PROG_HANDLE will only lookup symbols in the program itself, not honouring
         * libraries. passing NULL as a handle will also try to lookup the symbol
         * in currently loaded libraries. fix pointed out and supplied by:
         * David Gero <*****@*****.**>
         */
        handle = NULL;
    }
    if (shl_findsym ((shl_t*) &handle, symbol_name, TYPE_UNDEFINED, &p) != 0 ||
            handle == NULL || p == NULL)
    {
        /* the hp-docs say we should better abort() if errno==ENOSYM ;( */
        g_module_set_error (g_strerror (errno));
    }

    return p;
}
Ejemplo n.º 13
0
dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
				    const char *pathname, FILE *fp)
{
	dl_funcptr p;
	shl_t lib;
	int flags;
	char funcname[258];

	flags = BIND_FIRST | BIND_DEFERRED;
	if (Py_VerboseFlag) {
		flags = DYNAMIC_PATH | BIND_FIRST | BIND_IMMEDIATE |
			BIND_NONFATAL | BIND_VERBOSE;
		printf("shl_load %s\n",pathname);
	}
	lib = shl_load(pathname, flags, 0);
	/* XXX Chuck Blake once wrote that 0 should be BIND_NOSTART? */
	if (lib == NULL) {
		char buf[256];
		if (Py_VerboseFlag)
			perror(pathname);
		sprintf(buf, "Failed to load %.200s", pathname);
		PyErr_SetString(PyExc_ImportError, buf);
		return NULL;
	}
	sprintf(funcname, FUNCNAME_PATTERN, shortname);
	if (Py_VerboseFlag)
		printf("shl_findsym %s\n", funcname);
	shl_findsym(&lib, funcname, TYPE_UNDEFINED, (void *) &p);
	if (p == NULL && Py_VerboseFlag)
		perror(funcname);

	return p;
}
Ejemplo n.º 14
0
static DSO_FUNC_TYPE dl_bind_func(DSO *dso, const char *symname)
{
    shl_t ptr;
    void *sym;

    if ((dso == NULL) || (symname == NULL)) {
        DSOerr(DSO_F_DL_BIND_FUNC, ERR_R_PASSED_NULL_PARAMETER);
        return (NULL);
    }
    if (sk_num(dso->meth_data) < 1) {
        DSOerr(DSO_F_DL_BIND_FUNC, DSO_R_STACK_ERROR);
        return (NULL);
    }
    ptr = (shl_t) sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
    if (ptr == NULL) {
        DSOerr(DSO_F_DL_BIND_FUNC, DSO_R_NULL_HANDLE);
        return (NULL);
    }
    if (shl_findsym(&ptr, symname, TYPE_UNDEFINED, &sym) < 0) {
        DSOerr(DSO_F_DL_BIND_FUNC, DSO_R_SYM_FAILURE);
        ERR_add_error_data(4, "symname(", symname, "): ", strerror(errno));
        return (NULL);
    }
    return ((DSO_FUNC_TYPE)sym);
}
Ejemplo n.º 15
0
/* A function called through the vtable to open a module with this
   loader.  Returns an opaque representation of the newly opened
   module for processing with this loader's other vtable functions.  */
static lt_module
vm_open (lt_user_data LT__UNUSED loader_data, const char *filename,
         lt_dladvise LT__UNUSED advise)
{
  static shl_t self = (shl_t) 0;
  lt_module module = shl_load (filename, LT_BIND_FLAGS, 0L);

  /* Since searching for a symbol against a NULL module handle will also
     look in everything else that was already loaded and exported with
     the -E compiler flag, we always cache a handle saved before any
     modules are loaded.  */
  if (!self)
    {
      void *address;
      shl_findsym (&self, "main", TYPE_UNDEFINED, &address);
    }

  if (!filename)
    {
      module = self;
    }
  else
    {
      module = shl_load (filename, LT_BIND_FLAGS, 0L);

      if (!module)
	{
	  LT__SETERROR (CANNOT_OPEN);
	}
    }

  return module;
}
Ejemplo n.º 16
0
static void *dl_bind_var(DSO *dso, const char *symname)
	{
	shl_t ptr;
	void *sym;

	if((dso == NULL) || (symname == NULL))
		{
		DSOerr(DSO_F_DL_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
		return(NULL);
		}
	if(sk_num(dso->meth_data) < 1)
		{
		DSOerr(DSO_F_DL_BIND_VAR,DSO_R_STACK_ERROR);
		return(NULL);
		}
	ptr = (shl_t)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
	if(ptr == NULL)
		{
		DSOerr(DSO_F_DL_BIND_VAR,DSO_R_NULL_HANDLE);
		return(NULL);
		}
	if (shl_findsym(&ptr, symname, TYPE_UNDEFINED, &sym) < 0)
		{
		DSOerr(DSO_F_DL_BIND_VAR,DSO_R_SYM_FAILURE);
		return(NULL);
		}
	return(sym);
	}
Ejemplo n.º 17
0
void *
dlsym(void *handle, const char *name)
{
  void *p;

  shl_findsym((shl_t *) & handle, name, TYPE_UNDEFINED, &p);
  return p;
}
Ejemplo n.º 18
0
void *
dlsym(void *handle, const char *symbol)
{
	void	   *value;

	if (shl_findsym((shl_t *) & handle, symbol, TYPE_PROCEDURE, &value) == -1)
		return NULL;
	return value;
}
Ejemplo n.º 19
0
PGFunction
pg_dlsym(void *handle, char *funcname)
{
	PGFunction	f;

	if (shl_findsym((shl_t *) & handle, funcname, TYPE_PROCEDURE, &f) == -1)
		f = (PGFunction) NULL;
	return f;
}
Ejemplo n.º 20
0
void *dlsym(void *handle, const char *sym)
{
	shl_t h = (shl_t)handle;
	void *address;

	if (shl_findsym(&h, sym, TYPE_UNDEFINED, &address) == 0)
			return address;
	return NULL;
}
Ejemplo n.º 21
0
static int
xmlModulePlatformSymbol(void *handle, const char *name, void **symbol)
{
    int rc;

    errno = 0;
    rc = shl_findsym(&handle, name, TYPE_UNDEFINED, symbol);
    return rc;
}
Ejemplo n.º 22
0
void*
DSO_open(char* file,char** evalstring) {
  shl_t tt_handle;
  void *d_handle,**plugin_symtab,**plugin_utiltab;
  int  rc,*iptr, (*fptr)(int);
  func_ptr *function_list;
  DSO_handle *dso_handle;
  void (*f)(void *s,void *u); /* these will just have to be void for now */
  int i;

  *evalstring=NULL;

  mm_log( (1,"DSO_open(file '%s' (0x%08X), evalstring 0x%08X)\n",file,file,evalstring) );

  if ( (tt_handle = shl_load(file, BIND_DEFERRED,0L)) == NULL) return NULL; 
  if ( (shl_findsym(&tt_handle, I_EVALSTR,TYPE_UNDEFINED,(void*)evalstring))) return NULL;

  /*
  if ( (shl_findsym(&tt_handle, "symbol_table",TYPE_UNDEFINED,(void*)&plugin_symtab))) return NULL;
  if ( (shl_findsym(&tt_handle, "util_table",TYPE_UNDEFINED,&plugin_utiltab))) return NULL;
  (*plugin_symtab)=&symbol_table;
  (*plugin_utiltab)=&i_UTIL_table;
  */

  if ( (shl_findsym(&tt_handle, I_INSTALL_TABLES ,TYPE_UNDEFINED, &f ))) return NULL; 
 
  mm_log( (1,"Calling install_tables\n") );
  f(&symbol_table,&i_UTIL_table);
  mm_log( (1,"Call ok.\n") ); 
 
  if ( (shl_findsym(&tt_handle, I_FUNCTION_LIST ,TYPE_UNDEFINED,(func_ptr*)&function_list))) return NULL; 
  if ( (dso_handle=(DSO_handle*)malloc(sizeof(DSO_handle))) == NULL) /* checked 17jul05 tonyc */
    return NULL;

  dso_handle->handle=tt_handle; /* needed to close again */
  dso_handle->function_list=function_list;
  if ( (dso_handle->filename=(char*)malloc(strlen(file)+1)) == NULL) { /* checked 17jul05 tonyc */
    free(dso_handle); return NULL;
  }
  strcpy(dso_handle->filename,file);

  mm_log((1,"DSO_open <- (0x%X)\n",dso_handle));
  return (void*)dso_handle;
}
Ejemplo n.º 23
0
bool QLibraryPrivate::unload_sys()
{
#if !defined(QT_NO_DYNAMIC_LIBRARY)
#  if defined(QT_HPUX_LD)
    if (shl_unload((shl_t)pHnd)) {
#  else
    if (dlclose(pHnd)) {
#  endif
        errorString = QLibrary::tr("Cannot unload library %1: %2").arg(fileName).arg(qdlerror());
        return false;
    }
#endif
    errorString.clear();
    return true;
}

#ifdef Q_OS_LINUX
Q_CORE_EXPORT QFunctionPointer qt_linux_find_symbol_sys(const char *symbol)
{
    return QFunctionPointer(dlsym(RTLD_DEFAULT, symbol));
}
#endif

#ifdef Q_OS_MAC
Q_CORE_EXPORT QFunctionPointer qt_mac_resolve_sys(void *handle, const char *symbol)
{
    return QFunctionPointer(dlsym(handle, symbol));
}
#endif

QFunctionPointer QLibraryPrivate::resolve_sys(const char* symbol)
{
#if defined(QT_AOUT_UNDERSCORE)
    // older a.out systems add an underscore in front of symbols
    char* undrscr_symbol = new char[strlen(symbol)+2];
    undrscr_symbol[0] = '_';
    strcpy(undrscr_symbol+1, symbol);
    QFunctionPointer address = QFunctionPointer(dlsym(pHnd, undrscr_symbol));
    delete [] undrscr_symbol;
#elif defined(QT_HPUX_LD)
    QFunctionPointer address = 0;
    if (shl_findsym((shl_t*)&pHnd, symbol, TYPE_UNDEFINED, &address) < 0)
        address = 0;
#elif defined (QT_NO_DYNAMIC_LIBRARY)
    QFunctionPointer address = 0;
#else
    QFunctionPointer address = QFunctionPointer(dlsym(pHnd, symbol));
#endif
    if (!address) {
        errorString = QLibrary::tr("Cannot resolve symbol \"%1\" in %2: %3").arg(
                          QString::fromLatin1(symbol)).arg(fileName).arg(qdlerror());
    } else {
        errorString.clear();
    }
    return address;
}
Ejemplo n.º 24
0
void *dlsym(void *_handle, const char *name)
{
  void *result;
  shl_t handle = (shl_t)_handle;

  if (!shl_findsym(&handle, name, TYPE_PROCEDURE, (void *)&result))
    return result;
  else
    return NULL;
}
Ejemplo n.º 25
0
Archivo: dlopen.c Proyecto: 1ack/Impala
dll_func
dlsym(dll_handle h, char *n)
{
    dll_func handle;
    
    if (shl_findsym ((shl_t *)h, n, TYPE_PROCEDURE, &handle))
	return NULL;
    
    return (dll_func)handle;
}
Ejemplo n.º 26
0
static void* newSymbol(void*handle,char *name)
{
#ifdef __hpux
void * addr;
     if(shl_findsym((shl_t*)&handle,name,TYPE_UNDEFINED,&addr)) return NULL;
       else return addr;
#else
      return dlsym(handle, name);
#endif
}
Ejemplo n.º 27
0
int 
findSharedSymbol (void *object, const char *symbol, const void **address) {
#ifdef HAVE_SHL_LOAD
  shl_t handle = object;
  if (shl_findsym(&handle, symbol, TYPE_UNDEFINED, address) != -1) return 1;
  logMessage(LOG_ERR, "Shared symbol '%s' not found: %s",
             symbol, strerror(errno));
#endif /* HAVE_SHL_LOAD */
  return 0;
}
Ejemplo n.º 28
0
void* SharedLibraryImpl::findSymbolImpl(const std::string& name)
{
	FastMutex::ScopedLock lock(_mutex);

	void* result = 0;
	if (_handle && shl_findsym(&_handle, name.c_str(), TYPE_UNDEFINED, &result) !=  -1)
		return result;
	else
		return 0;
}
Ejemplo n.º 29
0
func_ptr
pg_dlsym(void *handle, char *funcname)
{
    func_ptr f;

    if (shl_findsym((shl_t *) &handle, funcname, TYPE_PROCEDURE, &f) == -1) {
	f = (func_ptr) NULL;
    }
    return(f);
}
Ejemplo n.º 30
0
static void *dlsym(void *module, char *function)
{
  void *func;
  int result;
  shl_t mod = (shl_t)module;

  result = shl_findsym(&mod, function, TYPE_UNDEFINED, &func);
  if (result == -1)
    return NULL;
  return func;
}