annotate src/sysdll.c @ 1897:d8a525bee708

[xemacs-hg @ 2004-02-03 22:50:48 by viteno] Update xemacs_extra_name.
author viteno
date Tue, 03 Feb 2004 22:50:48 +0000
parents 7fdde2d3ae5f
children 91d4c8c65a0f
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 { \
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
32 CIbyte *buf = alloca_array (CIbyte, strlen (n) + 2); \
1383
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
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
66 dll_init (const Extbyte *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
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
72 dll_open (Lisp_Object fname)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 {
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
74 Extbyte *soname;
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
75
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
76 if (NILP (fname))
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
77 {
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
78 soname = NULL;
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
79 }
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
80 else
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
81 {
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
82 LISP_STRING_TO_EXTERNAL (fname, soname, Qdll_filename_encoding);
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
83 }
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
84 return (dll_handle) dlopen (soname, RTLD_NOW);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 dll_close (dll_handle h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
90 return dlclose ((void *) h);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 dll_func
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
94 dll_function (dll_handle h, const CIbyte *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 {
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
96 MAYBE_PREPEND_UNDERSCORE (n);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
97 return (dll_func) dlsym ((void *) h, n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 }
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 dll_var
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
101 dll_variable (dll_handle h, const CIbyte *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 {
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
103 MAYBE_PREPEND_UNDERSCORE (n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 return (dll_var)dlsym ((void *)h, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
107 Lisp_Object
1811
3fe1a35b705d [xemacs-hg @ 2003-11-29 22:11:47 by james]
james
parents: 1706
diff changeset
108 dll_error ()
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 {
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
110 const Extbyte *msg;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 #if defined(HAVE_DLERROR) || defined(dlerror)
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
112 msg = (const Extbyte *) dlerror ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 #elif defined(HAVE__DLERROR)
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
114 msg = (const Extbyte *) _dlerror();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 #else
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
116 msg = (const Extbyte *) "Shared library error";
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 #endif
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
118 return build_ext_string (msg, Qnative);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 #elif defined(HAVE_SHL_LOAD)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 /* This is the HP/UX version */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 #include <dl.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 int
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
125 dll_init (const Extbyte *arg)
428
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 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 dll_handle
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
131 dll_open (Lisp_Object fname)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 {
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
133 Extbyte *soname;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
135 if (NILP (fname))
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
136 {
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
137 soname = NULL;
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
138 }
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
139 else
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
140 {
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
141 LISP_STRING_TO_EXTERNAL (fname, soname, Qdll_filename_encoding);
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
142 }
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
143 return (dll_handle) shl_load (soname, BIND_DEFERRED, 0L);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 dll_close (dll_handle h)
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 return shl_unload ((shl_t) h);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 dll_func
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
153 dll_function (dll_handle h, const CIbyte *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 long handle = 0L;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
157 if (shl_findsym ((shl_t *) &h, n, TYPE_PROCEDURE, &handle))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
160 return (dll_func) handle;
428
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 dll_var
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
164 dll_variable (dll_handle h, const CIbyte *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 long handle = 0L;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
168 if (shl_findsym ((shl_t *) &h, n, TYPE_DATA, &handle))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
171 return (dll_var) handle;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
174 Lisp_Object
1811
3fe1a35b705d [xemacs-hg @ 2003-11-29 22:11:47 by james]
james
parents: 1706
diff changeset
175 dll_error ()
428
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 /* #### WTF?! Shouldn't this at least attempt to get strerror or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 something? --hniksic */
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
179 return build_string ("Generic shared library error", Qnative);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181
1632
64eaceca611d [xemacs-hg @ 2003-08-19 02:07:03 by james]
james
parents: 1596
diff changeset
182 #elif defined (WIN32_NATIVE) || defined (CYGWIN)
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
183
1632
64eaceca611d [xemacs-hg @ 2003-08-19 02:07:03 by james]
james
parents: 1596
diff changeset
184 #include "syswindows.h"
64eaceca611d [xemacs-hg @ 2003-08-19 02:07:03 by james]
james
parents: 1596
diff changeset
185 #include "sysfile.h"
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 430
diff changeset
186
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 int
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
188 dll_init (const Extbyte *arg)
428
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 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 }
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 dll_handle
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
194 dll_open (Lisp_Object fname)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 {
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
196 Extbyte *soname;
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
197
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
198 if (NILP (fname))
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
199 {
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
200 soname = NULL;
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
201 }
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
202 else
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
203 {
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
204 LOCAL_FILE_FORMAT_TO_TSTR (fname, soname);
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
205 }
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
206 return (dll_handle) qxeLoadLibrary (soname);
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 dll_close (dll_handle h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 {
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
212 return FreeLibrary ((HMODULE) h);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 dll_func
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
216 dll_function (dll_handle h, const CIbyte *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 {
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
218 return (dll_func) GetProcAddress ((HINSTANCE) h, n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 dll_func
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
222 dll_variable (dll_handle h, const CIbyte *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 {
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
224 return (dll_func) GetProcAddress ((HINSTANCE) h, n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
227 Lisp_Object
1811
3fe1a35b705d [xemacs-hg @ 2003-11-29 22:11:47 by james]
james
parents: 1706
diff changeset
228 dll_error ()
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 {
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
230 CIbyte err[32];
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
231 snprintf (err, 32, "Windows DLL Error %lu", GetLastError ());
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
232 return build_string (err);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 }
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
234 #elif defined(HAVE_DYLD)
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
235 /* This section supports MacOSX dynamic libraries. Dynamically
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
236 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
237 */
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
238
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
239 #include <mach-o/dyld.h>
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
240
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
241 int
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
242 dll_init (const Extbyte *arg)
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
243 {
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
244 return 0;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
245 }
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
246
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
247 dll_handle
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
248 dll_open (Lisp_Object fname)
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
249 {
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
250 Extbyte *soname;
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
251 NSObjectFileImage file;
1418
c7045d239c2b [xemacs-hg @ 2003-04-16 20:24:06 by james]
james
parents: 1383
diff changeset
252 NSModule out;
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
253 NSObjectFileImageReturnCode ret;
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
254
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
255 if (NILP (fname))
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
256 {
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
257 soname = NULL;
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
258 }
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
259 else
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
260 {
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
261 LISP_STRING_TO_EXTERNAL (fname, soname, Qdll_filename_encoding);
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
262 }
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
263 ret = NSCreateObjectFileImageFromFile(soname, &file);
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
264 if (ret != NSObjectFileImageSuccess) {
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
265 return NULL;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
266 }
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
267 out = NSLinkModule(file, soname,
1418
c7045d239c2b [xemacs-hg @ 2003-04-16 20:24:06 by james]
james
parents: 1383
diff changeset
268 NSLINKMODULE_OPTION_BINDNOW |
c7045d239c2b [xemacs-hg @ 2003-04-16 20:24:06 by james]
james
parents: 1383
diff changeset
269 NSLINKMODULE_OPTION_PRIVATE |
c7045d239c2b [xemacs-hg @ 2003-04-16 20:24:06 by james]
james
parents: 1383
diff changeset
270 NSLINKMODULE_OPTION_RETURN_ON_ERROR);
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
271 return (dll_handle)out;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
272 }
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
273
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
274 int
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
275 dll_close (dll_handle h)
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
276 {
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
277 return NSUnLinkModule((NSModule)h, NSUNLINKMODULE_OPTION_NONE);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
278 }
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
279
1851
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
280 /* Given an address, return the mach_header for the image containing it
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
281 * or zero if the given address is not contained in any loaded images.
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
282 *
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
283 * Note: image_for_address(), my_find_image() and search_linked_libs() are
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
284 * based on code from the dlcompat library
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
285 * (http://www.opendarwin.org/projects/dlcompat).
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
286 */
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
287
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
288 static struct mach_header*
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
289 image_for_address(void *address)
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
290 {
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
291 unsigned long i;
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
292 unsigned long count = _dyld_image_count();
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
293 struct mach_header *mh = 0;
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
294
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
295 for (i = 0; i < count; i++)
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
296 {
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
297 unsigned long addr = (unsigned long)address -
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
298 _dyld_get_image_vmaddr_slide(i);
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
299 mh = _dyld_get_image_header(i);
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
300
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
301 if (mh)
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
302 {
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
303 struct load_command *lc =
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
304 (struct load_command *)((char *)mh + sizeof(struct mach_header));
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
305 unsigned long j;
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
306
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
307 for (j = 0; j < mh->ncmds;
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
308 j++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
309 {
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
310 if (LC_SEGMENT == lc->cmd &&
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
311 addr >= ((struct segment_command *)lc)->vmaddr &&
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
312 addr <
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
313 ((struct segment_command *)lc)->vmaddr +
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
314 ((struct segment_command *)lc)->vmsize)
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
315 {
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
316 goto image_found;
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
317 }
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
318 }
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
319 }
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
320
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
321 mh = 0;
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
322 }
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
323
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
324 image_found:
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
325 return mh;
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
326 }
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
327
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
328 static const struct mach_header*
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
329 my_find_image(const char *name)
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
330 {
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
331 const struct mach_header *mh = (struct mach_header *)
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
332 NSAddImage(name, NSADDIMAGE_OPTION_RETURN_ONLY_IF_LOADED |
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
333 NSADDIMAGE_OPTION_RETURN_ON_ERROR);
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
334
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
335 if (!mh)
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
336 {
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
337 int count = _dyld_image_count();
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
338 int j;
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
339
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
340 for (j = 0; j < count; j++)
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
341 {
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
342 const char *id = _dyld_get_image_name(j);
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
343
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
344 if (!strcmp(id, name))
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
345 {
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
346 mh = _dyld_get_image_header(j);
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
347 break;
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
348 }
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
349 }
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
350 }
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
351
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
352 return mh;
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
353 }
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
354
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
355 /*
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
356 * dyld adds libraries by first adding the directly dependant libraries in
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
357 * link order, and then adding the dependencies for those libraries, so we
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
358 * should do the same... but we don't bother adding the extra dependencies, if
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
359 * the symbols are neither in the loaded image nor any of it's direct
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
360 * dependencies, then it probably isn't there.
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
361 */
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
362 static NSSymbol
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
363 search_linked_libs(const struct mach_header * mh, const char *symbol)
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
364 {
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
365 int n;
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
366 NSSymbol nssym = 0;
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
367
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
368 struct load_command *lc =
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
369 (struct load_command *)((char *)mh + sizeof(struct mach_header));
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
370
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
371 for (n = 0; n < mh->ncmds;
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
372 n++, lc = (struct load_command *)((char *)lc + lc->cmdsize))
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
373 {
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
374 if ((LC_LOAD_DYLIB == lc->cmd) || (LC_LOAD_WEAK_DYLIB == lc->cmd))
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
375 {
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
376 struct mach_header *wh;
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
377
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
378 if ((wh = (struct mach_header *)
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
379 my_find_image((char *)(((struct dylib_command *)lc)->dylib.name.offset +
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
380 (char *)lc))))
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
381 {
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
382 if (NSIsSymbolNameDefinedInImage(wh, symbol))
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
383 {
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
384 nssym =
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
385 NSLookupSymbolInImage(wh,
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
386 symbol,
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
387 NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
388 NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
389 break;
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
390 }
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
391 }
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
392 }
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
393 }
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
394
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
395 return nssym;
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
396 }
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
397
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
398 dll_func
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
399 dll_function (dll_handle h, const CIbyte *n)
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
400 {
1851
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
401 NSSymbol sym = 0;
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
402 MAYBE_PREPEND_UNDERSCORE (n);
1851
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
403
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
404 /* NULL means the program image and shared libraries, not bundles. */
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
405
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
406 if (h == NULL)
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
407 {
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
408 /* NOTE: This assumes that this function is included in the main program
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
409 and not in a shared library. */
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
410 const struct mach_header* my_mh = image_for_address(&dll_function);
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
411
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
412 if (NSIsSymbolNameDefinedInImage(my_mh, n))
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
413 {
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
414 sym =
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
415 NSLookupSymbolInImage(my_mh,
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
416 n,
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
417 NSLOOKUPSYMBOLINIMAGE_OPTION_BIND |
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
418 NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR);
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
419 }
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
420
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
421 if (!sym)
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
422 {
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
423 sym = search_linked_libs(my_mh, n);
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
424 }
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
425 }
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
426 else
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
427 {
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
428 sym = NSLookupSymbolInModule((NSModule)h, n);
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
429 }
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
430
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
431 if (sym == 0) return 0;
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
432 return (dll_func)NSAddressOfSymbol(sym);
7fdde2d3ae5f [xemacs-hg @ 2004-01-03 23:06:49 by james]
james
parents: 1811
diff changeset
433 }
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
434
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
435 dll_var
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
436 dll_variable (dll_handle h, const CIbyte *n)
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
437 {
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
438 NSSymbol sym;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
439 MAYBE_PREPEND_UNDERSCORE (n);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
440 sym = NSLookupSymbolInModule((NSModule)h, n);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
441 if (sym == 0) return 0;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
442 return (dll_var)NSAddressOfSymbol(sym);
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
443 }
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
444
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
445 Lisp_Object
1811
3fe1a35b705d [xemacs-hg @ 2003-11-29 22:11:47 by james]
james
parents: 1706
diff changeset
446 dll_error ()
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
447 {
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
448 NSLinkEditErrors c;
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
449 int errorNumber;
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
450 const CIbyte *fileNameWithError, *errorString;
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
451 NSLinkEditError(&c, &errorNumber, &fileNameWithError, &errorString);
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
452 return build_ext_string (errorString, Qnative);
1383
517919955e3f [xemacs-hg @ 2003-03-26 04:22:47 by james]
james
parents: 1272
diff changeset
453 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 #else
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
455 /* Catchall if we don't know about this system's method of dynamic loading */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 int
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
457 dll_init (const Extbyte *arg)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 dll_handle
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
463 dll_open (Lisp_Object fname)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 dll_close (dll_handle h)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 dll_func
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
475 dll_function (dll_handle h, const CIbyte *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 dll_func
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
481 dll_variable (dll_handle h, const CIbyte *n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 return NULL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
486 Lisp_Object
1811
3fe1a35b705d [xemacs-hg @ 2003-11-29 22:11:47 by james]
james
parents: 1706
diff changeset
487 dll_error ()
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 {
1706
9fc738581a9d [xemacs-hg @ 2003-09-22 03:21:12 by james]
james
parents: 1632
diff changeset
489 return build_string ("Shared libraries not implemented on this system");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 #endif /* System conditionals */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 #endif /* HAVE_SHLIB */