3 * Platform: Apple Rhapsody 5.0
4 * Based on: dl_next.xs by Paul Marquess
5 * Based on: dl_dlopen.xs by Anno Siegel
6 * Created: Aug 15th, 1994
11 And Gandalf said: 'Many folk like to know beforehand what is to
12 be set on the table; but those who have laboured to prepare the
13 feast like to keep their secret; for wonder makes the words of
19 dl_next.xs is itself a port from dl_dlopen.xs by Paul Marquess. It
20 should not be used as a base for further ports though it may be used
21 as an example for how dl_dlopen.xs can be ported to other platforms.
23 The method used here is just to supply the sun style dlopen etc.
24 functions in terms of NeXTs rld_*. The xs code proper is unchanged
27 The port could use some streamlining. For one, error handling could
38 #define DL_LOADONCEONLY
40 #include "dlutils.c" /* SaveError() etc */
43 #import <mach-o/dyld.h>
45 static char * dl_last_error = (char *) 0;
46 static AV *dl_resolve_using = Nullav;
48 static char *dlerror()
53 int dlclose(handle) /* stub only */
64 static void TranslateError
65 (const char *path, enum dyldErrorSource type, int number)
70 static char *OFIErrorStrings[] =
72 "%s(%d): Object Image Load Failure\n",
73 "%s(%d): Object Image Load Success\n",
74 "%s(%d): Not an recognisable object file\n",
75 "%s(%d): No valid architecture\n",
76 "%s(%d): Object image has an invalid format\n",
77 "%s(%d): Invalid access (permissions?)\n",
78 "%s(%d): Unknown error code from NSCreateObjectFileImageFromFile\n",
80 #define NUM_OFI_ERRORS (sizeof(OFIErrorStrings) / sizeof(OFIErrorStrings[0]))
86 if (index > NUM_OFI_ERRORS - 1)
87 index = NUM_OFI_ERRORS - 1;
88 error = form(OFIErrorStrings[index], path, number);
92 error = form("%s(%d): Totally unknown error type %d\n",
96 safefree(dl_last_error);
97 dl_last_error = savepv(error);
100 static char *dlopen(char *path, int mode /* mode is ignored */)
103 NSObjectFileImage ofile;
104 NSModule handle = NULL;
106 dyld_result = NSCreateObjectFileImageFromFile(path, &ofile);
107 if (dyld_result != NSObjectFileImageSuccess)
108 TranslateError(path, OFImage, dyld_result);
111 // NSLinkModule will cause the run to abort on any link error's
112 // not very friendly but the error recovery functionality is limited.
113 handle = NSLinkModule(ofile, path, TRUE);
120 dlsym(handle, symbol)
126 if (NSIsSymbolNameDefined(symbol))
127 addr = NSAddressOfSymbol(NSLookupAndBindSymbol(symbol));
136 /* ----- code from dl_dlopen.xs below here ----- */
140 dl_private_init(pTHX)
142 (void)dl_generic_private_init(aTHX);
143 dl_resolve_using = get_av("DynaLoader::dl_resolve_using", GV_ADDMULTI);
146 MODULE = DynaLoader PACKAGE = DynaLoader
149 (void)dl_private_init(aTHX);
154 dl_load_file(filename, flags=0)
160 DLDEBUG(1,PerlIO_printf(Perl_debug_log, "dl_load_file(%s,%x):\n", filename,flags));
162 Perl_warn(aTHX_ "Can't make loaded symbols global on this platform while loading %s",filename);
163 RETVAL = dlopen(filename, mode) ;
164 DLDEBUG(2,PerlIO_printf(Perl_debug_log, " libref=%x\n", RETVAL));
165 ST(0) = sv_newmortal() ;
167 SaveError(aTHX_ "%s",dlerror()) ;
169 sv_setiv( ST(0), PTR2IV(RETVAL) );
173 dl_find_symbol(libhandle, symbolname)
177 symbolname = form("_%s", symbolname);
178 DLDEBUG(2, PerlIO_printf(Perl_debug_log,
179 "dl_find_symbol(handle=%lx, symbol=%s)\n",
180 (unsigned long) libhandle, symbolname));
181 RETVAL = dlsym(libhandle, symbolname);
182 DLDEBUG(2, PerlIO_printf(Perl_debug_log,
183 " symbolref = %lx\n", (unsigned long) RETVAL));
184 ST(0) = sv_newmortal() ;
186 SaveError(aTHX_ "%s",dlerror()) ;
188 sv_setiv( ST(0), PTR2IV(RETVAL) );
197 # These functions should not need changing on any platform:
200 dl_install_xsub(perl_name, symref, filename="$Package")
205 DLDEBUG(2,PerlIO_printf(Perl_debug_log, "dl_install_xsub(name=%s, symref=%x)\n",
207 ST(0) = sv_2mortal(newRV((SV*)newXS(perl_name,
208 (void(*)(pTHX_ CV *))symref,