📄 dl_aix.xs
字号:
if (--mp->refCnt > 0) return 0; result = UNLOAD(mp->entry); if (result == -1) { errvalid++; strerrorcpy(errbuf, errno); } if (mp->exports) { register ExportPtr ep; register int i; for (ep = mp->exports, i = mp->nExports; i; i--, ep++) if (ep->name) safefree(ep->name); safefree(mp->exports); } if (mp == modList) modList = mp->next; else { for (mp1 = modList; mp1; mp1 = mp1->next) if (mp1->next == mp) { mp1->next = mp->next; break; } } safefree(mp->name); safefree(mp); return result;}/* Added by Wayne Scott * This is needed because the ldopen system call calls * calloc to allocated a block of date. The ldclose call calls free. * Without this we get this system calloc and perl's free, resulting * in a "Bad free" message. This way we always use perl's malloc. */void *calloc(size_t ne, size_t sz) { void *out; out = (void *) safemalloc(ne*sz); memzero(out, ne*sz); return(out);} /* * Build the export table from the XCOFF .loader section. */static int readExports(ModulePtr mp){ dTHX; LDFILE *ldp = NULL; AIX_SCNHDR sh; AIX_LDHDR *lhp; char *ldbuf; AIX_LDSYM *ls; int i; ExportPtr ep; if ((ldp = ldopen(mp->name, ldp)) == NULL) { struct ld_info *lp; char *buf; int size = 4*1024; if (errno != ENOENT) { errvalid++; strcpy(errbuf, "readExports: "); strerrorcat(errbuf, errno); return -1; } /* * The module might be loaded due to the LIBPATH * environment variable. Search for the loaded * module using L_GETINFO. */ if ((buf = safemalloc(size)) == NULL) { errvalid++; strcpy(errbuf, "readExports: "); strerrorcat(errbuf, errno); return -1; } while ((i = loadquery(L_GETINFO, buf, size)) == -1 && errno == ENOMEM) { safefree(buf); size += 4*1024; if ((buf = safemalloc(size)) == NULL) { errvalid++; strcpy(errbuf, "readExports: "); strerrorcat(errbuf, errno); return -1; } } if (i == -1) { errvalid++; strcpy(errbuf, "readExports: "); strerrorcat(errbuf, errno); safefree(buf); return -1; } /* * Traverse the list of loaded modules. The entry point * returned by LOAD() does actually point to the data * segment origin. */ lp = (struct ld_info *)buf; while (lp) { if (lp->ldinfo_dataorg == mp->entry) { ldp = ldopen(lp->ldinfo_filename, ldp); break; } if (lp->ldinfo_next == 0) lp = NULL; else lp = (struct ld_info *)((char *)lp + lp->ldinfo_next); } safefree(buf); if (!ldp) { errvalid++; strcpy(errbuf, "readExports: "); strerrorcat(errbuf, errno); return -1; } }#ifdef USE_64_BIT_ALL if (TYPE(ldp) != U803XTOCMAGIC) {#else if (TYPE(ldp) != U802TOCMAGIC) {#endif errvalid++; strcpy(errbuf, "readExports: bad magic"); while(ldclose(ldp) == FAILURE) ; return -1; } if (ldnshread(ldp, _LOADER, &sh) != SUCCESS) { errvalid++; strcpy(errbuf, "readExports: cannot read loader section header"); while(ldclose(ldp) == FAILURE) ; return -1; } /* * We read the complete loader section in one chunk, this makes * finding long symbol names residing in the string table easier. */ if ((ldbuf = (char *)safemalloc(sh.s_size)) == NULL) { errvalid++; strcpy(errbuf, "readExports: "); strerrorcat(errbuf, errno); while(ldclose(ldp) == FAILURE) ; return -1; } if (FSEEK(ldp, sh.s_scnptr, BEGINNING) != OKFSEEK) { errvalid++; strcpy(errbuf, "readExports: cannot seek to loader section"); safefree(ldbuf); while(ldclose(ldp) == FAILURE) ; return -1; }/* This first case is a hack, since it assumes that the 3rd parameter to FREAD is 1. See the redefinition of FREAD above to see how this works. */ if (FREAD(ldbuf, sh.s_size, 1, ldp) != 1) { errvalid++; strcpy(errbuf, "readExports: cannot read loader section"); safefree(ldbuf); while(ldclose(ldp) == FAILURE) ; return -1; } lhp = (AIX_LDHDR *)ldbuf; ls = (AIX_LDSYM *)(ldbuf+AIX_LDHDRSZ); /* * Count the number of exports to include in our export table. */ for (i = lhp->l_nsyms; i; i--, ls++) { if (!LDR_EXPORT(*ls)) continue; mp->nExports++; } Newz(1001, mp->exports, mp->nExports, Export); if (mp->exports == NULL) { errvalid++; strcpy(errbuf, "readExports: "); strerrorcat(errbuf, errno); safefree(ldbuf); while(ldclose(ldp) == FAILURE) ; return -1; } /* * Fill in the export table. All entries are relative to * the entry point we got from load. */ ep = mp->exports; ls = (AIX_LDSYM *)(ldbuf+AIX_LDHDRSZ); for (i = lhp->l_nsyms; i; i--, ls++) { char *symname; if (!LDR_EXPORT(*ls)) continue;#ifndef USE_64_BIT_ALL if (ls->l_zeroes == 0)#endif symname = ls->l_offset+lhp->l_stoff+ldbuf;#ifndef USE_64_BIT_ALL else symname = ls->l_name;#endif ep->name = savepv(symname); ep->addr = (void *)((unsigned long)mp->entry + ls->l_value); ep++; } safefree(ldbuf); while(ldclose(ldp) == FAILURE) ; return 0;}/* * Find the main modules entry point. This is used as export pointer * for loadbind() to be able to resolve references to the main part. */static void * findMain(void){ struct ld_info *lp; char *buf; int size = 4*1024; int i; void *ret; if ((buf = safemalloc(size)) == NULL) { errvalid++; strcpy(errbuf, "findMain: "); strerrorcat(errbuf, errno); return NULL; } while ((i = loadquery(L_GETINFO, buf, size)) == -1 && errno == ENOMEM) { safefree(buf); size += 4*1024; if ((buf = safemalloc(size)) == NULL) { errvalid++; strcpy(errbuf, "findMain: "); strerrorcat(errbuf, errno); return NULL; } } if (i == -1) { errvalid++; strcpy(errbuf, "findMain: "); strerrorcat(errbuf, errno); safefree(buf); return NULL; } /* * The first entry is the main module. The entry point * returned by load() does actually point to the data * segment origin. */ lp = (struct ld_info *)buf; ret = lp->ldinfo_dataorg; safefree(buf); return ret;}/* dl_dlopen.xs * * Platform: SunOS/Solaris, possibly others which use dlopen. * Author: Paul Marquess (Paul.Marquess@btinternet.com) * Created: 10th July 1994 * * Modified: * 15th July 1994 - Added code to explicitly save any error messages. * 3rd August 1994 - Upgraded to v3 spec. * 9th August 1994 - Changed to use IV * 10th August 1994 - Tim Bunce: Added RTLD_LAZY, switchable debugging, * basic FreeBSD support, removed ClearError * *//* Porting notes: see dl_dlopen.xs*/#include "dlutils.c" /* SaveError() etc */static voiddl_private_init(pTHX){ (void)dl_generic_private_init(aTHX);} MODULE = DynaLoader PACKAGE = DynaLoaderBOOT: (void)dl_private_init(aTHX);void *dl_load_file(filename, flags=0) char * filename int flags CODE: DLDEBUG(1,PerlIO_printf(Perl_debug_log, "dl_load_file(%s,%x):\n", filename,flags)); if (flags & 0x01) Perl_warn(aTHX_ "Can't make loaded symbols global on this platform while loading %s",filename); RETVAL = dlopen(filename, 1) ; DLDEBUG(2,PerlIO_printf(Perl_debug_log, " libref=%x\n", RETVAL)); ST(0) = sv_newmortal() ; if (RETVAL == NULL) SaveError(aTHX_ "%s",dlerror()) ; else sv_setiv( ST(0), PTR2IV(RETVAL) );intdl_unload_file(libref) void * libref CODE: DLDEBUG(1,PerlIO_printf(Perl_debug_log, "dl_unload_file(%lx):\n", libref)); RETVAL = (dlclose(libref) == 0 ? 1 : 0); if (!RETVAL) SaveError(aTHX_ "%s", dlerror()) ; DLDEBUG(2,PerlIO_printf(Perl_debug_log, " retval = %d\n", RETVAL)); OUTPUT: RETVALvoid *dl_find_symbol(libhandle, symbolname) void * libhandle char * symbolname CODE: DLDEBUG(2,PerlIO_printf(Perl_debug_log, "dl_find_symbol(handle=%x, symbol=%s)\n", libhandle, symbolname)); RETVAL = dlsym(libhandle, symbolname); DLDEBUG(2,PerlIO_printf(Perl_debug_log, " symbolref = %x\n", RETVAL)); ST(0) = sv_newmortal() ; if (RETVAL == NULL) SaveError(aTHX_ "%s",dlerror()) ; else sv_setiv( ST(0), PTR2IV(RETVAL));voiddl_undef_symbols() PPCODE:# These functions should not need changing on any platform:voiddl_install_xsub(perl_name, symref, filename="$Package") char * perl_name void * symref char * filename CODE: DLDEBUG(2,PerlIO_printf(Perl_debug_log, "dl_install_xsub(name=%s, symref=%x)\n", perl_name, symref)); ST(0) = sv_2mortal(newRV((SV*)newXS(perl_name, (void(*)(pTHX_ CV *))symref, filename)));char *dl_error() CODE: RETVAL = LastError ; OUTPUT: RETVAL# end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -