Allocate/free the 16-bit thread stack in the kernel dll init routine.
This commit is contained in:
parent
fde5ab17f9
commit
e15aadd58a
|
@ -38,6 +38,8 @@
|
||||||
#include "miscemu.h"
|
#include "miscemu.h"
|
||||||
#include "module.h"
|
#include "module.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
|
#include "thread.h"
|
||||||
|
#include "stackframe.h"
|
||||||
#include "wincon.h"
|
#include "wincon.h"
|
||||||
#include "console_private.h"
|
#include "console_private.h"
|
||||||
|
|
||||||
|
@ -64,6 +66,31 @@ static void ldt_unlock(void)
|
||||||
LeaveCriticalSection( &ldt_section );
|
LeaveCriticalSection( &ldt_section );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* KERNEL thread initialisation routine
|
||||||
|
*/
|
||||||
|
static void thread_attach(void)
|
||||||
|
{
|
||||||
|
/* allocate the 16-bit stack (FIXME: should be done lazily) */
|
||||||
|
HGLOBAL16 hstack = K32WOWGlobalAlloc16( GMEM_FIXED, 0x10000 );
|
||||||
|
NtCurrentTeb()->stack_sel = GlobalHandleToSel16( hstack );
|
||||||
|
NtCurrentTeb()->cur_stack = MAKESEGPTR( NtCurrentTeb()->stack_sel,
|
||||||
|
0x10000 - sizeof(STACK16FRAME) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***********************************************************************
|
||||||
|
* KERNEL thread finalisation routine
|
||||||
|
*/
|
||||||
|
static void thread_detach(void)
|
||||||
|
{
|
||||||
|
/* free the 16-bit stack */
|
||||||
|
K32WOWGlobalFree16( NtCurrentTeb()->stack_sel );
|
||||||
|
NtCurrentTeb()->cur_stack = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/***********************************************************************
|
/***********************************************************************
|
||||||
* KERNEL process initialisation routine
|
* KERNEL process initialisation routine
|
||||||
*/
|
*/
|
||||||
|
@ -144,6 +171,7 @@ static BOOL process_attach(void)
|
||||||
if (main_create_flags & CREATE_NEW_PROCESS_GROUP)
|
if (main_create_flags & CREATE_NEW_PROCESS_GROUP)
|
||||||
SetConsoleCtrlHandler(NULL, TRUE);
|
SetConsoleCtrlHandler(NULL, TRUE);
|
||||||
|
|
||||||
|
thread_attach();
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,6 +184,12 @@ BOOL WINAPI MAIN_KernelInit( HINSTANCE hinst, DWORD reason, LPVOID reserved )
|
||||||
{
|
{
|
||||||
case DLL_PROCESS_ATTACH:
|
case DLL_PROCESS_ATTACH:
|
||||||
return process_attach();
|
return process_attach();
|
||||||
|
case DLL_THREAD_ATTACH:
|
||||||
|
thread_attach();
|
||||||
|
break;
|
||||||
|
case DLL_THREAD_DETACH:
|
||||||
|
thread_detach();
|
||||||
|
break;
|
||||||
case DLL_PROCESS_DETACH:
|
case DLL_PROCESS_DETACH:
|
||||||
WriteOutProfiles16();
|
WriteOutProfiles16();
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -293,7 +293,6 @@ void SYSDEPS_ExitThread( int status )
|
||||||
struct thread_cleanup_info info;
|
struct thread_cleanup_info info;
|
||||||
MEMORY_BASIC_INFORMATION meminfo;
|
MEMORY_BASIC_INFORMATION meminfo;
|
||||||
|
|
||||||
wine_ldt_free_entries( teb->stack_sel, 1 );
|
|
||||||
VirtualQuery( teb->stack_top, &meminfo, sizeof(meminfo) );
|
VirtualQuery( teb->stack_top, &meminfo, sizeof(meminfo) );
|
||||||
info.stack_base = meminfo.AllocationBase;
|
info.stack_base = meminfo.AllocationBase;
|
||||||
info.stack_size = meminfo.RegionSize + ((char *)teb->stack_top - (char *)meminfo.AllocationBase);
|
info.stack_size = meminfo.RegionSize + ((char *)teb->stack_top - (char *)meminfo.AllocationBase);
|
||||||
|
|
|
@ -120,7 +120,6 @@ static void THREAD_FreeTEB( TEB *teb )
|
||||||
{
|
{
|
||||||
TRACE("(%p) called\n", teb );
|
TRACE("(%p) called\n", teb );
|
||||||
/* Free the associated memory */
|
/* Free the associated memory */
|
||||||
wine_ldt_free_entries( teb->stack_sel, 1 );
|
|
||||||
wine_ldt_free_fs( teb->teb_sel );
|
wine_ldt_free_fs( teb->teb_sel );
|
||||||
VirtualFree( teb->stack_base, 0, MEM_RELEASE );
|
VirtualFree( teb->stack_base, 0, MEM_RELEASE );
|
||||||
}
|
}
|
||||||
|
@ -163,14 +162,12 @@ TEB *THREAD_InitStack( TEB *teb, DWORD stack_size )
|
||||||
* 1 page NOACCESS guard page
|
* 1 page NOACCESS guard page
|
||||||
* 1 page PAGE_GUARD guard page
|
* 1 page PAGE_GUARD guard page
|
||||||
* stack_size normal stack
|
* stack_size normal stack
|
||||||
* 64Kb 16-bit stack (optional)
|
|
||||||
* 1 page TEB (except for initial thread)
|
* 1 page TEB (except for initial thread)
|
||||||
* 1 page debug info (except for initial thread)
|
* 1 page debug info (except for initial thread)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
stack_size = (stack_size + (page_size - 1)) & ~(page_size - 1);
|
stack_size = (stack_size + (page_size - 1)) & ~(page_size - 1);
|
||||||
total_size = stack_size + SIGNAL_STACK_SIZE + 3 * page_size;
|
total_size = stack_size + SIGNAL_STACK_SIZE + 3 * page_size;
|
||||||
total_size += 0x10000; /* 16-bit stack */
|
|
||||||
if (!teb) total_size += 2 * page_size;
|
if (!teb) total_size += 2 * page_size;
|
||||||
|
|
||||||
if (!(base = VirtualAlloc( NULL, total_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE )))
|
if (!(base = VirtualAlloc( NULL, total_size, MEM_COMMIT, PAGE_EXECUTE_READWRITE )))
|
||||||
|
@ -179,7 +176,11 @@ TEB *THREAD_InitStack( TEB *teb, DWORD stack_size )
|
||||||
if (!teb)
|
if (!teb)
|
||||||
{
|
{
|
||||||
teb = (TEB *)((char *)base + total_size - 2 * page_size);
|
teb = (TEB *)((char *)base + total_size - 2 * page_size);
|
||||||
if (!THREAD_InitTEB( teb )) goto error;
|
if (!THREAD_InitTEB( teb ))
|
||||||
|
{
|
||||||
|
VirtualFree( base, 0, MEM_RELEASE );
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
teb->debug_info = (char *)teb + page_size;
|
teb->debug_info = (char *)teb + page_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,19 +195,7 @@ TEB *THREAD_InitStack( TEB *teb, DWORD stack_size )
|
||||||
VirtualProtect( (char *)teb->signal_stack + SIGNAL_STACK_SIZE, 1, PAGE_NOACCESS, &old_prot );
|
VirtualProtect( (char *)teb->signal_stack + SIGNAL_STACK_SIZE, 1, PAGE_NOACCESS, &old_prot );
|
||||||
VirtualProtect( (char *)teb->signal_stack + SIGNAL_STACK_SIZE + page_size, 1,
|
VirtualProtect( (char *)teb->signal_stack + SIGNAL_STACK_SIZE + page_size, 1,
|
||||||
PAGE_EXECUTE_READWRITE | PAGE_GUARD, &old_prot );
|
PAGE_EXECUTE_READWRITE | PAGE_GUARD, &old_prot );
|
||||||
|
|
||||||
/* Allocate the 16-bit stack selector */
|
|
||||||
|
|
||||||
teb->stack_sel = SELECTOR_AllocBlock( teb->stack_top, 0x10000, WINE_LDT_FLAGS_DATA );
|
|
||||||
if (!teb->stack_sel) goto error;
|
|
||||||
teb->cur_stack = MAKESEGPTR( teb->stack_sel, 0x10000 - sizeof(STACK16FRAME) );
|
|
||||||
|
|
||||||
return teb;
|
return teb;
|
||||||
|
|
||||||
error:
|
|
||||||
wine_ldt_free_fs( teb->teb_sel );
|
|
||||||
VirtualFree( base, 0, MEM_RELEASE );
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue