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