2
* Copyright (c) 1997 The XFree86 Project, Inc.
4
* Permission to use, copy, modify, distribute, and sell this software
5
* and its documentation for any purpose is hereby granted without
6
* fee, provided that the above copyright notice appear in all copies
7
* and that both that copyright notice and this permission notice
8
* appear in supporting documentation, and that the name of the
9
* XFree86 Project, Inc. not be used in advertising or publicity
10
* pertaining to distribution of the software without specific,
11
* written prior permission. The Xfree86 Project, Inc. makes no
12
* representations about the suitability of this software for any
13
* purpose. It is provided "as is" without express or implied
16
* THE XFREE86 PROJECT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO
17
* THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18
* AND FITNESS, IN NO EVENT SHALL THE XFREE86 PROJECT, INC. BE LIABLE
19
* FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
21
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
22
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
27
* Once upon a time, X had multiple loader backends, three of which were
28
* essentially libdl reimplementations. This was nonsense so we chucked
29
* it, but we still retain the factorization between loader API and
30
* platform implementation. This file is the libdl implementation, and
31
* currently the only backend. If you find yourself porting to a platform
32
* without working libdl - hpux, win32, some forsaken a.out host, etc. -
33
* make a new backend rather than hacking up this file.
36
#ifdef HAVE_XORG_CONFIG_H
37
#include <xorg-config.h>
51
#define DLOPEN_LAZY DL_LAZY
52
#elif defined(RTLD_LAZY)
53
#define DLOPEN_LAZY RTLD_LAZY
54
#elif defined(__FreeBSD__)
60
#if defined(LD_GLOBAL)
61
#define DLOPEN_GLOBAL LD_GLOBAL
62
#elif defined(RTLD_GLOBAL)
63
#define DLOPEN_GLOBAL RTLD_GLOBAL
65
#define DLOPEN_GLOBAL 0
68
#if defined(CSRG_BASED) && !defined(__ELF__)
69
#define DLSYM_PREFIX "_"
71
#define DLSYM_PREFIX ""
74
/* Hooray, yet another open coded linked list! FIXME */
75
typedef struct DLModuleList {
77
struct DLModuleList *next;
80
static DLModuleList *dlModuleList = NULL;
83
DLFindSymbolLocal(pointer module, const char *name)
88
static const char symPrefix[] = DLSYM_PREFIX;
90
if (sizeof(symPrefix) > 1) {
91
n = malloc(strlen(symPrefix) + strlen(name) + 1);
92
sprintf(n, "%s%s", symPrefix, name);
96
p = dlsym(module, name);
98
if (sizeof(symPrefix) > 1)
104
static void *global_scope = NULL;
107
DLFindSymbol(const char *name)
112
p = dlsym(RTLD_DEFAULT, name);
116
for (l = dlModuleList; l != NULL; l = l->next) {
117
p = DLFindSymbolLocal(l->module, name);
123
global_scope = dlopen(NULL, DLOPEN_LAZY | DLOPEN_GLOBAL);
126
return DLFindSymbolLocal(global_scope, name);
132
DLLoadModule(loaderPtr modrec, int flags)
138
if (flags & LD_FLAG_GLOBAL)
139
dlopen_flags = DLOPEN_LAZY | DLOPEN_GLOBAL;
141
dlopen_flags = DLOPEN_LAZY;
142
dlfile = dlopen(modrec->name, dlopen_flags);
143
if (dlfile == NULL) {
144
ErrorF("dlopen: %s\n", dlerror());
148
l = malloc(sizeof(DLModuleList));
150
l->next = dlModuleList;
153
return (void *)dlfile;
157
DLUnloadModule(void *modptr)
161
/* remove it from dlModuleList. */
162
if (dlModuleList->module == modptr) {
164
dlModuleList = l->next;
168
for (l = dlModuleList->next; l != NULL; l = l->next) {
169
if (l->module == modptr) {