1998-08-09 10:32:18 +02:00
|
|
|
/* GMODULE - GLIB wrapper code for dynamic module loading
|
|
|
|
* Copyright (C) 1998 Tim Janik
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
1998-08-10 03:36:18 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
1998-08-09 10:32:18 +02:00
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
#include <dl.h>
|
|
|
|
|
|
|
|
|
|
|
|
/* some flags are missing on some systems, so we provide
|
|
|
|
* harmless defaults.
|
1998-08-10 03:36:18 +02:00
|
|
|
*
|
|
|
|
* Mandatory:
|
|
|
|
* BIND_IMMEDIATE - Resolve symbol references when the library is loaded.
|
|
|
|
* BIND_DEFERRED - Delay code symbol resolution until actual reference.
|
|
|
|
*
|
|
|
|
* Optionally:
|
|
|
|
* BIND_FIRST - Place the library at the head of the symbol search order.
|
|
|
|
* BIND_NONFATAL - The default BIND_IMMEDIATE behavior is to treat all unsatisfied
|
|
|
|
* symbols as fatal. This flag allows binding of unsatisfied code
|
|
|
|
* symbols to be deferred until use.
|
|
|
|
* [Perl: For certain libraries, like DCE, deferred binding often
|
|
|
|
* causes run time problems. Adding BIND_NONFATAL to BIND_IMMEDIATE
|
|
|
|
* still allows unresolved references in situations like this.]
|
|
|
|
* BIND_NOSTART - Do not call the initializer for the shared library when the
|
|
|
|
* library is loaded, nor on a future call to shl_unload().
|
|
|
|
* BIND_VERBOSE - Print verbose messages concerning possible unsatisfied symbols.
|
|
|
|
*
|
|
|
|
* hp9000s700/hp9000s800:
|
|
|
|
* BIND_RESTRICTED - Restrict symbols visible by the library to those present at
|
|
|
|
* library load time.
|
|
|
|
* DYNAMIC_PATH - Allow the loader to dynamically search for the library specified
|
|
|
|
* by the path argument.
|
1998-08-09 10:32:18 +02:00
|
|
|
*/
|
|
|
|
#ifndef DYNAMIC_PATH
|
|
|
|
#define DYNAMIC_PATH 0
|
|
|
|
#endif /* DYNAMIC_PATH */
|
1998-08-10 03:36:18 +02:00
|
|
|
#ifndef BIND_RESTRICTED
|
|
|
|
#define BIND_RESTRICTED 0
|
|
|
|
#endif /* BIND_RESTRICTED */
|
1998-08-09 10:32:18 +02:00
|
|
|
|
1998-08-10 03:36:18 +02:00
|
|
|
#define OPT_BIND_FLAGS (BIND_NONFATAL | BIND_VERBOSE)
|
1998-08-09 10:32:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
/* --- functions --- */
|
|
|
|
static gpointer
|
|
|
|
_g_module_open (const gchar *file_name,
|
1998-08-10 03:36:18 +02:00
|
|
|
gboolean bind_lazy)
|
1998-08-09 10:32:18 +02:00
|
|
|
{
|
1998-08-10 03:36:18 +02:00
|
|
|
shl_t shl_handle;
|
|
|
|
|
|
|
|
shl_handle = shl_load (file_name,
|
|
|
|
(bind_lazy ? BIND_DEFERRED : BIND_IMMEDIATE) | OPT_BIND_FLAGS, 0);
|
|
|
|
if (!shl_handle)
|
|
|
|
{
|
|
|
|
/* the hp-docs say we should better abort() if errno==ENOSYM ;( */
|
|
|
|
g_module_set_error (g_strerror (errno));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (gpointer) shl_handle;
|
1998-08-09 10:32:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
_g_module_self (void)
|
|
|
|
{
|
1998-08-10 03:36:18 +02:00
|
|
|
shl_t shl_handle;
|
|
|
|
|
|
|
|
shl_handle = PROG_HANDLE;
|
|
|
|
if (!shl_handle)
|
1998-08-09 10:32:18 +02:00
|
|
|
g_module_set_error (g_strerror (errno));
|
1998-08-10 03:36:18 +02:00
|
|
|
|
|
|
|
return shl_handle;
|
1998-08-09 10:32:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-08-10 03:36:18 +02:00
|
|
|
_g_module_close (gpointer handle,
|
|
|
|
gboolean is_unref)
|
1998-08-09 10:32:18 +02:00
|
|
|
{
|
|
|
|
if (!is_unref)
|
|
|
|
{
|
1998-08-10 03:36:18 +02:00
|
|
|
if (shl_unload ((shl_t) handle) != 0)
|
1998-08-09 10:32:18 +02:00
|
|
|
g_module_set_error (g_strerror (errno));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static gpointer
|
1998-08-10 03:36:18 +02:00
|
|
|
_g_module_symbol (gpointer handle,
|
|
|
|
const gchar *symbol_name)
|
1998-08-09 10:32:18 +02:00
|
|
|
{
|
|
|
|
gpointer p = NULL;
|
1998-08-10 03:36:18 +02:00
|
|
|
|
1998-08-09 10:32:18 +02:00
|
|
|
/* should we restrict lookups to TYPE_PROCEDURE?
|
|
|
|
*/
|
1998-08-10 03:36:18 +02:00
|
|
|
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));
|
|
|
|
}
|
1998-08-09 10:32:18 +02:00
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|