Ejemplo n.º 1
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.º 2
0
Archivo: ppldso.c Proyecto: gozfree/src
ppl_status_t
ppl_dso_unload (ppl_dso_handle_t * thedso)
{
  ppl_dso_handle_t *dso = thedso;

  if (dso->handle == NULL)
    {
      osip_free (dso);
      return PPL_SUCCESS;
    }
#if defined(DSO_USE_SHL)
  shl_unload ((shl_t) dso->handle);
#elif defined(DSO_USE_DYLD)
  NSUnLinkModule (dso->handle, FALSE);
#elif defined(DSO_USE_DLFCN)
  if (dlclose (dso->handle) != 0)
    {
      osip_free (dso);
      return PPL_EINIT;
    }
#endif
  dso->handle = NULL;
  osip_free (dso);
  return PPL_SUCCESS;
}
Ejemplo n.º 3
0
Archivo: dlopen.c Proyecto: 1ack/Impala
int
dlclose(dll_handle h)
{
    shl_t hp = *((shl_t *)h);
    if (hp != NULL) free(hp);
    return shl_unload(h);
}
Ejemplo n.º 4
0
static int dl_load(DSO *dso, const char *filename)
	{
	shl_t ptr;
	char translated[DSO_MAX_TRANSLATED_SIZE];
	int len;

	/* The same comment as in dlfcn_load applies here. bleurgh. */
	len = strlen(filename) + strlen(extension);
	if((dso->flags & DSO_FLAG_NAME_TRANSLATION) &&
			(len + 3 < DSO_MAX_TRANSLATED_SIZE) &&
			(strstr(filename, "/") == NULL))
		{
		sprintf(translated, "lib%s%s", filename, extension);
		ptr = shl_load(translated, BIND_IMMEDIATE, NULL);
		}
	else
		ptr = shl_load(filename, BIND_IMMEDIATE, NULL);
	if(ptr == NULL)
		{
		DSOerr(DSO_F_DL_LOAD,DSO_R_LOAD_FAILED);
		return(0);
		}
	if(!sk_push(dso->meth_data, (char *)ptr))
		{
		DSOerr(DSO_F_DL_LOAD,DSO_R_STACK_ERROR);
		shl_unload(ptr);
		return(0);
		}
	return(1);
	}
Ejemplo n.º 5
0
void *dlopen(const char *fname, int mode)
{
  shl_t handle;
  LibEntry entry = NULL;

  dlerrno = 0;
  if (fname == NULL)
    handle = PROG_HANDLE;
  else {
    handle = shl_load(fname, mode | BIND_VERBOSE, 0L);
    if (handle != NULL) {
      if ((entry = find_lib_entry(handle)) == NULL) {
	if ((entry = new_lib_entry(handle)) == NULL) {
	  shl_unload(handle);
	  handle = NULL;
	}
      }
      else
	increment_lib_entry_count(entry);
    }
    if (handle == NULL) {
      dlerrno = 1;
      sprintf(errbuf, "can't open %s", fname);
    }
  }
#ifdef DEBUG
  printf("opening library %s, handle = %x, count = %d\n",
	 fname, handle, entry ? lib_entry_count(entry) : -1);
  if (dlerrno) printf("%s\n", dlerror());
#endif
  return (void *) handle;
}
Ejemplo n.º 6
0
int dlclose(void *handle)
{
  LibEntry entry;
#ifdef DEBUG
  entry = find_lib_entry(handle);
  printf("closing library handle = %x, count = %d\n",
	 handle, entry ? lib_entry_count(entry) : -1);
#endif

  dlerrno = 0;
  if ((shl_t) handle == PROG_HANDLE)
    return 0; /* ignore attempts to close main program */
  else {

    if ((entry = find_lib_entry((shl_t) handle)) != NULL) {
      decrement_lib_entry_count(entry);
      if (lib_entry_count(entry) > 0)
	return 0;
      else {
	/* unload once reference count reaches zero */
	free_lib_entry(entry);
	if (shl_unload((shl_t) handle) == 0)
	  return 0;
      }
    }
    /* if you get to here, an error has occurred */
    dlerrno = 1;
    sprintf(errbuf, "attempt to close library failed");
#ifdef DEBUG
    printf("%s\n", dlerror());
#endif
    return -1;
  }
}
Ejemplo n.º 7
0
bool QLibraryPrivate::unload_sys()
{
    if (shl_unload((shl_t)pHnd)) {
        qWarning("QLibrary: Cannot unload %s", QFile::encodeName(fileName).constData());
        return false;
    }
    return true;
}
Ejemplo n.º 8
0
void 
unloadSharedObject (void *object) {
#ifdef HAVE_SHL_LOAD
  if (shl_unload(object) == -1)
    logMessage(LOG_ERR, "Shared library unload error: %s",
               strerror(errno));
#endif /* HAVE_SHL_LOAD */
}
Ejemplo n.º 9
0
static void dClose(void * handle)
{
#ifdef __hpux
       shl_unload(handle);
#else
       dlclose(handle);
#endif
}
Ejemplo n.º 10
0
void
sane_exit (void)
{
  struct backend *be, *next;
  struct alias *alias;

  DBG(2, "sane_exit: exiting\n");

  for (be = first_backend; be; be = next)
    {
      next = be->next;
      if (be->loaded)
        {
          DBG(3, "sane_exit: calling backend `%s's exit function\n", be->name);
          (*be->op[OP_EXIT]) ();
#ifdef HAVE_DLL

#ifdef HAVE_DLOPEN
          if (be->handle)
            dlclose (be->handle);
#elif defined(HAVE_SHL_LOAD)
          if (be->handle)
            shl_unload(be->handle);
#else
# error "Tried to compile unsupported DLL."
#endif /* HAVE_DLOPEN */

#endif /* HAVE_DLL */
        }
      if (!be->permanent)
        {
          if (be->name)
            free ((void *) be->name);
          free (be);
        }
    }
  first_backend = 0;

  while( (alias = first_alias) != NULL )
    {
      first_alias = first_alias->next;
      free(alias->oldname);
      free(alias);
    }

  if (NULL != devlist)
    { /* Release memory allocated by sane_get_devices(). */
      int i = 0;
      while (devlist[i])
        free(devlist[i++]);
      free(devlist);

      devlist = NULL;
      devlist_size = 0;
      devlist_len = 0;
    }
  DBG(3, "sane_exit: finished\n");
}
Ejemplo n.º 11
0
void ap_os_dso_unload(void *handle) 
{
#if defined(HPUX) || defined(HPUX10)
    shl_unload((shl_t)handle);
#else
    dlclose(handle);
#endif
    return;
}
Ejemplo n.º 12
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.º 13
0
static void
_g_module_close (gpointer handle,
                 gboolean is_unref)
{
    if (!is_unref)
    {
        if (shl_unload ((shl_t) handle) != 0)
            g_module_set_error (g_strerror (errno));
    }
}
Ejemplo n.º 14
0
/******************************************************************
 *
 * Porting Free library function to different platforms 
 *
 *******************************************************************/
void myFreeLibrary(HINSTANCE hKVFILTER)
{
#if defined(_WINDOWS)
     FreeLibrary( hKVFILTER );
#elif defined(_HPUX11)
     shl_unload((shl_t)hKVFILTER);
#else
     dlclose(hKVFILTER);
#endif
}
void
TclpUnloadFile(
    Tcl_LoadHandle loadHandle)	/* loadHandle returned by a previous call to
				 * TclpDlopen(). The loadHandle is a token
				 * that represents the loaded file. */
{
    shl_t handle;

    handle = (shl_t) loadHandle;
    shl_unload(handle);
}
Ejemplo n.º 16
0
			void unload_library() {
#if defined(LINUX) || defined(SUN) || defined(AIX) || defined(CYGWIN)
				dlclose(handle_);
#elif defined(HP)
				shl_unload(handle_);
#else
				/* This type of UNIX has no DLL support yet */
				throw dll_exception("Unsupported Unix flavour (please report this): " + module_.string());
#endif

			}
Ejemplo n.º 17
0
void SharedLibraryImpl::unloadImpl()
{
	FastMutex::ScopedLock lock(_mutex);

	if (_handle)
	{
		shl_unload(_handle);
		_handle = 0;
		_path.clear();
	}
}
Ejemplo n.º 18
0
/* A function called through the vtable when a particular module
   should be unloaded.  */
static int
vm_close (lt_user_data LT__UNUSED loader_data, lt_module module)
{
  int errors = 0;

  if (module && (shl_unload ((shl_t) (module)) != 0))
    {
      LT__SETERROR (CANNOT_CLOSE);
      ++errors;
    }

  return errors;
}
Ejemplo n.º 19
0
// Close DLL of given dllhandle
void fxdllClose(void* dllhandle){
  if(dllhandle){
#ifndef WIN32
#ifdef HAVE_SHL_LOAD    // HP-UX
    shl_unload((shl_t)dllhandle);
#else			// POSIX
    dlclose(dllhandle);
#endif
#else                   // WIN32
    FreeLibrary((HMODULE)dllhandle);
#endif
    }
  }
Ejemplo n.º 20
0
Archivo: XlcDL.c Proyecto: iquiw/xsrc
static void
close_object(XI18NObjectsList object)
{
    object->refcount--;
    if (object->refcount == 0)
    {
#if defined(hpux)
        shl_unload(object->dl_module);
#else
        dlclose(object->dl_module);
#endif
        object->dl_module = NULL;
    }
}
Ejemplo n.º 21
0
bool QLibraryPrivate::unload_sys()
{
#if !defined(Q_OS_VXWORKS)
#  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_MAC
Q_CORE_EXPORT void *qt_mac_resolve_sys(void *handle, const char *symbol)
{
    return dlsym(handle, symbol);
}
#endif

void* 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);
    void* address = dlsym(pHnd, undrscr_symbol);
    delete [] undrscr_symbol;
#elif defined(QT_HPUX_LD)
    void* address = 0;
    if (shl_findsym((shl_t*)&pHnd, symbol, TYPE_UNDEFINED, &address) < 0)
        address = 0;
#elif defined(Q_OS_VXWORKS)
    void *address = 0;
#else
    void* address = dlsym(pHnd, symbol);
#endif
    if (!address) {
        errorString = QLibrary::tr("Cannot resolve symbol \"%1\" in %2: %3").arg(
                          QString::fromAscii(symbol)).arg(fileName).arg(qdlerror());
    } else {
        errorString.clear();
    }
    return address;
}
Ejemplo n.º 22
0
Boolean DynamicLibrary::unload(void)
{
    // ensure the module is loaded
    PEGASUS_ASSERT(isLoaded() == true);

    // decrement handle is valid and release the library only if the handle reference count is 0
    if((_handle != 0) && (_decrement_handle(_handle) == 0))
    {
        shl_unload(reinterpret_cast<shl_t>(_handle));
    }

    _handle = 0;

    return(isLoaded());
}
Ejemplo n.º 23
0
void
Yap_ShutdownLoadForeign( void )
{
  ForeignObj *f_code;
  int err;

  f_code = ForeignCodeLoaded;
  while( f_code != NULL ) {
    StringList objs, libs;
    
    objs = f_code->objs;
    while( objs ) {
      err = shl_unload( *(shl_t *)objs->handle );
      if( err ) {
	/* dunno how to properly report an error here */
	perror( NULL );
	return;
      }
      Yap_FreeCodeSpace( objs->handle );
      objs = objs->next;
    }

    libs = f_code->libs;
    while( libs ) {
      err = shl_unload( *(shl_t *)libs->handle );
      if( err ) {
	/* dunno how to properly report an error here */
	perror( NULL );
	return;
      }
      Yap_FreeCodeSpace( libs->handle );
      libs = libs->next;
    }
    f_code = f_code->next;
  }
}
Ejemplo n.º 24
0
GError GPlugLoader::UnloadPlug() {

    if (gPlugHandle) {
		#if defined(G_OS_WIN) && !defined(__CYGWIN__)
			FreeLibrary((HMODULE)gPlugHandle);
		#elif defined(G_OS_HPUX)
			// fortunately, shl_t is a pointer
			shl_unload(static_cast<shl_t>(gPlugHandle));
		#else // other unix (it works also on MacOSX and Tiger)
			dlclose(gPlugHandle);
		#endif    
		gPlugHandle = NULL;
		return G_NO_ERROR;
    }
	return G_PLUGIN_NOTLOADED;
}
Ejemplo n.º 25
0
int DYN_CloseLibrary(void **pvLHandle)
{

    int rv;

    rv = shl_unload((shl_t) * pvLHandle);
    *pvLHandle = 0;

    if (rv == -1)
    {
        Log2(PCSC_LOG_ERROR, "%s", strerror(errno));
        return SCARD_F_UNKNOWN_ERROR;
    }

    return SCARD_S_SUCCESS;
}
Ejemplo n.º 26
0
/* static */
void wxDynamicLibrary::Unload(wxDllType handle)
{
#ifdef wxHAVE_DYNLIB_ERROR
    int rc =
#endif

#ifdef USE_POSIX_DL_FUNCS
    dlclose(handle);
#else // !USE_POSIX_DL_FUNCS
    shl_unload(handle);
#endif // USE_POSIX_DL_FUNCS/!USE_POSIX_DL_FUNCS

#if defined(USE_POSIX_DL_FUNCS) && defined(wxHAVE_DYNLIB_ERROR)
    if ( rc != 0 )
        Error();
#endif
}
Ejemplo n.º 27
0
OSCodeFragment::~OSCodeFragment()
{
    if (fFragmentP == NULL)
        return;
        
#if defined(HPUX) || defined(HPUX10)
    shl_unload((shl_t)fFragmentP);
#elif defined(__Win32__)
    BOOL theErr = ::FreeLibrary(fFragmentP);
    Assert(theErr);
#elif defined(__MacOSX__)
    CFBundleUnloadExecutable( fFragmentP );
    CFRelease( fFragmentP );
#else
    dlclose(fFragmentP);
#endif
}
Ejemplo n.º 28
0
Archivo: dlopen.c Proyecto: 1ack/Impala
dll_handle
dlopen(char *fname, int mode)
{
    shl_t h = shl_load(fname, BIND_DEFERRED, 0L);
    shl_t *hp = NULL;
    
    if (h) {
	hp = (shl_t *)malloc(sizeof (shl_t));
	if (!hp) {
	    shl_unload(h);
	} else {
	    *hp = h;
	}
    }

    return (dll_handle)hp;
}
Ejemplo n.º 29
0
static int dl_load(DSO *dso)
{
    shl_t ptr = NULL;
    /*
     * We don't do any fancy retries or anything, just take the method's (or
     * DSO's if it has the callback set) best translation of the
     * platform-independent filename and try once with that.
     */
    char *filename = DSO_convert_filename(dso, NULL);

    if (filename == NULL) {
        DSOerr(DSO_F_DL_LOAD, DSO_R_NO_FILENAME);
        goto err;
    }
    ptr = shl_load(filename, BIND_IMMEDIATE |
                   (dso->flags & DSO_FLAG_NO_NAME_TRANSLATION ? 0 :
                    DYNAMIC_PATH), 0L);
    if (ptr == NULL) {
        char errbuf[160];
        DSOerr(DSO_F_DL_LOAD, DSO_R_LOAD_FAILED);
        if (openssl_strerror_r(errno, errbuf, sizeof(errbuf)))
            ERR_add_error_data(4, "filename(", filename, "): ", errbuf);
        goto err;
    }
    if (!sk_push(dso->meth_data, (char *)ptr)) {
        DSOerr(DSO_F_DL_LOAD, DSO_R_STACK_ERROR);
        goto err;
    }
    /*
     * Success, stick the converted filename we've loaded under into the DSO
     * (it also serves as the indicator that we are currently loaded).
     */
    dso->loaded_filename = filename;
    return (1);
 err:
    /* Cleanup! */
    OPENSSL_free(filename);
    if (ptr != NULL)
        shl_unload(ptr);
    return (0);
}
Ejemplo n.º 30
0
Archivo: os.c Proyecto: FLYKingdom/vlc
/**
 * CloseModule: unload a dynamic library
 *
 * This function unloads a previously opened dynamically linked library
 * using a system dependent method. No return value is taken in consideration,
 * since some libraries sometimes refuse to close properly.
 * \param handle handle of the library
 * \return nothing
 */
void module_Unload( module_handle_t handle )
{
#if defined(HAVE_DL_BEOS)
    unload_add_on( handle );

#elif defined(HAVE_DL_WINDOWS)
    FreeLibrary( handle );

#elif defined(HAVE_DL_DLOPEN)
# ifdef HAVE_VALGRIND_VALGRIND_H
    if( RUNNING_ON_VALGRIND > 0 )
        return; /* do not dlclose() so that we get proper stack traces */
# endif
    dlclose( handle );

#elif defined(HAVE_DL_SHL_LOAD)
    shl_unload( handle );

#endif
    return;
}