1 | /**************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | ****************************************/ |
---|
4 | /* $Id: mod_raw.cc,v 1.14 2001-02-15 13:54:08 levandov Exp $ */ |
---|
5 | /* |
---|
6 | * ABSTRACT: machine depend code for dynamic modules |
---|
7 | * |
---|
8 | * Provides: dynl_open() |
---|
9 | * dynl_sym() |
---|
10 | * dynl_error() |
---|
11 | * dunl_close() |
---|
12 | */ |
---|
13 | |
---|
14 | #include <stdio.h> |
---|
15 | |
---|
16 | #include "mod2.h" |
---|
17 | #include "static.h" |
---|
18 | #ifdef HAVE_STATIC |
---|
19 | #undef HAVE_DL |
---|
20 | #endif |
---|
21 | |
---|
22 | #if defined(HAVE_DL) |
---|
23 | #include "mod_raw.h" |
---|
24 | #include "febase.h" |
---|
25 | |
---|
26 | /***************************************************************************** |
---|
27 | * |
---|
28 | * General section |
---|
29 | * These are just wrappers around the repsective dynl_* calls |
---|
30 | * which look for the binary in the bin_dir of Singular and ommit warnings if |
---|
31 | * somethings goes wrong |
---|
32 | * |
---|
33 | *****************************************************************************/ |
---|
34 | static BOOLEAN warn_handle = FALSE; |
---|
35 | static BOOLEAN warn_proc = FALSE; |
---|
36 | #ifndef DL_TAIL |
---|
37 | #define DL_TAIL "so" |
---|
38 | #endif |
---|
39 | |
---|
40 | void* dynl_open_binary_warn(char* binary_name, const char* msg) |
---|
41 | { |
---|
42 | void* handle = NULL; |
---|
43 | const char* bin_dir = feGetResource('b'); |
---|
44 | if (bin_dir != NULL) |
---|
45 | { |
---|
46 | char path_name[MAXPATHLEN]; |
---|
47 | sprintf(path_name, "%s%s%s.%s", bin_dir, DIR_SEPP, binary_name, |
---|
48 | DL_TAIL); |
---|
49 | handle = dynl_open(path_name); |
---|
50 | if (handle == NULL && ! warn_handle) |
---|
51 | { |
---|
52 | Warn("Could not open dynamic library: %s", path_name); |
---|
53 | Warn("Error message from system: %s", dynl_error()); |
---|
54 | if (msg != NULL) Warn("%s", msg); |
---|
55 | Warn("See the INSTALL section in the Singular manual for details."); |
---|
56 | warn_handle = TRUE; |
---|
57 | } |
---|
58 | } |
---|
59 | return handle; |
---|
60 | } |
---|
61 | |
---|
62 | void* dynl_sym_warn(void* handle, char* proc, const char* msg) |
---|
63 | { |
---|
64 | void *proc_ptr = NULL; |
---|
65 | if (handle != NULL) |
---|
66 | { |
---|
67 | proc_ptr = dynl_sym(handle, proc); |
---|
68 | if (proc_ptr == NULL && ! warn_proc) |
---|
69 | { |
---|
70 | Warn("Could load a procedure from a dynamic library"); |
---|
71 | Warn("Error message from system: %s", dynl_error()); |
---|
72 | if (msg != NULL) Warn("%s", msg); |
---|
73 | Warn("See the INSTALL section in the Singular manual for details."); |
---|
74 | warn_proc = TRUE; |
---|
75 | } |
---|
76 | } |
---|
77 | return proc_ptr; |
---|
78 | } |
---|
79 | |
---|
80 | |
---|
81 | /***************************************************************************** |
---|
82 | * SECTION ix86-linux / alpha-linux * |
---|
83 | *****************************************************************************/ |
---|
84 | #if defined(ix86_Linux) || defined(DecAlpha_Linux) || defined(ix86_Linux_libc5) |
---|
85 | #include <dlfcn.h> |
---|
86 | |
---|
87 | static void* kernel_handle = NULL; |
---|
88 | void *dynl_open( |
---|
89 | char *filename /* I: filename to load */ |
---|
90 | ) |
---|
91 | { |
---|
92 | return(dlopen(filename, RTLD_NOW|RTLD_GLOBAL)); |
---|
93 | } |
---|
94 | |
---|
95 | void *dynl_sym(void *handle, char *symbol) |
---|
96 | { |
---|
97 | if (handle == DYNL_KERNEL_HANDLE) |
---|
98 | { |
---|
99 | if (kernel_handle == NULL) |
---|
100 | kernel_handle = dynl_open(NULL); |
---|
101 | handle = kernel_handle; |
---|
102 | } |
---|
103 | return(dlsym(handle, symbol)); |
---|
104 | } |
---|
105 | |
---|
106 | int dynl_close (void *handle) |
---|
107 | { |
---|
108 | return(dlclose (handle)); |
---|
109 | } |
---|
110 | |
---|
111 | const char *dynl_error() |
---|
112 | { |
---|
113 | return(dlerror()); |
---|
114 | } |
---|
115 | #endif /* ix86_Linux */ |
---|
116 | |
---|
117 | /***************************************************************************** |
---|
118 | * SECTION HPUX-9/10 * |
---|
119 | *****************************************************************************/ |
---|
120 | #if defined(HPUX_9) || defined(HPUX_10) |
---|
121 | #include <dl.h> |
---|
122 | |
---|
123 | typedef char *((*func_ptr) ()); |
---|
124 | |
---|
125 | void *dynl_open(char *filename) |
---|
126 | { |
---|
127 | shl_t handle = shl_load(filename, BIND_DEFERRED, 0); |
---|
128 | |
---|
129 | return ((void *) handle); |
---|
130 | } |
---|
131 | |
---|
132 | void *dynl_sym(void *handle, char *symbol) |
---|
133 | { |
---|
134 | func_ptr f; |
---|
135 | |
---|
136 | if (handle == DYNL_KERNEL_HANDLE) |
---|
137 | handle = PROG_HANDLE; |
---|
138 | |
---|
139 | if (shl_findsym((shl_t *) & handle, symbol, TYPE_PROCEDURE, &f) == -1) |
---|
140 | { |
---|
141 | if (shl_findsym((shl_t *) & handle, symbol, TYPE_UNDEFINED, &f) == -1) |
---|
142 | { |
---|
143 | f = (func_ptr) NULL; |
---|
144 | } |
---|
145 | } |
---|
146 | return (f); |
---|
147 | } |
---|
148 | |
---|
149 | int dynl_close (void *handle) |
---|
150 | { |
---|
151 | shl_unload((shl_t) handle); |
---|
152 | return(0); |
---|
153 | } |
---|
154 | |
---|
155 | const char *dynl_error() |
---|
156 | { |
---|
157 | static char errmsg[] = "shl_load failed"; |
---|
158 | |
---|
159 | return errmsg; |
---|
160 | } |
---|
161 | #endif /* HPUX_9 or HPUX_10 */ |
---|
162 | |
---|
163 | /***************************************************************************** |
---|
164 | * SECTION 68k-MPW * |
---|
165 | *****************************************************************************/ |
---|
166 | #ifdef 68k_MPW |
---|
167 | /* # include <> */ |
---|
168 | |
---|
169 | void *dynl_open(char *filename) |
---|
170 | { |
---|
171 | return(NULL); |
---|
172 | } |
---|
173 | |
---|
174 | void *dynl_sym(void *handle, char *symbol) |
---|
175 | { |
---|
176 | return(NULL); |
---|
177 | } |
---|
178 | |
---|
179 | int dynl_close (void *handle) |
---|
180 | { |
---|
181 | return(0); |
---|
182 | } |
---|
183 | |
---|
184 | const char *dynl_error() |
---|
185 | { |
---|
186 | static char errmsg[] = "support for dynamic loading not implemented"; |
---|
187 | |
---|
188 | return errmsg; |
---|
189 | } |
---|
190 | # endif /* 68k_MPW */ |
---|
191 | |
---|
192 | |
---|
193 | /***************************************************************************** |
---|
194 | * SECTION AIX-4 * |
---|
195 | *****************************************************************************/ |
---|
196 | #ifdef AIX_4 |
---|
197 | /* # include <> */ |
---|
198 | |
---|
199 | void *dynl_open(char *filename) |
---|
200 | { |
---|
201 | return(NULL); |
---|
202 | } |
---|
203 | |
---|
204 | void *dynl_sym(void *handle, char *symbol) |
---|
205 | { |
---|
206 | return(NULL); |
---|
207 | } |
---|
208 | |
---|
209 | int dynl_close (void *handle) |
---|
210 | { |
---|
211 | return(0); |
---|
212 | } |
---|
213 | |
---|
214 | const char *dynl_error() |
---|
215 | { |
---|
216 | static char errmsg[] = "support for dynamic loading not implemented"; |
---|
217 | |
---|
218 | return errmsg; |
---|
219 | } |
---|
220 | # endif /* AIX_4 */ |
---|
221 | |
---|
222 | /***************************************************************************** |
---|
223 | * SECTION IRIX-6 * |
---|
224 | *****************************************************************************/ |
---|
225 | #ifdef IRIX_6 |
---|
226 | #include <dlfcn.h> |
---|
227 | |
---|
228 | void *dynl_open(char *filename) |
---|
229 | { |
---|
230 | return(NULL); |
---|
231 | } |
---|
232 | |
---|
233 | void *dynl_sym(void *handle, char *symbol) |
---|
234 | { |
---|
235 | return(NULL); |
---|
236 | } |
---|
237 | |
---|
238 | int dynl_close (void *handle) |
---|
239 | { |
---|
240 | return(0); |
---|
241 | } |
---|
242 | |
---|
243 | const char *dynl_error() |
---|
244 | { |
---|
245 | static char errmsg[] = "support for dynamic loading not implemented"; |
---|
246 | |
---|
247 | return errmsg; |
---|
248 | } |
---|
249 | # endif /* IRIX_6 */ |
---|
250 | |
---|
251 | /***************************************************************************** |
---|
252 | * SECTION Sun3OS-4 * |
---|
253 | *****************************************************************************/ |
---|
254 | #ifdef Sun3OS_4 |
---|
255 | /* # include <> */ |
---|
256 | |
---|
257 | void *dynl_open(char *filename) |
---|
258 | { |
---|
259 | return(NULL); |
---|
260 | } |
---|
261 | |
---|
262 | void *dynl_sym(void *handle, char *symbol) |
---|
263 | { |
---|
264 | return(NULL); |
---|
265 | } |
---|
266 | |
---|
267 | int dynl_close (void *handle) |
---|
268 | { |
---|
269 | return(0); |
---|
270 | } |
---|
271 | |
---|
272 | const char *dynl_error() |
---|
273 | { |
---|
274 | static char errmsg[] = "support for dynamic loading not implemented"; |
---|
275 | |
---|
276 | return errmsg; |
---|
277 | } |
---|
278 | #endif /* Sun3OS_4 */ |
---|
279 | |
---|
280 | /***************************************************************************** |
---|
281 | * SECTION SunOS-4/5 * |
---|
282 | *****************************************************************************/ |
---|
283 | #if defined(SunOS_4) || defined(SunOS_5) |
---|
284 | /* # include <> */ |
---|
285 | |
---|
286 | void *dynl_open(char *filename) |
---|
287 | { |
---|
288 | return(NULL); |
---|
289 | } |
---|
290 | |
---|
291 | void *dynl_sym(void *handle, char *symbol) |
---|
292 | { |
---|
293 | return(NULL); |
---|
294 | } |
---|
295 | |
---|
296 | int dynl_close (void *handle) |
---|
297 | { |
---|
298 | return(0); |
---|
299 | } |
---|
300 | |
---|
301 | const char *dynl_error() |
---|
302 | { |
---|
303 | static char errmsg[] = "support for dynamic loading not implemented"; |
---|
304 | |
---|
305 | return errmsg; |
---|
306 | } |
---|
307 | #endif /* SunOS_4 or SunOS_5 */ |
---|
308 | |
---|
309 | /***************************************************************************** |
---|
310 | * SECTION ix86-Win * |
---|
311 | *****************************************************************************/ |
---|
312 | // is defined externally in sing_win.cc |
---|
313 | |
---|
314 | /***************************************************************************** |
---|
315 | * SECTION ppc-MPW * |
---|
316 | *****************************************************************************/ |
---|
317 | #ifdef ppc_MPW |
---|
318 | /* # include <> */ |
---|
319 | |
---|
320 | void *dynl_open(char *filename) |
---|
321 | { |
---|
322 | return(NULL); |
---|
323 | } |
---|
324 | |
---|
325 | void *dynl_sym(void *handle, char *symbol) |
---|
326 | { |
---|
327 | return(NULL); |
---|
328 | } |
---|
329 | |
---|
330 | int dynl_close (void *handle) |
---|
331 | { |
---|
332 | return(0); |
---|
333 | } |
---|
334 | |
---|
335 | const char *dynl_error() |
---|
336 | { |
---|
337 | static char errmsg[] = "support for dynamic loading not implemented"; |
---|
338 | return errmsg; |
---|
339 | } |
---|
340 | # endif /* ppc_MPW */ |
---|
341 | |
---|
342 | |
---|
343 | #endif /* HAVE_DL */ |
---|