source: git/kernel/mod_raw.cc @ 68349d

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