annotate src/sysdll.c @ 1472:4c87ece1e837

[xemacs-hg @ 2003-05-10 07:44:22 by stephent] tests for no-clobber-on-fail <87k7czs0xd.fsf@tleepslib.sk.tsukuba.ac.jp>
author stephent
date Sat, 10 May 2003 07:44:24 +0000
parents c7045d239c2b
children 0879be053100
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* sysdll.c --- system dependent support for dynamic linked libraries
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1998 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Author: William Perry <wmperry@aventail.com>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to the Free
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 #ifdef HAVE_CONFIG_H
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
430
a5df635868b2 Import from CVS: tag r21-2-23
cvs
parents: 428
diff changeset
26 #include <stdlib.h>
1272
df61d2b1d4c3 [xemacs-hg @ 2003-02-07 21:40:22 by james]
james
parents: 880
diff changeset
27 #include "lisp.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #include "sysdll.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
30 #ifdef DLSYM_NEEDS_UNDERSCORE
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
31 #define MAYBE_PREPEND_UNDERSCORE(n) do { \
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
32 char *buf = alloca_array (char, strlen (n) + 2); \
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
33 *buf = '_'; \
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
34 strcpy (buf + 1, n); \
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
35 n = buf; \
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
36 } while (0)
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
37 #else
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
38 #define MAYBE_PREPEND_UNDERSCORE(n)
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
39 #endif
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
40
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 /* This whole file is conditional upon HAVE_SHLIB */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 #ifdef HAVE_SHLIB
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 /* Thankfully, most systems follow the ELFish dlopen() method.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 */
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 442
diff changeset
46 #if defined(HAVE_DLOPEN)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 #include <dlfcn.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 #ifndef RTLD_LAZY
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
50 # ifdef DL_LAZY
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
51 # define RTLD_LAZY DL_LAZY
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
52 # else
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
53 # define RTLD_LAZY 1
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
54 # endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 #endif /* RTLD_LAZY isn't defined under FreeBSD - ick */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56
863
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 452
diff changeset
57 #ifndef RTLD_NOW
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
58 # ifdef DL_NOW
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
59 # define RTLD_NOW DL_NOW
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
60 # else
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
61 # define RTLD_NOW 2
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
62 # endif
863
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 452
diff changeset
63 #endif
42375619fa45 [xemacs-hg @ 2002-06-04 06:03:59 by andyp]
andyp
parents: 452
diff changeset
64
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
66 dll_init (const char *arg)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 dll_handle
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
72 dll_open (const char *fname)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 {
880
beddd25fe24a [xemacs-hg @ 2002-06-24 22:00:17 by youngs]
youngs
parents: 863
diff changeset
74 return (dll_handle) dlopen (fname, RTLD_NOW);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 dll_close (dll_handle h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
80 return dlclose ((void *) h);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 dll_func
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
84 dll_function (dll_handle h, const char *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 {
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
86 MAYBE_PREPEND_UNDERSCORE (n);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
87 return (dll_func) dlsym ((void *) h, n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 dll_var
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
91 dll_variable (dll_handle h, const char *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 {
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
93 MAYBE_PREPEND_UNDERSCORE (n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 return (dll_var)dlsym ((void *)h, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
97 const char *
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 dll_error (dll_handle h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100 #if defined(HAVE_DLERROR) || defined(dlerror)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
101 return (const char *) dlerror ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 #elif defined(HAVE__DLERROR)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
103 return (const char *) _dlerror();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 return "Shared library error";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 #elif defined(HAVE_SHL_LOAD)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 /* This is the HP/UX version */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 #include <dl.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
113 dll_init (const char *arg)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 dll_handle
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
119 dll_open (const char *fname)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
121 /* shl_load will hang hard if passed a NULL fname. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
122 if (fname == NULL) return NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
124 return (dll_handle) shl_load (fname, BIND_DEFERRED, 0L);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 dll_close (dll_handle h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
130 return shl_unload ((shl_t) h);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 dll_func
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
134 dll_function (dll_handle h, const char *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 long handle = 0L;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
138 if (shl_findsym ((shl_t *) &h, n, TYPE_PROCEDURE, &handle))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
141 return (dll_func) handle;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 dll_var
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
145 dll_variable (dll_handle h, const char *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 long handle = 0L;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
149 if (shl_findsym ((shl_t *) &h, n, TYPE_DATA, &handle))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
152 return (dll_var) handle;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
155 const char *
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 dll_error (dll_handle h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 /* #### WTF?! Shouldn't this at least attempt to get strerror or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 something? --hniksic */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 return "Generic shared library error";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 #elif defined(HAVE_INIT_DLD)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 #include <dld.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
166 dll_init (const char *arg)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 char *real_exe = dld_find_executable (arg);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 int rc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 rc = dld_init (real_exe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 if (rc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 dld_perror (exe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 dll_handle
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
181 dll_open (const char *fname)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 rc = dld_link (fname);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 if (rc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
187 return (dll_handle) 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 dll_close (dll_handle h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 /* *sigh* DLD is pretty lame and doesn't return a handle that you can use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 ** later on to free the file - you have to remember the filename and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 ** use that as the unlinker. We should eventually keep a linked list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 ** of loaded modules and then use the node pointer as the unique id
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 ** for the shared library. Wheeee. But not now.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 DLL_FUNC
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
203 dll_function (dll_handle h, const char *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
205 return dld_get_func (n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 DLL_FUNC
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
209 dll_variable (dll_handle h, const char *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
211 return dld_get_symbol (n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
213 #elif defined (WIN32_NATIVE)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
214
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
215 #define WIN32_LEAN_AND_MEAN
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
216 #include <windows.h>
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
217 #undef WIN32_LEAN_AND_MEAN
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
218
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
220 dll_init (const char *arg)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 dll_handle
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
226 dll_open (const char *fname)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
228 return (dll_handle) LoadLibrary (fname);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 dll_close (dll_handle h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 return FreeLibrary (h);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 dll_func
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
238 dll_function (dll_handle h, const char *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
240 return (dll_func) GetProcAddress (h, n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 dll_func
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
244 dll_variable (dll_handle h, const char *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
246 return (dll_func) GetProcAddress (h, n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
249 const char *
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 dll_error (dll_handle h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 return "Windows DLL Error";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 }
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
254 #elif defined(HAVE_DYLD)
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
255 /* This section supports MacOSX dynamic libraries. Dynamically
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
256 loadable libraries must be compiled as bundles, not dynamiclibs.
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
257 */
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
258
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
259 #include <mach-o/dyld.h>
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
260
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
261 int
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
262 dll_init (const char *arg)
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
263 {
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
264 return 0;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
265 }
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
266
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
267 dll_handle
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
268 dll_open (const char *fname)
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
269 {
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
270 NSObjectFileImage file;
1418
c7045d239c2b [xemacs-hg @ 2003-04-16 20:24:06 by james]
james
parents: 1383
diff changeset
271 NSModule out;
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
272 NSObjectFileImageReturnCode ret =
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
273 NSCreateObjectFileImageFromFile(fname, &file);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
274 if (ret != NSObjectFileImageSuccess) {
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
275 return NULL;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
276 }
1418
c7045d239c2b [xemacs-hg @ 2003-04-16 20:24:06 by james]
james
parents: 1383
diff changeset
277 out = NSLinkModule(file, fname,
c7045d239c2b [xemacs-hg @ 2003-04-16 20:24:06 by james]
james
parents: 1383
diff changeset
278 NSLINKMODULE_OPTION_BINDNOW |
c7045d239c2b [xemacs-hg @ 2003-04-16 20:24:06 by james]
james
parents: 1383
diff changeset
279 NSLINKMODULE_OPTION_PRIVATE |
c7045d239c2b [xemacs-hg @ 2003-04-16 20:24:06 by james]
james
parents: 1383
diff changeset
280 NSLINKMODULE_OPTION_RETURN_ON_ERROR);
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
281 return (dll_handle)out;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
282 }
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
283
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
284 int
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
285 dll_close (dll_handle h)
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
286 {
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
287 return NSUnLinkModule((NSModule)h, NSUNLINKMODULE_OPTION_NONE);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
288 }
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
289
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
290 dll_func
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
291 dll_function (dll_handle h, const char *n)
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
292 {
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
293 NSSymbol sym;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
294 MAYBE_PREPEND_UNDERSCORE (n);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
295 sym = NSLookupSymbolInModule((NSModule)h, n);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
296 if (sym == 0) return 0;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
297 return (dll_func)NSAddressOfSymbol(sym);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
298 }
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
299
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
300 dll_var
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
301 dll_variable (dll_handle h, const char *n)
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
302 {
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
303 NSSymbol sym;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
304 MAYBE_PREPEND_UNDERSCORE (n);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
305 sym = NSLookupSymbolInModule((NSModule)h, n);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
306 if (sym == 0) return 0;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
307 return (dll_var)NSAddressOfSymbol(sym);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
308 }
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
309
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
310 const char *
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
311 dll_error (dll_handle h)
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
312 {
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
313 NSLinkEditErrors c;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
314 int errorNumber;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
315 const char *fileNameWithError, *errorString;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
316 NSLinkEditError(&c, &errorNumber, &fileNameWithError, &errorString);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
317 return errorString;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
318 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 /* Catchall if we don't know about this systems method of dynamic loading */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
322 dll_init (const char *arg)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 dll_handle
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
328 dll_open (const char *fname)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 dll_close (dll_handle h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 dll_func
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
340 dll_function (dll_handle h, const char *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 dll_func
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
346 dll_variable (dll_handle h, const char *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
351 const char *
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 dll_error (dll_handle h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 return "Shared libraries not implemented on this system";
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 #endif /* System conditionals */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 #endif /* HAVE_SHLIB */