From bca9364f3f4a2376edbcf57a34f704ce28be21ba Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Fri, 21 Jul 2006 18:41:46 -0400 Subject: [PATCH 1/3] Remove the loader's required and referenced symbol lists, dead code. --- hw/xfree86/common/xf86Helper.c | 21 +--- hw/xfree86/loader/loader.c | 166 +------------------------------- hw/xfree86/loader/loaderProcs.h | 5 - 3 files changed, 4 insertions(+), 188 deletions(-) diff --git a/hw/xfree86/common/xf86Helper.c b/hw/xfree86/common/xf86Helper.c index b3978f7bf..c7d3fae7a 100644 --- a/hw/xfree86/common/xf86Helper.c +++ b/hw/xfree86/common/xf86Helper.c @@ -2448,44 +2448,25 @@ xf86LoaderCheckSymbol(const char *name) return LoaderSymbol(name) != NULL; } +/* These two are just ABI stubs, they don't do anything in dlloader world */ _X_EXPORT void xf86LoaderReqSymLists(const char **list0, ...) { - va_list ap; - - va_start(ap, list0); - LoaderVReqSymLists(list0, ap); - va_end(ap); } _X_EXPORT void xf86LoaderReqSymbols(const char *sym0, ...) { - va_list ap; - - va_start(ap, sym0); - LoaderVReqSymbols(sym0, ap); - va_end(ap); } _X_EXPORT void xf86LoaderRefSymLists(const char **list0, ...) { - va_list ap; - - va_start(ap, list0); - LoaderVRefSymLists(list0, ap); - va_end(ap); } _X_EXPORT void xf86LoaderRefSymbols(const char *sym0, ...) { - va_list ap; - - va_start(ap, sym0); - LoaderVRefSymbols(sym0, ap); - va_end(ap); } diff --git a/hw/xfree86/loader/loader.c b/hw/xfree86/loader/loader.c index a5c5b2c8e..42a9d3cd3 100644 --- a/hw/xfree86/loader/loader.c +++ b/hw/xfree86/loader/loader.c @@ -97,22 +97,6 @@ static int refCount[MAX_HANDLE]; */ static int moduleseq = 0; -typedef struct { - int num; - const char **list; -} symlist; - -/* - * List of symbols that may be referenced, and which are allowed to be - * unresolved providing that they don't appear on the "reqired" list. - */ -static symlist refList = { 0, NULL }; - -/* List of symbols that must not be unresolved */ -static symlist reqList = { 0, NULL }; - -static int fatalReqSym = 0; - /* Prototypes for static functions. */ static loaderPtr _LoaderListPush(void); static loaderPtr _LoaderListPop(int); @@ -300,165 +284,25 @@ _LoaderModuleToName(int module) return 0; } -/* - * Add a list of symbols to the referenced list. - */ - -static void -AppendSymbol(symlist * list, const char *sym) -{ - list->list = xnfrealloc(list->list, (list->num + 1) * sizeof(char **)); - /* copy the symbol, since it comes from a module - that can be unloaded later */ - list->list[list->num] = xnfstrdup(sym); - list->num++; -} - -static void -AppendSymList(symlist * list, const char **syms) -{ - while (*syms) { - AppendSymbol(list, *syms); - syms++; - } -} - -static int -SymInList(symlist * list, char *sym) -{ - int i; - - for (i = 0; i < list->num; i++) - if (strcmp(list->list[i], sym) == 0) - return 1; - - return 0; -} - -void -LoaderVRefSymbols(const char *sym0, va_list args) -{ - const char *s; - - if (sym0 == NULL) - return; - - s = sym0; - do { - AppendSymbol(&refList, s); - s = va_arg(args, const char *); - } while (s != NULL); -} - +/* These four are just ABI stubs */ _X_EXPORT void LoaderRefSymbols(const char *sym0, ...) { - va_list ap; - - va_start(ap, sym0); - LoaderVRefSymbols(sym0, ap); - va_end(ap); -} - -void -LoaderVRefSymLists(const char **list0, va_list args) -{ - const char **l; - - if (list0 == NULL) - return; - - l = list0; - do { - AppendSymList(&refList, l); - l = va_arg(args, const char **); - } while (l != NULL); } _X_EXPORT void LoaderRefSymLists(const char **list0, ...) { - va_list ap; - - va_start(ap, list0); - LoaderVRefSymLists(list0, ap); - va_end(ap); -} - -void -LoaderVReqSymLists(const char **list0, va_list args) -{ - const char **l; - - if (list0 == NULL) - return; - - l = list0; - do { - AppendSymList(&reqList, l); - l = va_arg(args, const char **); - } while (l != NULL); } _X_EXPORT void LoaderReqSymLists(const char **list0, ...) { - va_list ap; - - va_start(ap, list0); - LoaderVReqSymLists(list0, ap); - va_end(ap); -} - -void -LoaderVReqSymbols(const char *sym0, va_list args) -{ - const char *s; - - if (sym0 == NULL) - return; - - s = sym0; - do { - AppendSymbol(&reqList, s); - s = va_arg(args, const char *); - } while (s != NULL); } _X_EXPORT void LoaderReqSymbols(const char *sym0, ...) { - va_list ap; - - va_start(ap, sym0); - LoaderVReqSymbols(sym0, ap); - va_end(ap); -} - -/* - * _LoaderHandleUnresolved() decides what to do with an unresolved - * symbol. Symbols that are not on the "referenced" or "required" lists - * get a warning if they are unresolved. Symbols that are on the "required" - * list generate a fatal error if they are unresolved. - */ - -int -_LoaderHandleUnresolved(char *symbol, char *module) -{ - int fatalsym = 0; - - if (xf86ShowUnresolved && !fatalsym) { - if (SymInList(&reqList, symbol)) { - fatalReqSym = 1; - ErrorF("Required symbol %s from module %s is unresolved!\n", - symbol, module); - } - if (!SymInList(&refList, symbol)) { - ErrorF("Symbol %s from module %s is unresolved!\n", - symbol, module); - } - } - return (fatalsym); } /* Public Interface to the loader. */ @@ -578,15 +422,11 @@ LoaderSymbol(const char *sym) return (DLFindSymbol(sym)); } +/* more stub */ _X_EXPORT int LoaderCheckUnresolved(int delay_flag) { - int ret = 0; - - if (fatalReqSym) - FatalError("Some required symbols were unresolved\n"); - - return ret; + return 0; } int diff --git a/hw/xfree86/loader/loaderProcs.h b/hw/xfree86/loader/loaderProcs.h index 0e77e6b3a..324fa9e2b 100644 --- a/hw/xfree86/loader/loaderProcs.h +++ b/hw/xfree86/loader/loaderProcs.h @@ -103,11 +103,6 @@ ModuleDescPtr AddSibling(ModuleDescPtr head, ModuleDescPtr new); void LoaderSetPath(const char *path); void LoaderSortExtensions(void); -void LoaderVReqSymLists(const char **, va_list args); -void LoaderVReqSymbols(const char *, va_list args); -void LoaderVRefSymLists(const char **, va_list args); -void LoaderVRefSymbols(const char *, va_list args); - void LoaderShowStack(void); void *LoaderSymbolHandle(const char *, int); int LoaderUnload(int); From 63dfaa1d5ba556e09314ec914936e5471aab94b0 Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Fri, 21 Jul 2006 18:47:18 -0400 Subject: [PATCH 2/3] Delete internal usage of the symbol ref/req lists. --- hw/xfree86/ddc/xf86DDC.c | 17 ----------------- hw/xfree86/dri/drimodule.c | 31 +------------------------------ hw/xfree86/vbe/vbe.c | 7 ------- hw/xfree86/vbe/vbe_module.c | 16 ---------------- 4 files changed, 1 insertion(+), 70 deletions(-) diff --git a/hw/xfree86/ddc/xf86DDC.c b/hw/xfree86/ddc/xf86DDC.c index 564e72e3c..dd64bd56f 100644 --- a/hw/xfree86/ddc/xf86DDC.c +++ b/hw/xfree86/ddc/xf86DDC.c @@ -15,15 +15,6 @@ static const OptionInfoRec *DDCAvailableOptions(void *unused); -const char *i2cSymbols[] = { - "xf86CreateI2CDevRec", - "xf86I2CDevInit", - "xf86I2CWriteRead", - "xf86I2CFindDev", - "xf86DestroyI2CDevRec", - NULL -}; - static MODULESETUPPROTO(ddcSetup); static XF86ModuleVersionInfo ddcVersRec = @@ -58,12 +49,6 @@ ddcSetup(pointer module, pointer opts, int *errmaj, int *errmin) if (!setupDone) { setupDone = TRUE; xf86AddModuleInfo(&DDC, module); - /* - * Tell the loader about symbols from other modules that this module - * might refer to. - */ - LoaderRefSymLists(i2cSymbols, NULL); - } /* * The return value must be non-NULL on success even though there @@ -348,8 +333,6 @@ DDCRead_DDC2(int scrnIndex, I2CBusPtr pBus, int start, int len) unsigned char *R_Buffer; int i; - xf86LoaderReqSymLists(i2cSymbols, NULL); - if (!(dev = xf86I2CFindDev(pBus, 0x00A0))) { dev = xf86CreateI2CDevRec(); dev->DevName = "ddc2"; diff --git a/hw/xfree86/dri/drimodule.c b/hw/xfree86/dri/drimodule.c index 427065d91..331de8287 100644 --- a/hw/xfree86/dri/drimodule.c +++ b/hw/xfree86/dri/drimodule.c @@ -68,32 +68,6 @@ static ExtensionModule XF86DRIExt = NULL }; -static const char *drmSymbols[] = { - "drmAddContextTag", - "drmAddMap", - "drmAuthMagic", - "drmAvailable", - "drmClose", - "drmCreateContext", - "drmCreateDrawable", - "drmDelContextTag", - "drmDestroyContext", - "drmDestroyDrawable", - "drmFreeReservedContextList", - "drmGetContextTag", - "drmGetLock", - "drmGetReservedContextList", - "drmInstallSIGIOHandler", - "drmMap", - "drmOpen", - "drmRemoveSIGIOHandler", - "drmSetBusid", - "drmSetContextFlags", - "drmUnlock", - "drmUnmap", - NULL -}; - _X_EXPORT XF86ModuleData driModuleData = { &VersRec, driSetup, NULL }; static pointer @@ -110,10 +84,7 @@ driSetup(pointer module, pointer opts, int *errmaj, int *errmin) if (!drm) { if (errmaj) *errmaj = LDR_NOSUBENT; - } - else { - LoaderReqSymLists(drmSymbols, NULL); - LoaderRefSymbols("noPanoramiXExtension", NULL); + } else { LoadExtension(&XF86DRIExt, FALSE); } } else { diff --git a/hw/xfree86/vbe/vbe.c b/hw/xfree86/vbe/vbe.c index c0e983391..3ca985167 100644 --- a/hw/xfree86/vbe/vbe.c +++ b/hw/xfree86/vbe/vbe.c @@ -39,11 +39,6 @@ static unsigned char * vbeReadEDID(vbeInfoPtr pVbe); static Bool vbeProbeDDC(vbeInfoPtr pVbe); -const char *vbe_ddcSymbols[] = { - "xf86InterpretEDID", - NULL -}; - static const char vbeVersionString[] = "VBE2"; vbeInfoPtr @@ -327,8 +322,6 @@ vbeDoEDID(vbeInfoPtr pVbe, pointer pDDCModule) xf86LoadSubModule(xf86Screens[pVbe->pInt10->scrnIndex], "ddc"); if (!pModule) return NULL; - - xf86LoaderReqSymLists(vbe_ddcSymbols, NULL); } DDC_data = vbeReadEDID(pVbe); diff --git a/hw/xfree86/vbe/vbe_module.c b/hw/xfree86/vbe/vbe_module.c index 7c7d87660..cf37ef951 100644 --- a/hw/xfree86/vbe/vbe_module.c +++ b/hw/xfree86/vbe/vbe_module.c @@ -6,8 +6,6 @@ #include "xf86str.h" #include "vbe.h" -extern const char *vbe_ddcSymbols[]; - static MODULESETUPPROTO(vbeSetup); static XF86ModuleVersionInfo vbeVersRec = @@ -29,19 +27,5 @@ _X_EXPORT XF86ModuleData vbeModuleData = { &vbeVersRec, vbeSetup, NULL }; static pointer vbeSetup(pointer module, pointer opts, int *errmaj, int *errmin) { - static Bool setupDone = FALSE; - - if (!setupDone) { - setupDone = TRUE; - LoaderRefSymLists(vbe_ddcSymbols,NULL); - /* - * Tell the loader about symbols from other modules that this module - * might refer to. - */ - } - /* - * The return value must be non-NULL on success even though there - * is no TearDownProc. - */ return (pointer)1; } From 6cf844ab69926b6d23619a12c97734af3881ba67 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Fri, 21 Jul 2006 19:57:28 -0400 Subject: [PATCH 3/3] loader: walk directory paths with readdir(), don't stat() everything Walk the directories with readdir, and don't stat everything we can find. Thanks to davej for the public humiliation reminding me to go back and re-fix this one. --- hw/xfree86/loader/loadmod.c | 93 ++++++++++++++++++++++--------------- 1 file changed, 56 insertions(+), 37 deletions(-) diff --git a/hw/xfree86/loader/loadmod.c b/hw/xfree86/loader/loadmod.c index fd84a924c..53dcffef3 100644 --- a/hw/xfree86/loader/loadmod.c +++ b/hw/xfree86/loader/loadmod.c @@ -389,23 +389,65 @@ FreeSubdirs(const char **subdirs) } static char * -FindModule(const char *module, const char *dir, const char **subdirlist, +FindModuleInSubdir(const char *dirpath, const char *module) +{ + struct dirent *direntry = NULL; + DIR *dir = NULL; + char *ret = NULL, tmpBuf[PATH_MAX]; + struct stat stat_buf; + + dir = opendir(dirpath); + if (!dir) + return NULL; + + while ((direntry = readdir(dir))) { + if (direntry->d_name[0] == '.') + continue; + if ((stat(direntry->d_name, &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode)) { + snprintf(tmpBuf, PATH_MAX, "%s/%s", dirpath, direntry->d_name); + if ((ret = FindModuleInSubdir(tmpBuf, module))) + break; + continue; + } + + snprintf(tmpBuf, PATH_MAX, "lib%s.so", module); + if (strcmp(direntry->d_name, tmpBuf) == 0) { + ret = malloc(strlen(tmpBuf) + strlen(dirpath) + 2); + sprintf(ret, "%s/%s", dirpath, tmpBuf); + break; + } + + snprintf(tmpBuf, PATH_MAX, "%s_drv.so", module); + if (strcmp(direntry->d_name, tmpBuf) == 0) { + ret = malloc(strlen(tmpBuf) + strlen(dirpath) + 2); + sprintf(ret, "%s/%s", dirpath, tmpBuf); + break; + } + + snprintf(tmpBuf, PATH_MAX, "%s.so", module); + if (strcmp(direntry->d_name, tmpBuf) == 0) { + ret = malloc(strlen(tmpBuf) + strlen(dirpath) + 2); + sprintf(ret, "%s/%s", dirpath, tmpBuf); + break; + } + } + + closedir(dir); + return ret; +} + +static char * +FindModule(const char *module, const char *dirname, const char **subdirlist, PatternPtr patterns) { - char buf[PATH_MAX + 1], tmpBuf[PATH_MAX + 1]; + char buf[PATH_MAX + 1]; char *dirpath = NULL; char *name = NULL; - struct stat stat_buf; int dirlen; const char **subdirs = NULL; const char **s; -#ifndef __EMX__ - dirpath = (char *)dir; -#else - dirpath = xalloc(strlen(dir) + 10); - strcpy(dirpath, (char *)__XOS2RedirRoot(dir)); -#endif + dirpath = (char *)dirname; if (strlen(dirpath) > PATH_MAX) return NULL; @@ -418,38 +460,15 @@ FindModule(const char *module, const char *dir, const char **subdirlist, continue; strcpy(buf, dirpath); strcat(buf, *s); - if ((stat(buf, &stat_buf) == 0) && S_ISDIR(stat_buf.st_mode)) { - if (buf[dirlen - 1] != '/') { - buf[dirlen++] = '/'; - } - - snprintf(tmpBuf, PATH_MAX, "%slib%s.so", buf, module); - if (stat(tmpBuf, &stat_buf) == 0) { - name = tmpBuf; - break; - } - - snprintf(tmpBuf, PATH_MAX, "%s%s_drv.so", buf, module); - if (stat(tmpBuf, &stat_buf) == 0) { - name = tmpBuf; - break; - } - - snprintf(tmpBuf, PATH_MAX, "%s%s.so", buf, module); - if (stat(tmpBuf, &stat_buf) == 0) { - name = tmpBuf; - break; - } - } + if ((name = FindModuleInSubdir(buf, module))) + break; } + FreeSubdirs(subdirs); - if (dirpath != dir) + if (dirpath != dirname) xfree(dirpath); - if (name) { - return xstrdup(name); - } - return NULL; + return name; } _X_EXPORT char **