Commit 8c103f29 authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Add support for setting a platform-specific initial context.

parent 9979c793
...@@ -3115,6 +3115,7 @@ void WINAPI LdrInitializeThunk( void *kernel_start, ULONG_PTR unknown2, ...@@ -3115,6 +3115,7 @@ void WINAPI LdrInitializeThunk( void *kernel_start, ULONG_PTR unknown2,
WINE_MODREF *wm; WINE_MODREF *wm;
LPCWSTR load_path; LPCWSTR load_path;
PEB *peb = NtCurrentTeb()->Peb; PEB *peb = NtCurrentTeb()->Peb;
CONTEXT context = { 0 };
kernel32_start_process = kernel_start; kernel32_start_process = kernel_start;
if (main_exe_file) NtClose( main_exe_file ); /* at this point the main module is created */ if (main_exe_file) NtClose( main_exe_file ); /* at this point the main module is created */
...@@ -3145,7 +3146,7 @@ void WINAPI LdrInitializeThunk( void *kernel_start, ULONG_PTR unknown2, ...@@ -3145,7 +3146,7 @@ void WINAPI LdrInitializeThunk( void *kernel_start, ULONG_PTR unknown2,
InsertHeadList( &peb->LdrData->InMemoryOrderModuleList, &wm->ldr.InMemoryOrderModuleList ); InsertHeadList( &peb->LdrData->InMemoryOrderModuleList, &wm->ldr.InMemoryOrderModuleList );
if ((status = virtual_alloc_thread_stack( NtCurrentTeb(), 0, 0 )) != STATUS_SUCCESS) goto error; if ((status = virtual_alloc_thread_stack( NtCurrentTeb(), 0, 0 )) != STATUS_SUCCESS) goto error;
if ((status = server_init_process_done()) != STATUS_SUCCESS) goto error; if ((status = server_init_process_done( &context )) != STATUS_SUCCESS) goto error;
actctx_init(); actctx_init();
load_path = NtCurrentTeb()->Peb->ProcessParameters->DllPath.Buffer; load_path = NtCurrentTeb()->Peb->ProcessParameters->DllPath.Buffer;
...@@ -3157,6 +3158,7 @@ void WINAPI LdrInitializeThunk( void *kernel_start, ULONG_PTR unknown2, ...@@ -3157,6 +3158,7 @@ void WINAPI LdrInitializeThunk( void *kernel_start, ULONG_PTR unknown2,
virtual_release_address_space(); virtual_release_address_space();
virtual_clear_thread_stack(); virtual_clear_thread_stack();
if (context.ContextFlags) NtSetContextThread( GetCurrentThread(), &context );
wine_switch_to_stack( start_process, wm->ldr.EntryPoint, NtCurrentTeb()->Tib.StackBase ); wine_switch_to_stack( start_process, wm->ldr.EntryPoint, NtCurrentTeb()->Tib.StackBase );
error: error:
......
...@@ -67,7 +67,7 @@ extern LPCSTR debugstr_ObjectAttributes(const OBJECT_ATTRIBUTES *oa) DECLSPEC_HI ...@@ -67,7 +67,7 @@ extern LPCSTR debugstr_ObjectAttributes(const OBJECT_ATTRIBUTES *oa) DECLSPEC_HI
extern NTSTATUS signal_alloc_thread( TEB **teb ) DECLSPEC_HIDDEN; extern NTSTATUS signal_alloc_thread( TEB **teb ) DECLSPEC_HIDDEN;
extern void signal_free_thread( TEB *teb ) DECLSPEC_HIDDEN; extern void signal_free_thread( TEB *teb ) DECLSPEC_HIDDEN;
extern void signal_init_thread( TEB *teb ) DECLSPEC_HIDDEN; extern void signal_init_thread( TEB *teb ) DECLSPEC_HIDDEN;
extern void signal_init_process(void) DECLSPEC_HIDDEN; extern void signal_init_process( CONTEXT *context, LPTHREAD_START_ROUTINE entry ) DECLSPEC_HIDDEN;
extern void version_init( const WCHAR *appname ) DECLSPEC_HIDDEN; extern void version_init( const WCHAR *appname ) DECLSPEC_HIDDEN;
extern void debug_init(void) DECLSPEC_HIDDEN; extern void debug_init(void) DECLSPEC_HIDDEN;
extern HANDLE thread_init(void) DECLSPEC_HIDDEN; extern HANDLE thread_init(void) DECLSPEC_HIDDEN;
...@@ -82,7 +82,7 @@ extern timeout_t server_start_time DECLSPEC_HIDDEN; ...@@ -82,7 +82,7 @@ extern timeout_t server_start_time DECLSPEC_HIDDEN;
extern unsigned int server_cpus DECLSPEC_HIDDEN; extern unsigned int server_cpus DECLSPEC_HIDDEN;
extern BOOL is_wow64 DECLSPEC_HIDDEN; extern BOOL is_wow64 DECLSPEC_HIDDEN;
extern void server_init_process(void) DECLSPEC_HIDDEN; extern void server_init_process(void) DECLSPEC_HIDDEN;
extern NTSTATUS server_init_process_done(void) DECLSPEC_HIDDEN; extern NTSTATUS server_init_process_done( CONTEXT *context ) DECLSPEC_HIDDEN;
extern size_t server_init_thread( void *entry_point ) DECLSPEC_HIDDEN; extern size_t server_init_thread( void *entry_point ) DECLSPEC_HIDDEN;
extern void DECLSPEC_NORETURN abort_thread( int status ) DECLSPEC_HIDDEN; extern void DECLSPEC_NORETURN abort_thread( int status ) DECLSPEC_HIDDEN;
extern void DECLSPEC_NORETURN terminate_thread( int status ) DECLSPEC_HIDDEN; extern void DECLSPEC_NORETURN terminate_thread( int status ) DECLSPEC_HIDDEN;
......
...@@ -1421,10 +1421,11 @@ void server_init_process(void) ...@@ -1421,10 +1421,11 @@ void server_init_process(void)
/*********************************************************************** /***********************************************************************
* server_init_process_done * server_init_process_done
*/ */
NTSTATUS server_init_process_done(void) NTSTATUS server_init_process_done( CONTEXT *context )
{ {
PEB *peb = NtCurrentTeb()->Peb; PEB *peb = NtCurrentTeb()->Peb;
IMAGE_NT_HEADERS *nt = RtlImageNtHeader( peb->ImageBaseAddress ); IMAGE_NT_HEADERS *nt = RtlImageNtHeader( peb->ImageBaseAddress );
void *entry = (char *)peb->ImageBaseAddress + nt->OptionalHeader.AddressOfEntryPoint;
NTSTATUS status; NTSTATUS status;
/* Install signal handlers; this cannot be done earlier, since we cannot /* Install signal handlers; this cannot be done earlier, since we cannot
...@@ -1433,7 +1434,7 @@ NTSTATUS server_init_process_done(void) ...@@ -1433,7 +1434,7 @@ NTSTATUS server_init_process_done(void)
* We do need the handlers in place by the time the request is over, so * We do need the handlers in place by the time the request is over, so
* we set them up here. If we segfault between here and the server call * we set them up here. If we segfault between here and the server call
* something is very wrong... */ * something is very wrong... */
signal_init_process(); signal_init_process( context, entry );
/* Signal the parent process to continue */ /* Signal the parent process to continue */
SERVER_START_REQ( init_process_done ) SERVER_START_REQ( init_process_done )
...@@ -1442,7 +1443,7 @@ NTSTATUS server_init_process_done(void) ...@@ -1442,7 +1443,7 @@ NTSTATUS server_init_process_done(void)
#ifdef __i386__ #ifdef __i386__
req->ldt_copy = wine_server_client_ptr( &wine_ldt_copy ); req->ldt_copy = wine_server_client_ptr( &wine_ldt_copy );
#endif #endif
req->entry = wine_server_client_ptr( (char *)peb->ImageBaseAddress + nt->OptionalHeader.AddressOfEntryPoint ); req->entry = wine_server_client_ptr( entry );
req->gui = (nt->OptionalHeader.Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CUI); req->gui = (nt->OptionalHeader.Subsystem != IMAGE_SUBSYSTEM_WINDOWS_CUI);
status = wine_server_call( req ); status = wine_server_call( req );
} }
......
...@@ -981,7 +981,7 @@ void signal_init_thread( TEB *teb ) ...@@ -981,7 +981,7 @@ void signal_init_thread( TEB *teb )
/********************************************************************** /**********************************************************************
* signal_init_process * signal_init_process
*/ */
void signal_init_process(void) void signal_init_process( CONTEXT *context, LPTHREAD_START_ROUTINE entry )
{ {
struct sigaction sig_act; struct sigaction sig_act;
...@@ -1010,6 +1010,8 @@ void signal_init_process(void) ...@@ -1010,6 +1010,8 @@ void signal_init_process(void)
sig_act.sa_sigaction = trap_handler; sig_act.sa_sigaction = trap_handler;
if (sigaction( SIGTRAP, &sig_act, NULL ) == -1) goto error; if (sigaction( SIGTRAP, &sig_act, NULL ) == -1) goto error;
#endif #endif
/* FIXME: set the initial context */
return; return;
error: error:
......
...@@ -852,7 +852,7 @@ void signal_init_thread( TEB *teb ) ...@@ -852,7 +852,7 @@ void signal_init_thread( TEB *teb )
/********************************************************************** /**********************************************************************
* signal_init_process * signal_init_process
*/ */
void signal_init_process(void) void signal_init_process( CONTEXT *context, LPTHREAD_START_ROUTINE entry )
{ {
struct sigaction sig_act; struct sigaction sig_act;
...@@ -881,6 +881,8 @@ void signal_init_process(void) ...@@ -881,6 +881,8 @@ void signal_init_process(void)
sig_act.sa_sigaction = trap_handler; sig_act.sa_sigaction = trap_handler;
if (sigaction( SIGTRAP, &sig_act, NULL ) == -1) goto error; if (sigaction( SIGTRAP, &sig_act, NULL ) == -1) goto error;
#endif #endif
/* FIXME: set the initial context */
return; return;
error: error:
......
...@@ -2557,7 +2557,7 @@ void signal_init_thread( TEB *teb ) ...@@ -2557,7 +2557,7 @@ void signal_init_thread( TEB *teb )
/********************************************************************** /**********************************************************************
* signal_init_process * signal_init_process
*/ */
void signal_init_process(void) void signal_init_process( CONTEXT *context, LPTHREAD_START_ROUTINE entry )
{ {
struct sigaction sig_act; struct sigaction sig_act;
...@@ -2599,6 +2599,8 @@ void signal_init_process(void) ...@@ -2599,6 +2599,8 @@ void signal_init_process(void)
#endif #endif
wine_ldt_init_locking( ldt_lock, ldt_unlock ); wine_ldt_init_locking( ldt_lock, ldt_unlock );
/* FIXME: set the initial context */
return; return;
error: error:
......
...@@ -1054,7 +1054,7 @@ void signal_init_thread( TEB *teb ) ...@@ -1054,7 +1054,7 @@ void signal_init_thread( TEB *teb )
/********************************************************************** /**********************************************************************
* signal_init_process * signal_init_process
*/ */
void signal_init_process(void) void signal_init_process( CONTEXT *context, LPTHREAD_START_ROUTINE entry )
{ {
struct sigaction sig_act; struct sigaction sig_act;
...@@ -1083,6 +1083,8 @@ void signal_init_process(void) ...@@ -1083,6 +1083,8 @@ void signal_init_process(void)
sig_act.sa_sigaction = trap_handler; sig_act.sa_sigaction = trap_handler;
if (sigaction( SIGTRAP, &sig_act, NULL ) == -1) goto error; if (sigaction( SIGTRAP, &sig_act, NULL ) == -1) goto error;
#endif #endif
/* FIXME: set the initial context */
return; return;
error: error:
......
...@@ -3102,7 +3102,7 @@ void signal_init_thread( TEB *teb ) ...@@ -3102,7 +3102,7 @@ void signal_init_thread( TEB *teb )
/********************************************************************** /**********************************************************************
* signal_init_process * signal_init_process
*/ */
void signal_init_process(void) void signal_init_process( CONTEXT *context, LPTHREAD_START_ROUTINE entry )
{ {
struct sigaction sig_act; struct sigaction sig_act;
...@@ -3131,6 +3131,8 @@ void signal_init_process(void) ...@@ -3131,6 +3131,8 @@ void signal_init_process(void)
sig_act.sa_sigaction = trap_handler; sig_act.sa_sigaction = trap_handler;
if (sigaction( SIGTRAP, &sig_act, NULL ) == -1) goto error; if (sigaction( SIGTRAP, &sig_act, NULL ) == -1) goto error;
#endif #endif
/* FIXME: set the initial context */
return; return;
error: error:
......
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