Mercurial > mplayer.hg
diff loader/module.c @ 2069:ce45cce7f7a5
sync with avifile
| author | arpi |
|---|---|
| date | Thu, 04 Oct 2001 02:21:47 +0000 |
| parents | d8c1b0b38edc |
| children | 958d10763c34 |
line wrap: on
line diff
--- a/loader/module.c Thu Oct 04 00:24:05 2001 +0000 +++ b/loader/module.c Thu Oct 04 02:21:47 2001 +0000 @@ -12,14 +12,8 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> - #include <sys/mman.h> #include <sys/types.h> -#ifdef HAVE_LIBDL -#include <wine/elfdll.h> -#include <dlfcn.h> -#endif - /* #ifdef __linux__ #include <asm/unistd.h> @@ -53,6 +47,10 @@ #include <wine/module.h> #include <wine/pe_image.h> #include <wine/debugtools.h> +#ifdef HAVE_LIBDL +#include <dlfcn.h> +#include <wine/elfdll.h> +#endif #include "win32.h" struct modref_list_t; @@ -61,13 +59,15 @@ { WINE_MODREF* wm; struct modref_list_t *next; - struct modref_list_t *prev; + struct modref_list_t *prev; } modref_list; //WINE_MODREF *local_wm=NULL; modref_list* local_wm=NULL; +//HANDLE SegptrHeap; // unused? + WINE_MODREF *MODULE_FindModule(LPCSTR m) { modref_list* list=local_wm; @@ -80,10 +80,10 @@ list=list->prev; if(list==NULL) return NULL; - } + } TRACE("Resolved to %s\n", list->wm->filename); return list->wm; -} +} static void MODULE_RemoveFromList(WINE_MODREF *mod) { @@ -113,8 +113,8 @@ return; } } -} - +} + WINE_MODREF *MODULE32_LookupHMODULE(HMODULE m) { modref_list* list=local_wm; @@ -128,10 +128,10 @@ list=list->prev; if(list==NULL) return NULL; - } - TRACE("LookupHMODULE hit %X\n", list->wm); + } + TRACE("LookupHMODULE hit %p\n", list->wm); return list->wm; -} +} /************************************************************************* * MODULE_InitDll @@ -140,7 +140,7 @@ { WIN_BOOL retv = TRUE; - static LPCSTR typeName[] = { "PROCESS_DETACH", "PROCESS_ATTACH", + static LPCSTR typeName[] = { "PROCESS_DETACH", "PROCESS_ATTACH", "THREAD_ATTACH", "THREAD_DETACH" }; assert( wm ); @@ -181,14 +181,14 @@ /************************************************************************* * MODULE_DllProcessAttach - * + * * Send the process attach notification to all DLLs the given module * depends on (recursively). This is somewhat complicated due to the fact that * * - we have to respect the module dependencies, i.e. modules implicitly * referenced by another module have to be initialized before the module * itself can be initialized - * + * * - the initialization routine of a DLL can itself call LoadLibrary, * thereby introducing a whole new set of dependencies (even involving * the 'old' modules) at any time during the whole process @@ -199,7 +199,7 @@ * * Furthermore, we need to rearrange the main WINE_MODREF list to allow * the process *detach* notifications to be sent in the correct order. - * This must not only take into account module dependencies, but also + * This must not only take into account module dependencies, but also * 'hidden' dependencies created by modules calling LoadLibrary in their * attach notification routine. * @@ -248,10 +248,10 @@ local_wm=malloc(sizeof(modref_list)); local_wm->next=local_wm->prev=NULL; local_wm->wm=wm; - } + } /* Remove recursion flag */ wm->flags &= ~WINE_MODREF_MARKER; - + if ( retv ) { retv = MODULE_InitDll( wm, DLL_PROCESS_ATTACH, lpReserved ); @@ -267,8 +267,8 @@ /************************************************************************* * MODULE_DllProcessDetach - * - * Send DLL process detach notifications. See the comment about calling + * + * Send DLL process detach notifications. See the comment about calling * sequence at MODULE_DllProcessAttach. Unless the bForceDetach flag * is set, only DLLs with zero refcount are notified. */ @@ -285,18 +285,59 @@ */ HMODULE WINAPI LoadLibraryExA(LPCSTR libname, HANDLE hfile, DWORD flags) { - WINE_MODREF *wm; + WINE_MODREF *wm = 0; + char* listpath[] = { "", "", "/usr/lib/win32", "/usr/local/lib/win32", 0 }; + extern char* def_path; + char path[512]; + char checked[2000]; + int i = -1; + checked[0] = 0; if(!libname) { SetLastError(ERROR_INVALID_PARAMETER); return 0; } + + printf("Loading DLL: '%s'\n", libname); + // if(fs_installed==0) // install_fs(); - + + while (wm == 0 && listpath[++i]) + { + if (i < 2) + { + if (i == 0) + /* check just original file name */ + strncpy(path, libname, 511); + else + /* check default user path */ + strncpy(path, def_path, 300); + } + else if (strcmp(def_path, listpath[i])) + /* path from the list */ + strncpy(path, listpath[i], 300); + else + continue; - wm = MODULE_LoadLibraryExA( libname, hfile, flags ); + if (i > 0) + { + strcat(path, "/"); + strncat(path, libname, 100); + } + path[511] = 0; + wm = MODULE_LoadLibraryExA( path, hfile, flags ); + + if (!wm) + { + if (checked[0]) + strcat(checked, ", "); + strcat(checked, path); + checked[1500] = 0; + + } + } if ( wm ) { if ( !MODULE_DllProcessAttach( wm, NULL ) ) @@ -309,6 +350,10 @@ } } + if (!wm) + printf("Win32 LoadLibrary failed to load: %s\n", checked); + + return wm ? wm->module : 0; } @@ -331,7 +376,6 @@ int i; // module_loadorder_t *plo; - SetLastError( ERROR_FILE_NOT_FOUND ); TRACE("Trying native dll '%s'\n", libname); pwm = PE_LoadLibraryExA(libname, flags); @@ -340,8 +384,8 @@ { TRACE("Trying ELF dll '%s'\n", libname); pwm=(WINE_MODREF*)ELFDLL_LoadLibraryExA(libname, flags); - } -#endif + } +#endif // printf("0x%08x\n", pwm); // break; if(pwm) @@ -356,7 +400,7 @@ return pwm; } - + WARN("Failed to load module '%s'; error=0x%08lx, \n", libname, GetLastError()); return NULL; } @@ -384,10 +428,10 @@ { SetLastError( ERROR_INVALID_HANDLE ); return 0; - } + } else retv = MODULE_FreeLibrary( wm ); - + MODULE_RemoveFromList(wm); /* garbage... */ @@ -459,13 +503,13 @@ /*********************************************************************** * MODULE_GetProcAddress (internal) */ -FARPROC MODULE_GetProcAddress( +FARPROC MODULE_GetProcAddress( HMODULE hModule, /* [in] current module handle */ LPCSTR function, /* [in] function to be looked up */ WIN_BOOL snoop ) { WINE_MODREF *wm = MODULE32_LookupHMODULE( hModule ); -// WINE_MODREF *wm=local_wm; +// WINE_MODREF *wm=local_wm; FARPROC retproc; if (HIWORD(function)) @@ -482,9 +526,9 @@ retproc = PE_FindExportedFunction( wm, function, snoop ); if (!retproc) SetLastError(ERROR_PROC_NOT_FOUND); return retproc; -#ifdef HAVE_LIBDL +#ifdef HAVE_LIBDL case MODULE32_ELF: - retproc = (FARPROC) dlsym( (void*)wm->module, function); + retproc = (FARPROC) dlsym( (void*) wm->module, function); if (!retproc) SetLastError(ERROR_PROC_NOT_FOUND); return retproc; #endif
