2 * Copyright 1995-1998 by Metro Link, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Metro Link, Inc. not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Metro Link, Inc. makes no
11 * representations about the suitability of this software for any purpose.
12 * It is provided "as is" without express or implied warranty.
14 * METRO LINK, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL METRO LINK, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
23 * Copyright (c) 1997-2003 by The XFree86 Project, Inc.
25 * Permission is hereby granted, free of charge, to any person obtaining a
26 * copy of this software and associated documentation files (the "Software"),
27 * to deal in the Software without restriction, including without limitation
28 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
29 * and/or sell copies of the Software, and to permit persons to whom the
30 * Software is furnished to do so, subject to the following conditions:
32 * The above copyright notice and this permission notice shall be included in
33 * all copies or substantial portions of the Software.
35 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
36 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
37 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
38 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
39 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
40 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
41 * OTHER DEALINGS IN THE SOFTWARE.
43 * Except as contained in this notice, the name of the copyright holder(s)
44 * and author(s) shall not be used in advertising or otherwise to promote
45 * the sale, use or other dealings in this Software without prior written
46 * authorization from the copyright holder(s) and author(s).
49 #ifdef HAVE_XORG_CONFIG_H
50 #include <xorg-config.h>
56 #include <sys/types.h>
65 #include "loaderProcs.h"
76 #define DLOPEN_LAZY DL_LAZY
77 #elif defined(RTLD_LAZY)
78 #define DLOPEN_LAZY RTLD_LAZY
79 #elif defined(__FreeBSD__)
85 #if defined(LD_GLOBAL)
86 #define DLOPEN_GLOBAL LD_GLOBAL
87 #elif defined(RTLD_GLOBAL)
88 #define DLOPEN_GLOBAL RTLD_GLOBAL
90 #define DLOPEN_GLOBAL 0
94 #error i have no dynamic linker and i must scream
97 extern void *xorg_symbols
[];
102 xf86MsgVerb(X_INFO
, 2, "Loader magic: %p\n", (void *) xorg_symbols
);
103 xf86MsgVerb(X_INFO
, 2, "Module ABI versions:\n");
104 xf86ErrorFVerb(2, "\t%s: %d.%d\n", ABI_CLASS_ANSIC
,
105 GET_ABI_MAJOR(LoaderVersionInfo
.ansicVersion
),
106 GET_ABI_MINOR(LoaderVersionInfo
.ansicVersion
));
107 xf86ErrorFVerb(2, "\t%s: %d.%d\n", ABI_CLASS_VIDEODRV
,
108 GET_ABI_MAJOR(LoaderVersionInfo
.videodrvVersion
),
109 GET_ABI_MINOR(LoaderVersionInfo
.videodrvVersion
));
110 xf86ErrorFVerb(2, "\t%s : %d.%d\n", ABI_CLASS_XINPUT
,
111 GET_ABI_MAJOR(LoaderVersionInfo
.xinputVersion
),
112 GET_ABI_MINOR(LoaderVersionInfo
.xinputVersion
));
113 xf86ErrorFVerb(2, "\t%s : %d.%d\n", ABI_CLASS_EXTENSION
,
114 GET_ABI_MAJOR(LoaderVersionInfo
.extensionVersion
),
115 GET_ABI_MINOR(LoaderVersionInfo
.extensionVersion
));
119 /* Public Interface to the loader. */
122 LoaderOpen(const char *module
, int *errmaj
, int *errmin
)
127 ErrorF("LoaderOpen(%s)\n", module
);
130 xf86Msg(X_INFO
, "Loading %s\n", module
);
132 if (!(ret
= dlopen(module
, DLOPEN_LAZY
| DLOPEN_GLOBAL
))) {
133 xf86Msg(X_ERROR
, "Failed to load %s: %s\n", module
, dlerror());
135 *errmaj
= LDR_NOLOAD
;
137 *errmin
= LDR_NOLOAD
;
145 LoaderSymbol(const char *name
)
147 static void *global_scope
= NULL
;
150 p
= dlsym(RTLD_DEFAULT
, name
);
155 global_scope
= dlopen(NULL
, DLOPEN_LAZY
| DLOPEN_GLOBAL
);
158 return dlsym(global_scope
, name
);
164 LoaderSymbolFromModule(void *handle
, const char *name
)
166 return dlsym(handle
, name
);
170 LoaderUnload(const char *name
, void *handle
)
172 LogMessageVerbSigSafe(X_INFO
, 1, "Unloading %s\n", name
);
177 unsigned long LoaderOptions
= 0;
180 LoaderSetOptions(unsigned long opts
)
182 LoaderOptions
|= opts
;
186 LoaderShouldIgnoreABI(void)
188 return (LoaderOptions
& LDR_OPT_ABI_MISMATCH_NONFATAL
) != 0;
192 LoaderGetABIVersion(const char *abiclass
)
198 {ABI_CLASS_ANSIC
, LoaderVersionInfo
.ansicVersion
},
199 {ABI_CLASS_VIDEODRV
, LoaderVersionInfo
.videodrvVersion
},
200 {ABI_CLASS_XINPUT
, LoaderVersionInfo
.xinputVersion
},
201 {ABI_CLASS_EXTENSION
, LoaderVersionInfo
.extensionVersion
},
202 {ABI_CLASS_FONT
, LoaderVersionInfo
.fontVersion
},
207 for (i
= 0; classes
[i
].name
; i
++) {
208 if (!strcmp(classes
[i
].name
, abiclass
)) {
209 return classes
[i
].version
;