Alexandre Julliard : ntdll: Rename attach_dlls() to LdrInitializeThunk().

Alexandre Julliard julliard at winehq.org
Thu Feb 14 16:19:12 CST 2019


Module: wine
Branch: master
Commit: 9f0d66923933d82ae0b09fe5d84f977c1a657cc1
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=9f0d66923933d82ae0b09fe5d84f977c1a657cc1

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Thu Feb 14 16:49:09 2019 +0100

ntdll: Rename attach_dlls() to LdrInitializeThunk().

Based on a patch by Andrew Wesie.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/loader.c         | 87 ++++++++++++++++++---------------------------
 dlls/ntdll/ntdll_misc.h     |  2 +-
 dlls/ntdll/signal_arm.c     |  2 +-
 dlls/ntdll/signal_arm64.c   |  2 +-
 dlls/ntdll/signal_i386.c    |  2 +-
 dlls/ntdll/signal_powerpc.c |  2 +-
 dlls/ntdll/signal_x86_64.c  |  2 +-
 include/winternl.h          |  1 -
 8 files changed, 41 insertions(+), 59 deletions(-)

diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c
index d6b8950..d7dbe57 100644
--- a/dlls/ntdll/loader.c
+++ b/dlls/ntdll/loader.c
@@ -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();
 }
diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h
index 5a93ede..5bfc8a9 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -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
diff --git a/dlls/ntdll/signal_arm.c b/dlls/ntdll/signal_arm.c
index e224808..75a1133 100644
--- a/dlls/ntdll/signal_arm.c
+++ b/dlls/ntdll/signal_arm.c
@@ -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;
 }
 
diff --git a/dlls/ntdll/signal_arm64.c b/dlls/ntdll/signal_arm64.c
index c063be5..1d26125 100644
--- a/dlls/ntdll/signal_arm64.c
+++ b/dlls/ntdll/signal_arm64.c
@@ -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 );
 }
diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c
index 91ecfa7..1b3b10f 100644
--- a/dlls/ntdll/signal_i386.c
+++ b/dlls/ntdll/signal_i386.c
@@ -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;
 }
 
diff --git a/dlls/ntdll/signal_powerpc.c b/dlls/ntdll/signal_powerpc.c
index 1c96d62..86398d8 100644
--- a/dlls/ntdll/signal_powerpc.c
+++ b/dlls/ntdll/signal_powerpc.c
@@ -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 );
 }
diff --git a/dlls/ntdll/signal_x86_64.c b/dlls/ntdll/signal_x86_64.c
index c3cc3d8..54871b8 100644
--- a/dlls/ntdll/signal_x86_64.c
+++ b/dlls/ntdll/signal_x86_64.c
@@ -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;
 }
 
diff --git a/include/winternl.h b/include/winternl.h
index a3adba3..46dac7e 100644
--- a/include/winternl.h
+++ b/include/winternl.h
@@ -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);




More information about the wine-cvs mailing list