Commit | Line | Data |
a0d0e21e |
1 | /* |
2 | * Author: Jeff Okamoto (okamoto@corp.hp.com) |
75f92628 |
3 | * Version: 2.1, 1995/1/25 |
a0d0e21e |
4 | */ |
5 | |
b13ecc09 |
6 | /* o Added BIND_VERBOSE to dl_nonlazy condition to add names of missing |
7 | * symbols to stderr message on fatal error. |
8 | * |
9 | * o Added BIND_NONFATAL comment to default condition. |
10 | * |
11 | * Chuck Phillips (cdp@fc.hp.com) |
12 | * Version: 2.2, 1997/5/4 */ |
13 | |
a0d0e21e |
14 | #ifdef __hp9000s300 |
15 | #define magic hpux_magic |
16 | #define MAGIC HPUX_MAGIC |
17 | #endif |
18 | |
19 | #include <dl.h> |
20 | #ifdef __hp9000s300 |
21 | #undef magic |
22 | #undef MAGIC |
23 | #endif |
24 | |
25 | #include "EXTERN.h" |
26 | #include "perl.h" |
27 | #include "XSUB.h" |
28 | |
29 | |
30 | #include "dlutils.c" /* for SaveError() etc */ |
31 | |
8e07c86e |
32 | static AV *dl_resolve_using = Nullav; |
33 | |
a0d0e21e |
34 | |
35 | static void |
cea2e8a9 |
36 | dl_private_init(pTHX) |
a0d0e21e |
37 | { |
cea2e8a9 |
38 | (void)dl_generic_private_init(aTHX); |
a7a8d5a9 |
39 | dl_resolve_using = get_av("DynaLoader::dl_resolve_using", GV_ADDMULTI); |
a0d0e21e |
40 | } |
41 | |
42 | MODULE = DynaLoader PACKAGE = DynaLoader |
43 | |
44 | BOOT: |
cea2e8a9 |
45 | (void)dl_private_init(aTHX); |
a0d0e21e |
46 | |
47 | |
48 | void * |
ff7f3c60 |
49 | dl_load_file(filename, flags=0) |
50 | char * filename |
51 | int flags |
52 | PREINIT: |
a0d0e21e |
53 | shl_t obj = NULL; |
8e07c86e |
54 | int i, max, bind_type; |
ff7f3c60 |
55 | CODE: |
bf49b057 |
56 | DLDEBUG(1,PerlIO_printf(Perl_debug_log, "dl_load_file(%s,%x):\n", filename,flags)); |
ff7f3c60 |
57 | if (flags & 0x01) |
cea2e8a9 |
58 | Perl_warn(aTHX_ "Can't make loaded symbols global on this platform while loading %s",filename); |
b13ecc09 |
59 | if (dl_nonlazy) { |
60 | bind_type = BIND_IMMEDIATE|BIND_VERBOSE; |
61 | } else { |
62 | bind_type = BIND_DEFERRED; |
63 | /* For certain libraries, like DCE, deferred binding often causes run |
64 | * time problems. Adding BIND_NONFATAL to BIND_IMMEDIATE still allows |
65 | * unresolved references in situations like this. */ |
66 | /* bind_type = BIND_IMMEDIATE|BIND_NONFATAL; */ |
67 | } |
491527d0 |
68 | /* BIND_NOSTART removed from bind_type because it causes the shared library's */ |
69 | /* initialisers not to be run. This causes problems with all of the static objects */ |
70 | /* in the library. */ |
d43d69ec |
71 | #ifdef DEBUGGING |
72 | if (dl_debug) |
73 | bind_type |= BIND_VERBOSE; |
74 | #endif /* DEBUGGING */ |
8e07c86e |
75 | |
76 | max = AvFILL(dl_resolve_using); |
77 | for (i = 0; i <= max; i++) { |
78 | char *sym = SvPVX(*av_fetch(dl_resolve_using, i, 0)); |
bf49b057 |
79 | DLDEBUG(1,PerlIO_printf(Perl_debug_log, "dl_load_file(%s) (dependent)\n", sym)); |
491527d0 |
80 | obj = shl_load(sym, bind_type, 0L); |
8e07c86e |
81 | if (obj == NULL) { |
82 | goto end; |
75f92628 |
83 | } |
84 | } |
85 | |
bf49b057 |
86 | DLDEBUG(1,PerlIO_printf(Perl_debug_log, "dl_load_file(%s): ", filename)); |
491527d0 |
87 | obj = shl_load(filename, bind_type, 0L); |
75f92628 |
88 | |
bf49b057 |
89 | DLDEBUG(2,PerlIO_printf(Perl_debug_log, " libref=%x\n", obj)); |
75f92628 |
90 | end: |
a0d0e21e |
91 | ST(0) = sv_newmortal() ; |
92 | if (obj == NULL) |
cea2e8a9 |
93 | SaveError(aTHX_ "%s",Strerror(errno)); |
a0d0e21e |
94 | else |
3175b8cd |
95 | sv_setiv( ST(0), PTR2IV(obj) ); |
a0d0e21e |
96 | |
97 | |
98 | void * |
99 | dl_find_symbol(libhandle, symbolname) |
100 | void * libhandle |
101 | char * symbolname |
102 | CODE: |
103 | shl_t obj = (shl_t) libhandle; |
104 | void *symaddr = NULL; |
105 | int status; |
106 | #ifdef __hp9000s300 |
7a3f2258 |
107 | symbolname = Perl_form_nocontext("_%s", symbolname); |
a0d0e21e |
108 | #endif |
bf49b057 |
109 | DLDEBUG(2, PerlIO_printf(Perl_debug_log, |
46fc3d4c |
110 | "dl_find_symbol(handle=%lx, symbol=%s)\n", |
111 | (unsigned long) libhandle, symbolname)); |
112 | |
8e07c86e |
113 | ST(0) = sv_newmortal() ; |
114 | errno = 0; |
115 | |
a0d0e21e |
116 | status = shl_findsym(&obj, symbolname, TYPE_PROCEDURE, &symaddr); |
bf49b057 |
117 | DLDEBUG(2,PerlIO_printf(Perl_debug_log, " symbolref(PROCEDURE) = %x\n", symaddr)); |
8e07c86e |
118 | |
119 | if (status == -1 && errno == 0) { /* try TYPE_DATA instead */ |
120 | status = shl_findsym(&obj, symbolname, TYPE_DATA, &symaddr); |
bf49b057 |
121 | DLDEBUG(2,PerlIO_printf(Perl_debug_log, " symbolref(DATA) = %x\n", symaddr)); |
8e07c86e |
122 | } |
123 | |
75f92628 |
124 | if (status == -1) { |
cea2e8a9 |
125 | SaveError(aTHX_ "%s",(errno) ? Strerror(errno) : "Symbol not found") ; |
75f92628 |
126 | } else { |
3175b8cd |
127 | sv_setiv( ST(0), PTR2IV(symaddr) ); |
75f92628 |
128 | } |
a0d0e21e |
129 | |
130 | |
8e07c86e |
131 | void |
a0d0e21e |
132 | dl_undef_symbols() |
133 | PPCODE: |
134 | |
135 | |
136 | |
137 | # These functions should not need changing on any platform: |
138 | |
139 | void |
140 | dl_install_xsub(perl_name, symref, filename="$Package") |
141 | char * perl_name |
142 | void * symref |
143 | char * filename |
144 | CODE: |
bf49b057 |
145 | DLDEBUG(2,PerlIO_printf(Perl_debug_log, "dl_install_xsub(name=%s, symref=%x)\n", |
a0d0e21e |
146 | perl_name, symref)); |
cea2e8a9 |
147 | ST(0) = sv_2mortal(newRV((SV*)newXS(perl_name, |
148 | (void(*)(pTHX_ CV *))symref, |
149 | filename))); |
a0d0e21e |
150 | |
151 | |
152 | char * |
153 | dl_error() |
154 | CODE: |
155 | RETVAL = LastError ; |
156 | OUTPUT: |
157 | RETVAL |
158 | |
159 | # end. |