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. */
36 void *dlopen(const char *filename, int flag);
37 void *dlsym(void *handle, const char *symbol);
38 int dlclose(void *handle);
39 const char *dlerror(void);
41 extern void* memset(void *s, int c, size_t n);
42 extern size_t strlen(const char *s);
48 #define RTLD_LAZY 0x0001
49 #define RTLD_NOW 0x0002
50 #define RTLD_GLOBAL 0x0004
56 /* No need to pull in symbian_dll.cpp for this. */
57 #define symbian_get_vars() ((void*)Dll::Tls())
59 const TInt KPerlDllSetupFunction = 1;
65 } PerlSymbianLibHandle;
67 typedef void (*PerlSymbianLibInit)(void *);
69 void* dlopen(const char *filename, int flags) {
70 TBuf16<KMaxFileName> utf16fn;
71 const TUint8* utf8fn = (const TUint8*)filename;
72 PerlSymbianLibHandle* h = NULL;
76 CnvUtfConverter::ConvertToUnicodeFromUtf8(utf16fn, TPtrC8(utf8fn));
77 if (error == KErrNone) {
78 h = new PerlSymbianLibHandle;
86 if (h && error == KErrNone) {
87 error = (h->handle).Load(utf16fn);
88 if (error == KErrNone) {
89 TLibraryFunction init = (h->handle).Lookup(KPerlDllSetupFunction);
90 ((PerlSymbianLibInit)init)(h);
103 void* dlsym(void *handle, const char *symbol) {
106 PerlSymbianLibHandle* h = (PerlSymbianLibHandle*)handle;
107 HV* symbols = h->symbols;
109 SV** svp = hv_fetch(symbols, symbol, strlen(symbol), FALSE);
110 if (svp && *svp && SvIOK(*svp)) {
113 return (void*)((h->handle).Lookup(ord));
120 int dlclose(void *handle) {
121 PerlSymbianLibHandle* h = (PerlSymbianLibHandle*)handle;
126 hv_undef(h->symbols);
134 const char* dlerror(void) {
135 return 0; /* Bad interface: assumes static data. */
139 dl_private_init(pTHX)
141 (void)dl_generic_private_init(aTHX);
144 MODULE = DynaLoader PACKAGE = DynaLoader
149 (void)dl_private_init(aTHX);
153 dl_load_file(filename, flags=0)
157 PerlSymbianLibHandle* h;
160 ST(0) = sv_newmortal();
161 h = (PerlSymbianLibHandle*)dlopen(filename, flags);
162 if (h && h->error == KErrNone)
163 sv_setiv(ST(0), PTR2IV(h));
165 PerlIO_printf(Perl_debug_log, "(dl_load_file %s %d)",
166 filename, h ? h->error : -1);
171 dl_unload_file(libhandle)
174 RETVAL = (dlclose(libhandle) == 0 ? 1 : 0);
180 dl_find_symbol(libhandle, symbolname)
186 PerlSymbianLibHandle* h = (PerlSymbianLibHandle*)libhandle;
187 sym = dlsym(libhandle, symbolname);
188 ST(0) = sv_newmortal();
190 sv_setiv(ST(0), PTR2IV(sym));
192 PerlIO_printf(Perl_debug_log, "(dl_find_symbol %s %d)",
193 symbolname, h ? h->error : -1);
202 # These functions should not need changing on any platform:
205 dl_install_xsub(perl_name, symref, filename="$Package")
210 ST(0) = sv_2mortal(newRV((SV*)newXS(perl_name,
211 (void(*)(pTHX_ CV *))symref,
219 RETVAL = dl_last_error;