Commit 43be3507 authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Setup the main thread before initializing ntdll.

parent 83a4549e
......@@ -153,6 +153,20 @@ static CRITICAL_SECTION_DEBUG dlldir_critsect_debug =
};
static CRITICAL_SECTION dlldir_section = { &dlldir_critsect_debug, -1, 0, 0, 0, 0 };
static RTL_CRITICAL_SECTION peb_lock;
static RTL_CRITICAL_SECTION_DEBUG peb_critsect_debug =
{
0, 0, &peb_lock,
{ &peb_critsect_debug.ProcessLocksList, &peb_critsect_debug.ProcessLocksList },
0, 0, { (DWORD_PTR)(__FILE__ ": peb_lock") }
};
static RTL_CRITICAL_SECTION peb_lock = { &peb_critsect_debug, -1, 0, 0, 0, 0 };
static PEB_LDR_DATA ldr = { sizeof(ldr), TRUE };
static RTL_BITMAP tls_bitmap;
static RTL_BITMAP tls_expansion_bitmap;
static RTL_BITMAP fls_bitmap;
static WINE_MODREF *cached_modref;
static WINE_MODREF *current_modref;
static WINE_MODREF *last_failed_modref;
......@@ -3920,12 +3934,37 @@ void __wine_process_init(void)
UNICODE_STRING nt_name;
HMODULE ntdll_module = (HMODULE)((__wine_spec_nt_header.OptionalHeader.ImageBase + 0xffff) & ~0xffff);
INITIAL_TEB stack;
SIZE_T info_size;
TEB *teb = thread_init( &info_size );
ULONG_PTR val;
TEB *teb = NtCurrentTeb();
PEB *peb = teb->Peb;
peb->ProcessHeap = RtlCreateHeap( HEAP_GROWABLE, NULL, 0, 0, NULL, NULL );
peb->LoaderLock = &loader_section;
peb->LdrData = &ldr;
peb->FastPebLock = &peb_lock;
peb->TlsBitmap = &tls_bitmap;
peb->TlsExpansionBitmap = &tls_expansion_bitmap;
peb->FlsBitmap = &fls_bitmap;
peb->LoaderLock = &loader_section;
peb->OSMajorVersion = 5;
peb->OSMinorVersion = 1;
peb->OSBuildNumber = 0xA28;
peb->OSPlatformId = VER_PLATFORM_WIN32_NT;
peb->SessionId = 1;
peb->ProcessHeap = RtlCreateHeap( HEAP_GROWABLE, NULL, 0, 0, NULL, NULL );
InitializeListHead( &peb->FlsListHead );
RtlInitializeBitMap( &tls_bitmap, peb->TlsBitmapBits, sizeof(peb->TlsBitmapBits) * 8 );
RtlInitializeBitMap( &tls_expansion_bitmap, peb->TlsExpansionBitmapBits,
sizeof(peb->TlsExpansionBitmapBits) * 8 );
RtlInitializeBitMap( &fls_bitmap, peb->FlsBitmapBits, sizeof(peb->FlsBitmapBits) * 8 );
RtlSetBits( peb->TlsBitmap, 0, 1 ); /* TLS index 0 is reserved and should be initialized to NULL. */
RtlSetBits( peb->FlsBitmap, 0, 1 );
InitializeListHead( &ldr.InLoadOrderModuleList );
InitializeListHead( &ldr.InMemoryOrderModuleList );
InitializeListHead( &ldr.InInitializationOrderModuleList );
NtQueryInformationProcess( GetCurrentProcess(), ProcessWow64Information, &val, sizeof(val), NULL );
is_wow64 = !!val;
init_unix_codepage();
init_directories();
......
......@@ -64,7 +64,6 @@ extern LPCSTR debugstr_ObjectAttributes(const OBJECT_ATTRIBUTES *oa) DECLSPEC_HI
/* init routines */
extern void version_init(void) DECLSPEC_HIDDEN;
extern void debug_init(void) DECLSPEC_HIDDEN;
extern TEB *thread_init( SIZE_T *info_size ) DECLSPEC_HIDDEN;
extern void actctx_init(void) DECLSPEC_HIDDEN;
extern void heap_set_debug_flags( HANDLE handle ) DECLSPEC_HIDDEN;
extern void init_unix_codepage(void) DECLSPEC_HIDDEN;
......
......@@ -40,21 +40,6 @@ WINE_DECLARE_DEBUG_CHANNEL(relay);
struct _KUSER_SHARED_DATA *user_shared_data = (void *)0x7ffe0000;
static PEB *peb;
static PEB_LDR_DATA ldr;
static RTL_BITMAP tls_bitmap;
static RTL_BITMAP tls_expansion_bitmap;
static RTL_BITMAP fls_bitmap;
static RTL_CRITICAL_SECTION peb_lock;
static RTL_CRITICAL_SECTION_DEBUG critsect_debug =
{
0, 0, &peb_lock,
{ &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
0, 0, { (DWORD_PTR)(__FILE__ ": peb_lock") }
};
static RTL_CRITICAL_SECTION peb_lock = { &critsect_debug, -1, 0, 0, 0, 0 };
/***********************************************************************
* __wine_dbg_get_channel_flags (NTDLL.@)
......@@ -93,53 +78,6 @@ int __cdecl __wine_dbg_output( const char *str )
/***********************************************************************
* thread_init
*
* Setup the initial thread.
*
* NOTES: The first allocated TEB on NT is at 0x7ffde000.
*/
TEB *thread_init( SIZE_T *info_size )
{
ULONG_PTR val;
TEB *teb = unix_funcs->init_threading( info_size );
peb = teb->Peb;
peb->FastPebLock = &peb_lock;
peb->TlsBitmap = &tls_bitmap;
peb->TlsExpansionBitmap = &tls_expansion_bitmap;
peb->FlsBitmap = &fls_bitmap;
peb->LdrData = &ldr;
peb->OSMajorVersion = 5;
peb->OSMinorVersion = 1;
peb->OSBuildNumber = 0xA28;
peb->OSPlatformId = VER_PLATFORM_WIN32_NT;
ldr.Length = sizeof(ldr);
ldr.Initialized = TRUE;
RtlInitializeBitMap( &tls_bitmap, peb->TlsBitmapBits, sizeof(peb->TlsBitmapBits) * 8 );
RtlInitializeBitMap( &tls_expansion_bitmap, peb->TlsExpansionBitmapBits,
sizeof(peb->TlsExpansionBitmapBits) * 8 );
RtlInitializeBitMap( &fls_bitmap, peb->FlsBitmapBits, sizeof(peb->FlsBitmapBits) * 8 );
RtlSetBits( peb->TlsBitmap, 0, 1 ); /* TLS index 0 is reserved and should be initialized to NULL. */
RtlSetBits( peb->FlsBitmap, 0, 1 );
InitializeListHead( &peb->FlsListHead );
InitializeListHead( &ldr.InLoadOrderModuleList );
InitializeListHead( &ldr.InMemoryOrderModuleList );
InitializeListHead( &ldr.InInitializationOrderModuleList );
/*
* Starting with Vista, the first user to log on has session id 1.
* Session id 0 is for processes that don't interact with the user (like services).
*/
peb->SessionId = 1;
NtQueryInformationProcess( GetCurrentProcess(), ProcessWow64Information, &val, sizeof(val), NULL );
is_wow64 = !!val;
return teb;
}
/***********************************************************************
* RtlExitUserThread (NTDLL.@)
*/
void WINAPI RtlExitUserThread( ULONG status )
......@@ -284,8 +222,7 @@ NTSTATUS WINAPI RtlCreateUserThread( HANDLE process, SECURITY_DESCRIPTOR *descr,
*/
ULONG WINAPI RtlGetNtGlobalFlags(void)
{
if (!peb) return 0; /* init not done yet */
return peb->NtGlobalFlag;
return NtCurrentTeb()->Peb->NtGlobalFlag;
}
......
......@@ -1507,7 +1507,6 @@ static struct unix_funcs unix_funcs =
virtual_locked_recvmsg,
virtual_release_address_space,
virtual_set_large_address_space,
init_threading,
exit_thread,
exit_process,
exec_process,
......@@ -1532,6 +1531,29 @@ static struct unix_funcs unix_funcs =
};
/***********************************************************************
* start_main_thread
*/
static void start_main_thread(void)
{
BOOL suspend;
TEB *teb = virtual_alloc_first_teb();
signal_init_threading();
signal_alloc_thread( teb );
signal_init_thread( teb );
dbg_init();
server_init_process();
startup_info_size = server_init_thread( teb->Peb, &suspend );
virtual_map_user_shared_data();
virtual_create_builtin_view( ntdll_module );
init_cpu_info();
init_files();
NtCreateKeyedEvent( &keyed_event, GENERIC_READ | GENERIC_WRITE, NULL, 0 );
p__wine_set_unix_funcs( NTDLL_UNIXLIB_VERSION, &unix_funcs );
}
#ifdef __APPLE__
struct apple_stack_info
{
......@@ -1541,7 +1563,7 @@ struct apple_stack_info
static void *apple_wine_thread( void *arg )
{
p__wine_set_unix_funcs( NTDLL_UNIXLIB_VERSION, &unix_funcs );
start_main_thread();
return NULL;
}
......@@ -1795,7 +1817,7 @@ void __wine_main( int argc, char *argv[], char *envp[] )
#ifdef __APPLE__
apple_main_thread();
#endif
p__wine_set_unix_funcs( NTDLL_UNIXLIB_VERSION, &unix_funcs );
start_main_thread();
}
......
......@@ -83,33 +83,6 @@ static void pthread_exit_wrapper( int status )
}
/***********************************************************************
* init_threading
*/
TEB * CDECL init_threading( SIZE_T *size )
{
TEB *teb;
BOOL suspend;
teb = virtual_alloc_first_teb();
signal_init_threading();
signal_alloc_thread( teb );
signal_init_thread( teb );
dbg_init();
server_init_process();
startup_info_size = server_init_thread( teb->Peb, &suspend );
virtual_map_user_shared_data();
virtual_create_builtin_view( ntdll_module );
init_cpu_info();
init_files();
NtCreateKeyedEvent( &keyed_event, GENERIC_READ | GENERIC_WRITE, NULL, 0 );
if (size) *size = startup_info_size;
return teb;
}
/* info passed to a starting thread */
struct startup_info
{
......
......@@ -117,7 +117,6 @@ extern NTSTATUS CDECL server_handle_to_fd( HANDLE handle, unsigned int access, i
unsigned int *options ) DECLSPEC_HIDDEN;
extern void CDECL server_release_fd( HANDLE handle, int unix_fd ) DECLSPEC_HIDDEN;
extern void CDECL server_init_process_done( void *relay ) DECLSPEC_HIDDEN;
extern TEB * CDECL init_threading( SIZE_T *size ) DECLSPEC_HIDDEN;
extern void CDECL DECLSPEC_NORETURN exit_thread( int status ) DECLSPEC_HIDDEN;
extern void CDECL DECLSPEC_NORETURN exit_process( int status ) DECLSPEC_HIDDEN;
extern NTSTATUS CDECL exec_process( UNICODE_STRING *path, UNICODE_STRING *cmdline, NTSTATUS status ) DECLSPEC_HIDDEN;
......
......@@ -28,7 +28,7 @@ struct msghdr;
struct _DISPATCHER_CONTEXT;
/* increment this when you change the function table */
#define NTDLL_UNIXLIB_VERSION 68
#define NTDLL_UNIXLIB_VERSION 69
struct unix_funcs
{
......@@ -319,7 +319,6 @@ struct unix_funcs
void (CDECL *virtual_set_large_address_space)(void);
/* thread/process functions */
TEB * (CDECL *init_threading)( SIZE_T *size );
void (CDECL *exit_thread)( int status );
void (CDECL *exit_process)( int status );
NTSTATUS (CDECL *exec_process)( UNICODE_STRING *path, UNICODE_STRING *cmdline, NTSTATUS status );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment