summaryrefslogtreecommitdiffstats
path: root/loader/module.c
diff options
context:
space:
mode:
Diffstat (limited to 'loader/module.c')
-rw-r--r--loader/module.c116
1 files changed, 80 insertions, 36 deletions
diff --git a/loader/module.c b/loader/module.c
index e2eb306cc2..c2c88bb74d 100644
--- a/loader/module.c
+++ b/loader/module.c
@@ -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 @@ struct modify_ldt_ldt_s {
#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 @@ typedef struct modref_list_t
{
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 @@ WINE_MODREF *MODULE_FindModule(LPCSTR m)
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 @@ static void MODULE_RemoveFromList(WINE_MODREF *mod)
return;
}
}
-}
-
+}
+
WINE_MODREF *MODULE32_LookupHMODULE(HMODULE m)
{
modref_list* list=local_wm;
@@ -128,10 +128,10 @@ WINE_MODREF *MODULE32_LookupHMODULE(HMODULE m)
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 @@ static WIN_BOOL MODULE_InitDll( WINE_MODREF *wm, DWORD type, LPVOID lpReserved )
{
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 @@ static WIN_BOOL MODULE_InitDll( WINE_MODREF *wm, DWORD type, LPVOID lpReserved )
/*************************************************************************
* 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 @@ static WIN_BOOL MODULE_InitDll( WINE_MODREF *wm, DWORD type, LPVOID lpReserved )
*
* 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 @@ WIN_BOOL MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved )
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 @@ WIN_BOOL MODULE_DllProcessAttach( WINE_MODREF *wm, LPVOID lpReserved )
/*************************************************************************
* 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 @@ void MODULE_DllProcessDetach( WINE_MODREF* wm, WIN_BOOL bForceDetach, LPVOID lpR
*/
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();
-
- wm = MODULE_LoadLibraryExA( libname, hfile, flags );
+ 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;
+
+ 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 @@ HMODULE WINAPI LoadLibraryExA(LPCSTR libname, HANDLE hfile, DWORD flags)
}
}
+ if (!wm)
+ printf("Win32 LoadLibrary failed to load: %s\n", checked);
+
+
return wm ? wm->module : 0;
}
@@ -331,7 +376,6 @@ WINE_MODREF *MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags )
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 @@ WINE_MODREF *MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags )
{
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 @@ WINE_MODREF *MODULE_LoadLibraryExA( LPCSTR libname, HFILE hfile, DWORD flags )
return pwm;
}
-
+
WARN("Failed to load module '%s'; error=0x%08lx, \n", libname, GetLastError());
return NULL;
}
@@ -384,10 +428,10 @@ WIN_BOOL WINAPI FreeLibrary(HINSTANCE hLibModule)
{
SetLastError( ERROR_INVALID_HANDLE );
return 0;
- }
+ }
else
retv = MODULE_FreeLibrary( wm );
-
+
MODULE_RemoveFromList(wm);
/* garbage... */
@@ -459,13 +503,13 @@ FARPROC WINAPI GetProcAddress( HMODULE hModule, LPCSTR function )
/***********************************************************************
* 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 @@ FARPROC MODULE_GetProcAddress(
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