source: git/kernel/mod_raw.cc @ 4c7d73

spielwiese
Last change on this file since 4c7d73 was 4c7d73, checked in by Hans Schönemann <hannes@…>, 18 years ago
*hannes: frwalk stuff git-svn-id: file:///usr/local/Singular/svn/trunk@8045 2c84dea3-7e68-4137-9b89-c4e89433aadc
  • Property mode set to 100644
File size: 8.9 KB
Line 
1/****************************************
2*  Computer Algebra System SINGULAR     *
3****************************************/
4/* $Id: mod_raw.cc,v 1.3 2005-05-04 15:25:45 Singular Exp $ */
5/*
6 * ABSTRACT: machine depend code for dynamic modules
7 *
8 * Provides: dynl_open()
9 *           dynl_sym()
10 *           dynl_error()
11 *           dynl_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 *****************************************************************************/
34static BOOLEAN warn_handle = FALSE;
35static BOOLEAN warn_proc = FALSE;
36#ifndef DL_TAIL
37#define DL_TAIL "so"
38#endif
39
40void* 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
62void* 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#ifdef __cplusplus
81extern "C" {
82#endif
83
84/*****************************************************************************
85 * SECTION generic Linux: ix86-linux / alpha-linux / IA64-linux /x86_64_Linux*
86 *****************************************************************************/
87#if defined(ix86_Linux)
88#define HAVE_ELF_SYSTEM
89#endif
90
91#if defined(ix86_Linux_libc5)
92#define HAVE_ELF_SYSTEM
93#endif
94
95#if defined(DecAlpha_Linux)
96#define HAVE_ELF_SYSTEM
97#endif
98
99#if defined(IA64_Linux)
100#define HAVE_ELF_SYSTEM
101#endif
102
103#if defined(x86_64_Linux)
104#define HAVE_ELF_SYSTEM
105#endif
106
107#if defined(ppc_Linux)
108#define HAVE_ELF_SYSTEM
109#endif
110
111#if defined(HAVE_ELF_SYSTEM)
112#include <dlfcn.h>
113
114static void* kernel_handle = NULL;
115void *dynl_open(
116  char *filename    /* I: filename to load */
117  )
118{
119  return(dlopen(filename, RTLD_NOW|RTLD_GLOBAL));
120}
121
122void *dynl_sym(void *handle, char *symbol)
123{
124  if (handle == DYNL_KERNEL_HANDLE)
125  {
126    if (kernel_handle == NULL)
127      kernel_handle = dynl_open(NULL);
128    handle = kernel_handle;
129  }
130  return(dlsym(handle, symbol));
131}
132
133int dynl_close (void *handle)
134{
135  return(dlclose (handle));
136}
137
138const char *dynl_error()
139{
140  return(dlerror());
141}
142#endif /* Linux */
143
144/*****************************************************************************
145 * SECTION HPUX-9/10                                                         *
146 *****************************************************************************/
147#if defined(HPUX_9) || defined(HPUX_10)
148#include <dl.h>
149
150typedef char *((*func_ptr) ());
151
152void *dynl_open(char *filename)
153{
154  shl_t           handle = shl_load(filename, BIND_DEFERRED, 0);
155
156  return ((void *) handle);
157}
158
159void *dynl_sym(void *handle, char *symbol)
160{
161  func_ptr        f;
162 
163  if (handle == DYNL_KERNEL_HANDLE)
164    handle = PROG_HANDLE;
165 
166  if (shl_findsym((shl_t *) & handle, symbol, TYPE_PROCEDURE, &f) == -1)
167  {
168    if (shl_findsym((shl_t *) & handle, symbol, TYPE_UNDEFINED, &f) == -1)
169    {
170      f = (func_ptr) NULL;
171    }
172  }
173  return ((void *)f);
174}
175
176int dynl_close (void *handle)
177{
178  shl_unload((shl_t) handle);
179  return(0);
180}
181
182const char *dynl_error()
183{
184  static char errmsg[] = "shl_load failed";
185
186  return errmsg;
187}
188#endif /* HPUX_9  or HPUX_10 */
189
190/*****************************************************************************
191 * SECTION 68k-MPW                                                           *
192 *****************************************************************************/
193#ifdef MPW
194/* #    include <> */
195
196void *dynl_open(char *filename)
197{
198  return(NULL);
199}
200
201void *dynl_sym(void *handle, char *symbol)
202{
203  return(NULL);
204}
205
206int dynl_close (void *handle)
207{
208  return(0);
209}
210
211const char *dynl_error()
212{
213  static char errmsg[] = "support for dynamic loading not implemented";
214
215  return errmsg;
216}
217#  endif /* 68k_MPW */
218
219
220/*****************************************************************************
221 * SECTION AIX-4                                                             *
222 *****************************************************************************/
223#ifdef AIX_4
224/* #    include <> */
225
226void *dynl_open(char *filename)
227{
228  return(NULL);
229}
230
231void *dynl_sym(void *handle, char *symbol)
232{
233  return(NULL);
234}
235
236int dynl_close (void *handle)
237{
238  return(0);
239}
240
241const char *dynl_error()
242{
243  static char errmsg[] = "support for dynamic loading not implemented";
244
245  return errmsg;
246}
247#  endif /* AIX_4 */
248
249/*****************************************************************************
250 * SECTION IRIX-6                                                            *
251 *****************************************************************************/
252#ifdef IRIX_6
253#include <dlfcn.h>
254static void* kernel_handle = NULL;
255void *dynl_open( char *filename)
256{
257  return(dlopen(filename, RTLD_NOW|RTLD_GLOBAL));
258}
259
260void *dynl_sym(void *handle, char *symbol)
261{
262  if (handle == DYNL_KERNEL_HANDLE)
263  {
264    if (kernel_handle == NULL)
265      kernel_handle = dynl_open(NULL);
266    handle = kernel_handle;
267  }
268  return(dlsym(handle, symbol));
269}
270
271int dynl_close (void *handle)
272{
273  return(dlclose (handle));
274}
275
276const char *dynl_error()
277{
278  return(dlerror());
279}
280#  endif /* IRIX_6 */
281
282/*****************************************************************************
283 * SECTION Sun3OS-4                                                          *
284 *****************************************************************************/
285#ifdef Sun3OS_4
286/* #    include <> */
287
288void *dynl_open(char *filename)
289{
290  return(NULL);
291}
292
293void *dynl_sym(void *handle, char *symbol)
294{
295  return(NULL);
296}
297
298int dynl_close (void *handle)
299{
300  return(0);
301}
302
303const char *dynl_error()
304{
305  static char errmsg[] = "support for dynamic loading not implemented";
306
307  return errmsg;
308}
309#endif /* Sun3OS_4 */
310
311/*****************************************************************************
312 * SECTION SunOS-4                                                         *
313 *****************************************************************************/
314#if defined(SunOS_4)
315/* #    include <> */
316
317void *dynl_open(char *filename)
318{
319  return(NULL);
320}
321
322void *dynl_sym(void *handle, char *symbol)
323{
324  return(NULL);
325}
326
327int dynl_close (void *handle)
328{
329  return(0);
330}
331
332const char *dynl_error()
333{
334  static char errmsg[] = "support for dynamic loading not implemented";
335
336  return errmsg;
337}
338#endif /* SunOS_4 */
339 
340/*****************************************************************************
341 * SECTION SunOs-5
342 *****************************************************************************/
343#if defined(SunOS_5)
344#include <dlfcn.h>
345
346static void* kernel_handle = NULL;
347void *dynl_open(
348  char *filename    /* I: filename to load */
349  )
350{
351  return(dlopen(filename, RTLD_NOW|RTLD_GLOBAL));
352}
353
354void *dynl_sym(void *handle, char *symbol)
355{
356  if (handle == DYNL_KERNEL_HANDLE)
357  {
358    if (kernel_handle == NULL)
359      kernel_handle = dynl_open(NULL);
360    handle = kernel_handle;
361  }
362  return(dlsym(handle, symbol));
363}
364
365int dynl_close (void *handle)
366{
367  return(dlclose (handle));
368}
369
370const char *dynl_error()
371{
372  return(dlerror());
373}
374#endif /* SunOS_5 */
375
376/*****************************************************************************
377 * SECTION ix86-Win                                                          *
378 *****************************************************************************/
379// is defined externally in sing_win.cc
380
381/*****************************************************************************
382 * SECTION ppc-MPW                                                           *
383 *****************************************************************************/
384#ifdef ppc_MPW
385/* #    include <> */
386
387void *dynl_open(char *filename)
388{
389  return(NULL);
390}
391
392void *dynl_sym(void *handle, char *symbol)
393{
394  return(NULL);
395}
396
397int dynl_close (void *handle)
398{
399  return(0);
400}
401
402const char *dynl_error()
403{
404  static char errmsg[] = "support for dynamic loading not implemented";
405  return errmsg;
406}
407#  endif /* ppc_MPW */
408
409#ifdef __cplusplus
410}
411#endif
412
413#endif /* HAVE_DL */
Note: See TracBrowser for help on using the repository browser.