1 | /***************************************** |
---|
2 | * Computer Algebra System SINGULAR * |
---|
3 | *****************************************/ |
---|
4 | /* $Id: sing_dld.cc,v 1.1.1.1 2003-10-06 12:16:03 Singular Exp $ */ |
---|
5 | |
---|
6 | /* |
---|
7 | * ABSTRACT: interface to dynamic loading |
---|
8 | */ |
---|
9 | |
---|
10 | #include "mod2.h" |
---|
11 | #include "febase.h" |
---|
12 | #include "structs.h" |
---|
13 | #include "ipshell.h" |
---|
14 | |
---|
15 | |
---|
16 | #ifdef HAVE_DLD |
---|
17 | #ifdef linux |
---|
18 | #ifdef __ELF__ |
---|
19 | #include <dlfcn.h> |
---|
20 | #else |
---|
21 | #include <dld.h> |
---|
22 | #endif |
---|
23 | #elif defined(hpux) |
---|
24 | #include <dl.h> |
---|
25 | #endif |
---|
26 | |
---|
27 | #ifdef linux |
---|
28 | #ifndef __ELF__ |
---|
29 | static int dlInitError=0; |
---|
30 | void dlInit(const char *thisfile) |
---|
31 | { |
---|
32 | int i=dld_init (thisfile); |
---|
33 | if (i!=0) |
---|
34 | { |
---|
35 | //Print("dld_int:%d, errno:%d\n",i,dld_errno); |
---|
36 | i=dld_init (dld_find_executable(thisfile)); |
---|
37 | //Print("dld_int(dld_find_executable):%d, errno:%d\n",i,dld_errno); |
---|
38 | dlInitError=i; |
---|
39 | } |
---|
40 | } |
---|
41 | #endif |
---|
42 | #endif |
---|
43 | |
---|
44 | BOOLEAN dlLoad(const char * fn, const char *pn) |
---|
45 | { |
---|
46 | typedef void (*PROC)(void); |
---|
47 | PROC p1; |
---|
48 | #ifdef linux |
---|
49 | #ifdef __ELF__ |
---|
50 | /*======================linux elf dl============================*/ |
---|
51 | void *h=dlopen(fn,RTD_GLOBAL|RTD_NOW); |
---|
52 | if (h!=NULL) |
---|
53 | { |
---|
54 | p1=(PROC)dlsym(h,pn); |
---|
55 | char *s; |
---|
56 | if((s=dlerror())==NULL) |
---|
57 | { |
---|
58 | p1(); |
---|
59 | return FALSE; |
---|
60 | } |
---|
61 | else |
---|
62 | { |
---|
63 | Werror("cannot find %s in %s(%s)",pn,fn,s); |
---|
64 | dlclose(h); |
---|
65 | } |
---|
66 | } |
---|
67 | else |
---|
68 | { |
---|
69 | Werror("cannot link %s (%s)",fn,dlerror()); |
---|
70 | } |
---|
71 | #else |
---|
72 | /*======================linux dld============================*/ |
---|
73 | if (dlInitError) |
---|
74 | { |
---|
75 | Werror("dld init error %d",dlInitError); |
---|
76 | } |
---|
77 | else |
---|
78 | { |
---|
79 | dld_errno=0; |
---|
80 | int i= dld_link (fn); |
---|
81 | if (dld_function_executable_p(pn)) |
---|
82 | { |
---|
83 | p1 = (PROC) dld_get_func (pn); |
---|
84 | p1(); |
---|
85 | return FALSE; |
---|
86 | } |
---|
87 | else |
---|
88 | { |
---|
89 | Werror("cannot find %s in %s",pn,fn); |
---|
90 | dld_unlink_by_file (fn,0); |
---|
91 | } |
---|
92 | } |
---|
93 | #endif |
---|
94 | /*======================hpux dl============================*/ |
---|
95 | #elif defined(hpux) |
---|
96 | shl_t hdl=shl_load(fn, |
---|
97 | BIND_IMMEDIATE|BIND_NOSTART|BIND_NONFATAL|BIND_VERBOSE,0L); |
---|
98 | int i=shl_findsym(&hdl,pn,TYPE_PROCEDURE,&p1); |
---|
99 | if (i==0) |
---|
100 | { |
---|
101 | p1(); |
---|
102 | return FALSE; |
---|
103 | } |
---|
104 | else |
---|
105 | { |
---|
106 | Werror("cannot find %s in %s",pn,fn); |
---|
107 | shl_unload(hdl); |
---|
108 | } |
---|
109 | /*=================systems without dynamic loading================*/ |
---|
110 | #else |
---|
111 | WerrorS("dynamic loading not implemented"); |
---|
112 | #endif |
---|
113 | return TRUE; |
---|
114 | } |
---|
115 | sleftv * iiMake_binary(idhdl pn, sleftv* sl) |
---|
116 | { |
---|
117 | return NULL; |
---|
118 | } |
---|
119 | #endif |
---|