kernel: Moved main stack initialization to process.c.
This commit is contained in:
parent
770c4a1551
commit
8a8a94aecb
|
@ -115,9 +115,6 @@ extern LPVOID DOSMEM_MapDosToLinear(UINT); /* linear DOS to Wine */
|
||||||
extern UINT DOSMEM_MapLinearToDos(LPVOID); /* linear Wine to DOS */
|
extern UINT DOSMEM_MapLinearToDos(LPVOID); /* linear Wine to DOS */
|
||||||
extern void load_winedos(void);
|
extern void load_winedos(void);
|
||||||
|
|
||||||
/* thread.c */
|
|
||||||
extern TEB *THREAD_InitStack( TEB *teb, DWORD stack_size );
|
|
||||||
|
|
||||||
/* environ.c */
|
/* environ.c */
|
||||||
extern void ENV_CopyStartupInformation(void);
|
extern void ENV_CopyStartupInformation(void);
|
||||||
|
|
||||||
|
|
|
@ -966,6 +966,38 @@ static BOOL process_init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* init_stack
|
||||||
|
*
|
||||||
|
* Allocate the stack of new process.
|
||||||
|
*/
|
||||||
|
static void *init_stack(void)
|
||||||
|
{
|
||||||
|
void *base;
|
||||||
|
SIZE_T stack_size, page_size = getpagesize();
|
||||||
|
IMAGE_NT_HEADERS *nt = RtlImageNtHeader( NtCurrentTeb()->Peb->ImageBaseAddress );
|
||||||
|
|
||||||
|
stack_size = max( nt->OptionalHeader.SizeOfStackReserve, nt->OptionalHeader.SizeOfStackCommit );
|
||||||
|
stack_size = (stack_size + (page_size - 1)) & ~(page_size - 1);
|
||||||
|
if (stack_size < 1024 * 1024) stack_size = 1024 * 1024; /* Xlib needs a large stack */
|
||||||
|
|
||||||
|
if (!(base = VirtualAlloc( NULL, stack_size, MEM_COMMIT, PAGE_READWRITE )))
|
||||||
|
{
|
||||||
|
ERR( "failed to allocate main process stack\n" );
|
||||||
|
ExitProcess( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* note: limit is lower than base since the stack grows down */
|
||||||
|
NtCurrentTeb()->DeallocationStack = base;
|
||||||
|
NtCurrentTeb()->Tib.StackBase = (char *)base + stack_size;
|
||||||
|
NtCurrentTeb()->Tib.StackLimit = base;
|
||||||
|
|
||||||
|
/* setup guard page */
|
||||||
|
VirtualProtect( base, 1, PAGE_READWRITE | PAGE_GUARD, NULL );
|
||||||
|
return NtCurrentTeb()->Tib.StackBase;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* start_process
|
* start_process
|
||||||
*
|
*
|
||||||
|
@ -1010,7 +1042,6 @@ void __wine_kernel_init(void)
|
||||||
{
|
{
|
||||||
WCHAR *main_exe_name, *p;
|
WCHAR *main_exe_name, *p;
|
||||||
char error[1024];
|
char error[1024];
|
||||||
DWORD stack_size = 0;
|
|
||||||
int file_exists;
|
int file_exists;
|
||||||
PEB *peb = NtCurrentTeb()->Peb;
|
PEB *peb = NtCurrentTeb()->Peb;
|
||||||
|
|
||||||
|
@ -1130,13 +1161,8 @@ void __wine_kernel_init(void)
|
||||||
set_library_wargv( __wine_main_argv );
|
set_library_wargv( __wine_main_argv );
|
||||||
if (!build_command_line( __wine_main_wargv )) goto error;
|
if (!build_command_line( __wine_main_wargv )) goto error;
|
||||||
|
|
||||||
stack_size = RtlImageNtHeader(peb->ImageBaseAddress)->OptionalHeader.SizeOfStackReserve;
|
|
||||||
|
|
||||||
/* allocate main thread stack */
|
|
||||||
if (!THREAD_InitStack( NtCurrentTeb(), stack_size )) goto error;
|
|
||||||
|
|
||||||
/* switch to the new stack */
|
/* switch to the new stack */
|
||||||
wine_switch_to_stack( start_process, NULL, NtCurrentTeb()->Tib.StackBase );
|
wine_switch_to_stack( start_process, NULL, init_stack() );
|
||||||
|
|
||||||
error:
|
error:
|
||||||
ExitProcess( GetLastError() );
|
ExitProcess( GetLastError() );
|
||||||
|
|
|
@ -49,34 +49,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(thread);
|
||||||
WINE_DECLARE_DEBUG_CHANNEL(relay);
|
WINE_DECLARE_DEBUG_CHANNEL(relay);
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
|
||||||
* THREAD_InitStack
|
|
||||||
*
|
|
||||||
* Allocate the stack of a thread.
|
|
||||||
*/
|
|
||||||
TEB *THREAD_InitStack( TEB *teb, DWORD stack_size )
|
|
||||||
{
|
|
||||||
DWORD old_prot;
|
|
||||||
DWORD page_size = getpagesize();
|
|
||||||
void *base;
|
|
||||||
|
|
||||||
stack_size = (stack_size + (page_size - 1)) & ~(page_size - 1);
|
|
||||||
if (stack_size < 1024 * 1024) stack_size = 1024 * 1024; /* Xlib needs a large stack */
|
|
||||||
|
|
||||||
if (!(base = VirtualAlloc( NULL, stack_size, MEM_COMMIT, PAGE_READWRITE )))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
teb->DeallocationStack = base;
|
|
||||||
teb->Tib.StackBase = (char *)base + stack_size;
|
|
||||||
teb->Tib.StackLimit = base; /* note: limit is lower than base since the stack grows down */
|
|
||||||
|
|
||||||
/* Setup guard pages */
|
|
||||||
|
|
||||||
VirtualProtect( base, 1, PAGE_READWRITE | PAGE_GUARD, &old_prot );
|
|
||||||
return teb;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
struct new_thread_info
|
struct new_thread_info
|
||||||
{
|
{
|
||||||
LPTHREAD_START_ROUTINE func;
|
LPTHREAD_START_ROUTINE func;
|
||||||
|
|
Loading…
Reference in New Issue