Commit 0f079d78 authored by Alexandre Julliard's avatar Alexandre Julliard

Moved the kernel per-thread data out of the TEB into a private

structure stored in TEB.SystemReserved1.
parent 6ae4ee49
......@@ -28,6 +28,8 @@
#include "winbase.h"
#include "winerror.h"
#include "ntstatus.h"
#include "winreg.h"
#include "winternl.h"
#include "kernel_private.h"
#include "wine/windef16.h"
#include "wine/server.h"
......
......@@ -40,6 +40,8 @@
#include "wine/winbase16.h"
#include "ntstatus.h"
#include "toolhelp.h"
#include "winreg.h"
#include "winternl.h"
#include "kernel_private.h"
#include "kernel16_private.h"
#include "wine/debug.h"
......
......@@ -33,7 +33,6 @@
#include "windef.h"
#include "winbase.h"
#include "wincon.h"
#include "thread.h"
#include "winreg.h"
#include "winternl.h"
......@@ -84,8 +83,8 @@ 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()->WOW32Reserved = (void *)MAKESEGPTR( NtCurrentTeb()->stack_sel,
kernel_get_thread_data()->stack_sel = GlobalHandleToSel16( hstack );
NtCurrentTeb()->WOW32Reserved = (void *)MAKESEGPTR( kernel_get_thread_data()->stack_sel,
0x10000 - sizeof(STACK16FRAME) );
}
......@@ -96,7 +95,7 @@ static void thread_attach(void)
static void thread_detach(void)
{
/* free the 16-bit stack */
K32WOWGlobalFree16( NtCurrentTeb()->stack_sel );
K32WOWGlobalFree16( kernel_get_thread_data()->stack_sel );
NtCurrentTeb()->WOW32Reserved = 0;
if (NtCurrentTeb()->Tib.SubSystemTib) TASK_ExitTask();
}
......
......@@ -21,6 +21,24 @@
#ifndef __WINE_KERNEL_PRIVATE_H
#define __WINE_KERNEL_PRIVATE_H
struct tagSYSLEVEL;
struct kernel_thread_data
{
UINT code_page; /* thread code page */
WORD stack_sel; /* 16-bit stack selector */
WORD htask16; /* Win16 task handle */
DWORD sys_count[4]; /* syslevel mutex entry counters */
struct tagSYSLEVEL *sys_mutex[4]; /* syslevel mutex pointers */
void *pthread_data; /* private data for pthread emulation */
void *pad[43]; /* change this if you add fields! */
};
static inline struct kernel_thread_data *kernel_get_thread_data(void)
{
return (struct kernel_thread_data *)NtCurrentTeb()->SystemReserved1;
}
HANDLE WINAPI OpenConsoleW(LPCWSTR, DWORD, BOOL, DWORD);
BOOL WINAPI VerifyConsoleIoHandle(HANDLE);
HANDLE WINAPI DuplicateConsoleHandle(HANDLE, DWORD, BOOL, DWORD);
......@@ -98,6 +116,9 @@ extern LPVOID DOSMEM_MapDosToLinear(UINT); /* linear DOS to Wine */
extern UINT DOSMEM_MapLinearToDos(LPVOID); /* linear Wine to DOS */
extern void load_winedos(void);
/* thread.c */
extern TEB *THREAD_InitStack( TEB *teb, DWORD stack_size );
extern struct winedos_exports
{
/* for global16.c */
......
......@@ -36,6 +36,8 @@
#include "wine/winbase16.h"
#include "wownt32.h"
#include "toolhelp.h"
#include "winreg.h"
#include "winternl.h"
#include "kernel_private.h"
#include "kernel16_private.h"
#include "wine/debug.h"
......
......@@ -35,7 +35,6 @@
#include "windef.h"
#include "winbase.h"
#include "winuser.h" /* for RT_STRINGW */
#include "thread.h"
#include "winreg.h"
#include "winternl.h"
#include "wine/unicode.h"
......@@ -203,7 +202,7 @@ static const union cptable *get_codepage_table( unsigned int codepage )
case CP_UTF8:
break;
case CP_THREAD_ACP:
if (!(codepage = NtCurrentTeb()->code_page)) return ansi_cptable;
if (!(codepage = kernel_get_thread_data()->code_page)) return ansi_cptable;
/* fall through */
default:
if (codepage == ansi_cptable->info.codepage) return ansi_cptable;
......@@ -1713,7 +1712,7 @@ BOOL WINAPI SetThreadLocale( LCID lcid )
}
NtCurrentTeb()->CurrentLocale = lcid;
NtCurrentTeb()->code_page = get_lcid_codepage( lcid );
kernel_get_thread_data()->code_page = get_lcid_codepage( lcid );
}
return TRUE;
}
......
......@@ -35,6 +35,8 @@
#include "windef.h"
#include "wine/winbase16.h"
#include "wownt32.h"
#include "winreg.h"
#include "winternl.h"
#include "toolhelp.h"
#include "excpt.h"
#include "kernel_private.h"
......
......@@ -35,6 +35,8 @@
#include "wine/winbase16.h"
#include "wownt32.h"
#include "winreg.h"
#include "winternl.h"
#include "wine/library.h"
#include "kernel_private.h"
#include "kernel16_private.h"
......
......@@ -45,8 +45,9 @@
#include "windef.h"
#include "winbase.h"
#include "thread.h"
#include "winreg.h"
#include "winternl.h"
#include "kernel_private.h"
#include "wine/pthread.h"
#define P_OUTPUT(stuff) write(2,stuff,strlen(stuff))
......@@ -531,12 +532,12 @@ static void wine_pthread_exit(void *retval, char *currentframe)
static void *wine_get_thread_data(void)
{
return NtCurrentTeb()->pthread_data;
return kernel_get_thread_data()->pthread_data;
}
static void wine_set_thread_data( void *data )
{
NtCurrentTeb()->pthread_data = data;
kernel_get_thread_data()->pthread_data = data;
}
static const struct wine_pthread_functions functions =
......
......@@ -29,6 +29,8 @@
#include "windef.h"
#include "winbase.h"
#include "wine/winbase16.h"
#include "winreg.h"
#include "winternl.h"
#include "kernel_private.h"
#include "kernel16_private.h"
#include "wine/unicode.h"
......
......@@ -29,6 +29,8 @@
#include "winbase.h"
#include "winnt.h"
#include "wine/winbase16.h"
#include "winreg.h"
#include "winternl.h"
#include "wine/library.h"
#include "kernel_private.h"
#include "kernel16_private.h"
......
......@@ -27,7 +27,6 @@
#include <sys/types.h>
#include "windef.h"
#include "winbase.h"
#include "thread.h"
#include "winreg.h"
#include "winternl.h"
#include "wine/winbase16.h"
......@@ -93,26 +92,26 @@ VOID WINAPI _CreateSysLevel(SYSLEVEL *lock, INT level)
*/
VOID WINAPI _EnterSysLevel(SYSLEVEL *lock)
{
TEB *teb = NtCurrentTeb();
struct kernel_thread_data *thread_data = kernel_get_thread_data();
int i;
TRACE("(%p, level %d): thread %lx count before %ld\n",
lock, lock->level, GetCurrentThreadId(), teb->sys_count[lock->level] );
lock, lock->level, GetCurrentThreadId(), thread_data->sys_count[lock->level] );
for ( i = 3; i > lock->level; i-- )
if ( teb->sys_count[i] > 0 )
if ( thread_data->sys_count[i] > 0 )
{
ERR("(%p, level %d): Holding %p, level %d. Expect deadlock!\n",
lock, lock->level, teb->sys_mutex[i], i );
lock, lock->level, thread_data->sys_mutex[i], i );
}
RtlEnterCriticalSection( &lock->crst );
teb->sys_count[lock->level]++;
teb->sys_mutex[lock->level] = lock;
thread_data->sys_count[lock->level]++;
thread_data->sys_mutex[lock->level] = lock;
TRACE("(%p, level %d): thread %lx count after %ld\n",
lock, lock->level, GetCurrentThreadId(), teb->sys_count[lock->level] );
lock, lock->level, GetCurrentThreadId(), thread_data->sys_count[lock->level] );
#ifdef __i386__
if (lock == &Win16Mutex) CallTo16_TebSelector = wine_get_fs();
......@@ -125,27 +124,27 @@ VOID WINAPI _EnterSysLevel(SYSLEVEL *lock)
*/
VOID WINAPI _LeaveSysLevel(SYSLEVEL *lock)
{
TEB *teb = NtCurrentTeb();
struct kernel_thread_data *thread_data = kernel_get_thread_data();
TRACE("(%p, level %d): thread %lx count before %ld\n",
lock, lock->level, GetCurrentThreadId(), teb->sys_count[lock->level] );
lock, lock->level, GetCurrentThreadId(), thread_data->sys_count[lock->level] );
if ( teb->sys_count[lock->level] <= 0 || teb->sys_mutex[lock->level] != lock )
if ( thread_data->sys_count[lock->level] <= 0 || thread_data->sys_mutex[lock->level] != lock )
{
ERR("(%p, level %d): Invalid state: count %ld mutex %p.\n",
lock, lock->level, teb->sys_count[lock->level],
teb->sys_mutex[lock->level] );
lock, lock->level, thread_data->sys_count[lock->level],
thread_data->sys_mutex[lock->level] );
}
else
{
if ( --teb->sys_count[lock->level] == 0 )
teb->sys_mutex[lock->level] = NULL;
if ( --thread_data->sys_count[lock->level] == 0 )
thread_data->sys_mutex[lock->level] = NULL;
}
RtlLeaveCriticalSection( &lock->crst );
TRACE("(%p, level %d): thread %lx count after %ld\n",
lock, lock->level, GetCurrentThreadId(), teb->sys_count[lock->level] );
lock, lock->level, GetCurrentThreadId(), thread_data->sys_count[lock->level] );
}
/************************************************************************
......@@ -236,7 +235,7 @@ VOID SYSLEVEL_CheckNotLevel( INT level )
INT i;
for ( i = 3; i >= level; i-- )
if ( NtCurrentTeb()->sys_count[i] > 0 )
if ( kernel_get_thread_data()->sys_count[i] > 0 )
{
ERR("(%d): Holding lock of level %d!\n",
level, i );
......
......@@ -28,6 +28,8 @@
#include "wine/winbase16.h"
#include "wine/winuser16.h"
#include "wownt32.h"
#include "winreg.h"
#include "winternl.h"
#include "kernel_private.h"
#include "kernel16_private.h"
#include "wine/debug.h"
......
......@@ -458,7 +458,7 @@ static DWORD CALLBACK task_start( LPVOID p )
TDB *pTask = (TDB *)p;
DWORD ret;
NtCurrentTeb()->htask16 = pTask->hSelf;
kernel_get_thread_data()->htask16 = pTask->hSelf;
NtCurrentTeb()->Tib.SubSystemTib = allocate_win16_tib( pTask );
_EnterWin16Lock();
......@@ -1176,7 +1176,7 @@ void WINAPI GetTaskQueueES16(void)
*/
HTASK16 WINAPI GetCurrentTask(void)
{
HTASK16 ret = NtCurrentTeb()->htask16;
HTASK16 ret = kernel_get_thread_data()->htask16;
if (!ret) ret = main_task;
return ret;
}
......
......@@ -38,6 +38,7 @@
#include "winbase.h"
#include "winreg.h"
#include "winerror.h"
#include "winternl.h"
#include "kernel_private.h"
#include "wine/library.h"
#include "wine/unicode.h"
......
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