ntdll: Rename attach_dlls() to LdrInitializeThunk().

Based on a patch by Andrew Wesie.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2019-02-14 16:49:09 +01:00
parent 42df4dccd5
commit 9f0d669239
8 changed files with 41 additions and 59 deletions

View File

@ -3247,13 +3247,13 @@ PIMAGE_NT_HEADERS WINAPI RtlImageNtHeader(HMODULE hModule)
}
/***********************************************************************
* attach_dlls
/******************************************************************
* LdrInitializeThunk (NTDLL.@)
*
* Attach to all the loaded dlls.
* If this is the first time, perform the full process initialization.
*/
NTSTATUS attach_dlls( CONTEXT *context, void **entry )
void WINAPI LdrInitializeThunk( CONTEXT *context, void **entry, ULONG_PTR unknown3, ULONG_PTR unknown4 )
{
NTSTATUS status;
WINE_MODREF *wm;
@ -3261,7 +3261,7 @@ NTSTATUS attach_dlls( CONTEXT *context, void **entry )
pthread_sigmask( SIG_UNBLOCK, &server_block_set, NULL );
if (process_detaching) return STATUS_SUCCESS;
if (process_detaching) return;
RtlEnterCriticalSection( &loader_section );
@ -3317,7 +3317,6 @@ NTSTATUS attach_dlls( CONTEXT *context, void **entry )
}
RtlLeaveCriticalSection( &loader_section );
return STATUS_SUCCESS;
}
@ -3374,52 +3373,6 @@ static void load_global_options(void)
}
/******************************************************************
* LdrInitializeThunk (NTDLL.@)
*
*/
void WINAPI LdrInitializeThunk( void *kernel_start, ULONG_PTR unknown2,
ULONG_PTR unknown3, ULONG_PTR unknown4 )
{
static const WCHAR globalflagW[] = {'G','l','o','b','a','l','F','l','a','g',0};
NTSTATUS status;
WINE_MODREF *wm;
PEB *peb = NtCurrentTeb()->Peb;
/* allocate the modref for the main exe (if not already done) */
wm = get_modref( peb->ImageBaseAddress );
assert( wm );
if (wm->ldr.Flags & LDR_IMAGE_IS_DLL)
{
ERR("%s is a dll, not an executable\n", debugstr_w(wm->ldr.FullDllName.Buffer) );
exit(1);
}
peb->LoaderLock = &loader_section;
update_user_process_params( &wm->ldr.FullDllName );
version_init( wm->ldr.FullDllName.Buffer );
virtual_set_large_address_space();
LdrQueryImageFileExecutionOptions( &peb->ProcessParameters->ImagePathName, globalflagW,
REG_DWORD, &peb->NtGlobalFlag, sizeof(peb->NtGlobalFlag), NULL );
heap_set_debug_flags( GetProcessHeap() );
/* the main exe needs to be the first in the load order list */
RemoveEntryList( &wm->ldr.InLoadOrderModuleList );
InsertHeadList( &peb->LdrData->InLoadOrderModuleList, &wm->ldr.InLoadOrderModuleList );
RemoveEntryList( &wm->ldr.InMemoryOrderModuleList );
InsertHeadList( &peb->LdrData->InMemoryOrderModuleList, &wm->ldr.InMemoryOrderModuleList );
if ((status = virtual_alloc_thread_stack( NtCurrentTeb(), 0, 0, NULL )) != STATUS_SUCCESS)
{
ERR( "Main exe initialization for %s failed, status %x\n",
debugstr_w(peb->ProcessParameters->ImagePathName.Buffer), status );
NtTerminateProcess( GetCurrentProcess(), status );
}
server_init_process_done();
}
/***********************************************************************
* RtlImageDirectoryEntryToData (NTDLL.@)
*/
@ -3551,6 +3504,7 @@ BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
void __wine_process_init(void)
{
static const WCHAR kernel32W[] = {'k','e','r','n','e','l','3','2','.','d','l','l',0};
static const WCHAR globalflagW[] = {'G','l','o','b','a','l','F','l','a','g',0};
WINE_MODREF *wm;
NTSTATUS status;
@ -3585,5 +3539,34 @@ void __wine_process_init(void)
kernel32_start_process = init_func();
LdrInitializeThunk( NULL, 0, 0, 0 );
wm = get_modref( NtCurrentTeb()->Peb->ImageBaseAddress );
assert( wm );
if (wm->ldr.Flags & LDR_IMAGE_IS_DLL)
{
MESSAGE( "wine: %s is a dll, not an executable\n", debugstr_w(wm->ldr.FullDllName.Buffer) );
exit(1);
}
NtCurrentTeb()->Peb->LoaderLock = &loader_section;
update_user_process_params( &wm->ldr.FullDllName );
version_init( wm->ldr.FullDllName.Buffer );
virtual_set_large_address_space();
LdrQueryImageFileExecutionOptions( &wm->ldr.FullDllName, globalflagW, REG_DWORD,
&NtCurrentTeb()->Peb->NtGlobalFlag, sizeof(DWORD), NULL );
heap_set_debug_flags( GetProcessHeap() );
/* the main exe needs to be the first in the load order list */
RemoveEntryList( &wm->ldr.InLoadOrderModuleList );
InsertHeadList( &NtCurrentTeb()->Peb->LdrData->InLoadOrderModuleList, &wm->ldr.InLoadOrderModuleList );
RemoveEntryList( &wm->ldr.InMemoryOrderModuleList );
InsertHeadList( &NtCurrentTeb()->Peb->LdrData->InMemoryOrderModuleList, &wm->ldr.InMemoryOrderModuleList );
if ((status = virtual_alloc_thread_stack( NtCurrentTeb(), 0, 0, NULL )) != STATUS_SUCCESS)
{
ERR( "Main exe initialization for %s failed, status %x\n",
debugstr_w(wm->ldr.FullDllName.Buffer), status );
NtTerminateProcess( GetCurrentProcess(), status );
}
server_init_process_done();
}

View File

@ -111,7 +111,6 @@ extern BOOL invoke_apc( const apc_call_t *call, apc_result_t *result ) DECLSPEC_
/* module handling */
extern LIST_ENTRY tls_links DECLSPEC_HIDDEN;
extern NTSTATUS attach_dlls( CONTEXT *context, void **entry ) DECLSPEC_HIDDEN;
extern FARPROC RELAY_GetProcAddress( HMODULE module, const IMAGE_EXPORT_DIRECTORY *exports,
DWORD exp_size, FARPROC proc, DWORD ordinal, const WCHAR *user ) DECLSPEC_HIDDEN;
extern FARPROC SNOOP_GetProcAddress( HMODULE hmod, const IMAGE_EXPORT_DIRECTORY *exports, DWORD exp_size,
@ -255,5 +254,6 @@ extern HANDLE keyed_event DECLSPEC_HIDDEN;
#define HASH_STRING_ALGORITHM_INVALID 0xffffffff
NTSTATUS WINAPI RtlHashUnicodeString(PCUNICODE_STRING,BOOLEAN,ULONG,ULONG*);
void WINAPI LdrInitializeThunk(CONTEXT*,void**,ULONG_PTR,ULONG_PTR);
#endif

View File

@ -1327,7 +1327,7 @@ PCONTEXT DECLSPEC_HIDDEN attach_thread( LPTHREAD_START_ROUTINE entry, void *arg,
init_thread_context( ctx, entry, arg, relay );
}
ctx->ContextFlags = CONTEXT_FULL;
attach_dlls( ctx, (void **)&ctx->R0 );
LdrInitializeThunk( ctx, (void **)&ctx->R0, 0, 0 );
return ctx;
}

View File

@ -1100,7 +1100,7 @@ static void thread_startup( void *param )
context.Pc = (DWORD_PTR)info->start;
if (info->suspend) wait_suspend( &context );
attach_dlls( &context, (void **)&context.u.s.X0 );
LdrInitializeThunk( &context, (void **)&context.u.s.X0, 0, 0 );
((thread_start_func)context.Pc)( (LPTHREAD_START_ROUTINE)context.u.s.X0, (void *)context.u.s.X1 );
}

View File

@ -2717,7 +2717,7 @@ PCONTEXT DECLSPEC_HIDDEN attach_thread( LPTHREAD_START_ROUTINE entry, void *arg,
init_thread_context( ctx, entry, arg, relay );
}
ctx->ContextFlags = CONTEXT_FULL;
attach_dlls( ctx, (void **)&ctx->Eax );
LdrInitializeThunk( ctx, (void **)&ctx->Eax, 0, 0 );
return ctx;
}

View File

@ -1194,7 +1194,7 @@ static void thread_startup( void *param )
context.Iar = (DWORD)info->start;
if (info->suspend) wait_suspend( &context );
attach_dlls( &context, (void **)&context.Gpr3 );
LdrInitializeThunk( &context, (void **)&context.Gpr3, 0, 0 );
((thread_start_func)context.Iar)( (LPTHREAD_START_ROUTINE)context.Gpr3, (void *)context.Gpr4 );
}

View File

@ -4557,7 +4557,7 @@ PCONTEXT DECLSPEC_HIDDEN attach_thread( LPTHREAD_START_ROUTINE entry, void *arg,
init_thread_context( ctx, entry, arg, relay );
}
ctx->ContextFlags = CONTEXT_FULL;
attach_dlls( ctx, (void **)&ctx->Rcx );
LdrInitializeThunk( ctx, (void **)&ctx->Rcx, 0, 0 );
return ctx;
}

View File

@ -2302,7 +2302,6 @@ NTSYSAPI NTSTATUS WINAPI LdrDisableThreadCalloutsForDll(HMODULE);
NTSYSAPI NTSTATUS WINAPI LdrFindEntryForAddress(const void*, PLDR_MODULE*);
NTSYSAPI NTSTATUS WINAPI LdrGetDllHandle(LPCWSTR, ULONG, const UNICODE_STRING*, HMODULE*);
NTSYSAPI NTSTATUS WINAPI LdrGetProcedureAddress(HMODULE, const ANSI_STRING*, ULONG, void**);
NTSYSAPI void WINAPI LdrInitializeThunk(void*,ULONG_PTR,ULONG_PTR,ULONG_PTR);
NTSYSAPI NTSTATUS WINAPI LdrLoadDll(LPCWSTR, DWORD, const UNICODE_STRING*, HMODULE*);
NTSYSAPI NTSTATUS WINAPI LdrLockLoaderLock(ULONG,ULONG*,ULONG_PTR*);
IMAGE_BASE_RELOCATION * WINAPI LdrProcessRelocationBlock(void*,UINT,USHORT*,INT_PTR);