Merged PE_InitDLL into MODULE_InitDLL.

Fixed a few traces.
This commit is contained in:
Alexandre Julliard 2003-04-04 19:50:17 +00:00
parent 56b5e0862c
commit 39f73ddeaa
3 changed files with 25 additions and 53 deletions

View file

@ -33,11 +33,12 @@
#include "wine/server.h"
#include "ntdll_misc.h"
WINE_DEFAULT_DEBUG_CHANNEL(ntdll);
WINE_DECLARE_DEBUG_CHANNEL(module);
WINE_DECLARE_DEBUG_CHANNEL(module);
WINE_DEFAULT_DEBUG_CHANNEL(module);
WINE_DECLARE_DEBUG_CHANNEL(relay);
WINE_DECLARE_DEBUG_CHANNEL(loaddll);
typedef DWORD (CALLBACK *DLLENTRYPROC)(HMODULE,DWORD,LPVOID);
WINE_MODREF *MODULE_modref_list = NULL;
static WINE_MODREF *exe_modref;
@ -144,20 +145,30 @@ static BOOL MODULE_InitDLL( WINE_MODREF *wm, DWORD type, LPVOID lpReserved )
static const char * const typeName[] = { "PROCESS_DETACH", "PROCESS_ATTACH",
"THREAD_ATTACH", "THREAD_DETACH" };
BOOL retv = TRUE;
DLLENTRYPROC entry = wm->ldr.EntryPoint;
void *module = wm->ldr.BaseAddress;
/* Skip calls for modules loaded with special load flags */
if (wm->ldr.Flags & LDR_DONT_RESOLVE_REFS) return TRUE;
if (!entry || !(wm->ldr.Flags & LDR_IMAGE_IS_DLL)) return TRUE;
TRACE("(%s,%s,%p) - CALL\n", wm->modname, typeName[type], lpReserved );
TRACE("(%p (%s),%s,%p) - CALL\n", module, wm->modname, typeName[type], lpReserved );
/* Call the initialization routine */
retv = PE_InitDLL( wm->ldr.BaseAddress, type, lpReserved );
if (TRACE_ON(relay))
DPRINTF("%04lx:Call PE DLL (proc=%p,module=%p,type=%ld,res=%p)\n",
GetCurrentThreadId(), entry, module, type, lpReserved );
retv = entry( module, type, lpReserved );
if (TRACE_ON(relay))
DPRINTF("%04lx:Ret PE DLL (proc=%p,module=%p,type=%ld,res=%p) retval=%x\n",
GetCurrentThreadId(), entry, module, type, lpReserved, retv );
/* The state of the module list may have changed due to the call
to PE_InitDLL. We cannot assume that this module has not been
to the dll. We cannot assume that this module has not been
deleted. */
TRACE("(%p,%s,%p) - RETURN %d\n", wm, typeName[type], lpReserved, retv );
TRACE("(%p,%s,%p) - RETURN %d\n", module, typeName[type], lpReserved, retv );
return retv;
}
@ -445,9 +456,6 @@ NTSTATUS WINAPI LdrGetDllHandle(ULONG x, ULONG y, PUNICODE_STRING name, HMODULE
{
WINE_MODREF *wm;
TRACE("%08lx %08lx %s %p\n",
x, y, name ? debugstr_wn(name->Buffer, name->Length) : NULL, base);
if (x != 0 || y != 0)
FIXME("Unknown behavior, please report\n");
@ -471,6 +479,10 @@ NTSTATUS WINAPI LdrGetDllHandle(ULONG x, ULONG y, PUNICODE_STRING name, HMODULE
}
*base = wm->ldr.BaseAddress;
TRACE("%lx %lx %s -> %p\n",
x, y, name ? debugstr_wn(name->Buffer, name->Length/sizeof(WCHAR)) : "(null)", *base);
return STATUS_SUCCESS;
}
@ -486,11 +498,6 @@ FARPROC MODULE_GetProcAddress(
WINE_MODREF *wm;
FARPROC retproc = 0;
if (HIWORD(function))
TRACE("(%p,%s (%d))\n",hModule,function,hint);
else
TRACE("(%p,%p)\n",hModule,function);
RtlEnterCriticalSection( &loader_section );
if ((wm = MODULE32_LookupHMODULE( hModule )))
{
@ -503,15 +510,10 @@ FARPROC MODULE_GetProcAddress(
/******************************************************************
* LdrGetProcedureAddress (NTDLL.@)
*
*
*/
NTSTATUS WINAPI LdrGetProcedureAddress(HMODULE base, PANSI_STRING name, ULONG ord, PVOID *address)
{
WARN("%p %s %ld %p\n", base, name ? debugstr_an(name->Buffer, name->Length) : NULL, ord, address);
*address = MODULE_GetProcAddress( base, name ? name->Buffer : (LPSTR)ord, -1, TRUE );
return (*address) ? STATUS_SUCCESS : STATUS_PROCEDURE_NOT_FOUND;
}
@ -678,7 +680,7 @@ NTSTATUS MODULE_LoadLibraryExA( LPCSTR libname, DWORD flags, WINE_MODREF** pwm)
if (nts == STATUS_SUCCESS)
{
/* Initialize DLL just loaded */
TRACE("Loaded module '%s' at %p\n", filename, (*pwm)->ldr.BaseAddress);
TRACE("Loaded module '%s' (%s) at %p\n", filename, filetype, (*pwm)->ldr.BaseAddress);
if (!TRACE_ON(module))
TRACE_(loaddll)("Loaded module '%s' : %s\n", filename, filetype);
/* Set the ldr.LoadCount here so that an attach failure will */
@ -733,7 +735,7 @@ NTSTATUS WINAPI LdrLoadDll(LPCWSTR path_name, DWORD flags, PUNICODE_STRING libna
case STATUS_SUCCESS:
if ( !MODULE_DllProcessAttach( wm, NULL ) )
{
WARN_(module)("Attach failed for module '%s'.\n", str.Buffer);
WARN("Attach failed for module '%s'.\n", str.Buffer);
LdrUnloadDll(wm->ldr.BaseAddress);
nts = STATUS_DLL_INIT_FAILED;
wm = NULL;

View file

@ -237,7 +237,6 @@ extern HMODULE PE_LoadImage( HANDLE hFile, LPCSTR filename, DWORD flags );
extern WINE_MODREF *PE_CreateModule( HMODULE hModule, LPCSTR filename,
DWORD flags, HANDLE hFile, BOOL builtin );
extern void PE_InitTls(void);
extern BOOL PE_InitDLL( HMODULE module, DWORD type, LPVOID lpReserved );
extern DWORD PE_fixup_imports(WINE_MODREF *wm);
/* loader/loadorder.c */

View file

@ -632,35 +632,6 @@ NTSTATUS PE_LoadLibraryExA (LPCSTR name, DWORD flags, WINE_MODREF** pwm)
}
/* Called if the library is loaded or freed.
* NOTE: if a thread attaches a DLL, the current thread will only do
* DLL_PROCESS_ATTACH. Only newly created threads do DLL_THREAD_ATTACH
* (SDK)
*/
typedef DWORD (CALLBACK *DLLENTRYPROC)(HMODULE,DWORD,LPVOID);
BOOL PE_InitDLL( HMODULE module, DWORD type, LPVOID lpReserved )
{
BOOL retv = TRUE;
IMAGE_NT_HEADERS *nt = RtlImageNtHeader(module);
/* Is this a library? And has it got an entrypoint? */
if (nt && (nt->FileHeader.Characteristics & IMAGE_FILE_DLL) &&
(nt->OptionalHeader.AddressOfEntryPoint))
{
DLLENTRYPROC entry = (void*)((char*)module + nt->OptionalHeader.AddressOfEntryPoint);
if (TRACE_ON(relay))
DPRINTF("%04lx:Call PE DLL (proc=%p,module=%p,type=%ld,res=%p)\n",
GetCurrentThreadId(), entry, module, type, lpReserved );
retv = entry( module, type, lpReserved );
if (TRACE_ON(relay))
DPRINTF("%04lx:Ret PE DLL (proc=%p,module=%p,type=%ld,res=%p) retval=%x\n",
GetCurrentThreadId(), entry, module, type, lpReserved, retv );
}
return retv;
}
/************************************************************************
* PE_InitTls (internal)
*