3 * Platform: Symbian 7.0s
4 * Author: Jarkko Hietaniemi <jarkko.hietaniemi@nokia.com>
5 * Copyright: 2004, Nokia
6 * License: Artistic/GPL
11 * In Symbian DLLs there is no name information, one can only access
12 * the functions by their ordinals. Perl, however, very much would like
13 * to load functions by their names. We fake this by having a special
14 * setup function at the ordinal 1 (this is arranged by building the DLLs
15 * in a special way). The setup function builds a Perl hash mapping the
16 * names to the ordinals, and the hash is then used by dlsym().
24 /* This is a useful pattern: first include the Symbian headers,
25 * only after that the Perl ones. Otherwise you will get a lot
26 * trouble because of Symbian's New(), Copy(), etc definitions. */
29 #define PERL_IN_DL_SYMBIAN_XS
37 void *dlopen(const char *filename, int flag);
38 void *dlsym(void *handle, const char *symbol);
39 int dlclose(void *handle);
40 const char *dlerror(void);
42 extern void* memset(void *s, int c, size_t n);
43 extern size_t strlen(const char *s);
49 #define RTLD_LAZY 0x0001
50 #define RTLD_NOW 0x0002
51 #define RTLD_GLOBAL 0x0004
57 /* No need to pull in symbian_dll.cpp for this. */
58 #define symbian_get_vars() ((void*)Dll::Tls())
60 const TInt KPerlDllSetupFunction = 1;
66 } PerlSymbianLibHandle;
68 typedef void (*PerlSymbianLibInit)(void *);
70 void* dlopen(const char *filename, int flags) {
71 TBuf16<KMaxFileName> utf16fn;
72 const TUint8* utf8fn = (const TUint8*)filename;
73 PerlSymbianLibHandle* h = NULL;
77 CnvUtfConverter::ConvertToUnicodeFromUtf8(utf16fn, TPtrC8(utf8fn));
78 if (error == KErrNone) {
79 h = new PerlSymbianLibHandle;
82 h->symbols = (HV *)NULL;
87 if (h && error == KErrNone) {
88 error = (h->handle).Load(utf16fn);
89 if (error == KErrNone) {
90 TLibraryFunction init = (h->handle).Lookup(KPerlDllSetupFunction);
91 ((PerlSymbianLibInit)init)(h);
104 void* dlsym(void *handle, const char *symbol) {
107 PerlSymbianLibHandle* h = (PerlSymbianLibHandle*)handle;
108 HV* symbols = h->symbols;
110 SV** svp = hv_fetch(symbols, symbol, strlen(symbol), FALSE);
111 if (svp && *svp && SvIOK(*svp)) {
114 return (void*)((h->handle).Lookup(ord));
121 int dlclose(void *handle) {
122 PerlSymbianLibHandle* h = (PerlSymbianLibHandle*)handle;
127 hv_undef(h->symbols);
135 const char* dlerror(void) {
136 return 0; /* Bad interface: assumes static data. */
140 dl_private_init(pTHX)
142 (void)dl_generic_private_init(aTHX);
145 MODULE = DynaLoader PACKAGE = DynaLoader
150 (void)dl_private_init(aTHX);
154 dl_load_file(filename, flags=0)
158 PerlSymbianLibHandle* h;
161 ST(0) = sv_newmortal();
162 h = (PerlSymbianLibHandle*)dlopen(filename, flags);
163 if (h && h->error == KErrNone)
164 sv_setiv(ST(0), PTR2IV(h));
166 SaveError(aTHX_ "(dl_load_file %s %d)"
167 filename, h ? h->error : -1);
172 dl_unload_file(libhandle)
175 RETVAL = (dlclose(libhandle) == 0 ? 1 : 0);
181 dl_find_symbol(libhandle, symbolname, ign_err=0)
188 PerlSymbianLibHandle* h = (PerlSymbianLibHandle*)libhandle;
189 sym = dlsym(libhandle, symbolname);
190 ST(0) = sv_newmortal();
192 sv_setiv(ST(0), PTR2IV(sym));
195 SaveError(aTHX_ "(dl_find_symbol %s %d)",
196 symbolname, h ? h->error : -1);
206 # These functions should not need changing on any platform:
209 dl_install_xsub(perl_name, symref, filename="$Package")
212 const char * filename
214 ST(0) = sv_2mortal(newRV((SV*)newXS_flags(perl_name,
215 (void(*)(pTHX_ CV *))symref,
217 XS_DYNAMIC_FILENAME)));
224 RETVAL = newSVsv(MY_CXT.x_dl_last_error);
228 #if defined(USE_ITHREADS)
235 PERL_UNUSED_VAR(items);
237 /* MY_CXT_CLONE just does a memcpy on the whole structure, so to avoid
238 * using Perl variables that belong to another thread, we create our
239 * own for this thread.
241 MY_CXT.x_dl_last_error = newSVpvs("");