Renamed a few more TEB fields.

This commit is contained in:
Alexandre Julliard 2003-08-28 03:44:41 +00:00
parent ee106783d0
commit b91e9cb3e6
7 changed files with 75 additions and 82 deletions

View File

@ -141,7 +141,7 @@ void _local_unwind2(MSVCRT_EXCEPTION_FRAME* frame, int trylevel)
/* Register a handler in case of a nested exception */
reg.Handler = (PEXCEPTION_HANDLER)MSVCRT_nested_handler;
reg.Prev = NtCurrentTeb()->except;
reg.Prev = NtCurrentTeb()->Tib.ExceptionList;
__wine_push_frame(&reg);
while (frame->trylevel != TRYLEVEL_END && frame->trylevel != trylevel)
@ -285,7 +285,7 @@ void _MSVCRT__setjmp(_JUMP_BUFFER *jmp, CONTEXT86* context)
jmp->Esi = context->Esi;
jmp->Esp = context->Esp;
jmp->Eip = context->Eip;
jmp->Registration = (unsigned long)NtCurrentTeb()->except;
jmp->Registration = (unsigned long)NtCurrentTeb()->Tib.ExceptionList;
if (jmp->Registration == TRYLEVEL_END)
jmp->TryLevel = TRYLEVEL_END;
else
@ -308,7 +308,7 @@ void _MSVCRT__setjmp3(_JUMP_BUFFER *jmp, int nb_args, CONTEXT86* context)
jmp->Eip = context->Eip;
jmp->Cookie = MSVCRT_JMP_MAGIC;
jmp->UnwindFunc = 0;
jmp->Registration = (unsigned long)NtCurrentTeb()->except;
jmp->Registration = (unsigned long)NtCurrentTeb()->Tib.ExceptionList;
if (jmp->Registration == TRYLEVEL_END)
{
jmp->TryLevel = TRYLEVEL_END;
@ -339,7 +339,7 @@ void _MSVCRT_longjmp(_JUMP_BUFFER *jmp, int retval, CONTEXT86* context)
TRACE("(%p,%d)\n", jmp, retval);
cur_frame=(unsigned long)NtCurrentTeb()->except;
cur_frame=(unsigned long)NtCurrentTeb()->Tib.ExceptionList;
TRACE("cur_frame=%lx\n",cur_frame);
if (cur_frame != jmp->Registration)

View File

@ -193,13 +193,13 @@ void WINAPI EXC_RtlRaiseException( EXCEPTION_RECORD *rec, CONTEXT *context )
SIGNAL_Unblock(); /* we may be in a signal handler, and exception handlers may jump out */
frame = NtCurrentTeb()->except;
frame = NtCurrentTeb()->Tib.ExceptionList;
nested_frame = NULL;
while (frame != (PEXCEPTION_REGISTRATION_RECORD)~0UL)
{
/* Check frame address */
if (((void*)frame < NtCurrentTeb()->stack_low) ||
((void*)(frame+1) > NtCurrentTeb()->stack_top) ||
if (((void*)frame < NtCurrentTeb()->Tib.StackLimit) ||
((void*)(frame+1) > NtCurrentTeb()->Tib.StackBase) ||
(int)frame & 3)
{
rec->ExceptionFlags |= EH_STACK_INVALID;
@ -277,7 +277,7 @@ void WINAPI EXC_RtlUnwind( PEXCEPTION_REGISTRATION_RECORD pEndFrame, LPVOID unus
TRACE( "code=%lx flags=%lx\n", pRecord->ExceptionCode, pRecord->ExceptionFlags );
/* get chain of exception frames */
frame = NtCurrentTeb()->except;
frame = NtCurrentTeb()->Tib.ExceptionList;
while ((frame != (PEXCEPTION_REGISTRATION_RECORD)~0UL) && (frame != pEndFrame))
{
/* Check frame address */
@ -289,8 +289,8 @@ void WINAPI EXC_RtlUnwind( PEXCEPTION_REGISTRATION_RECORD pEndFrame, LPVOID unus
newrec.NumberParameters = 0;
RtlRaiseException( &newrec ); /* never returns */
}
if (((void*)frame < NtCurrentTeb()->stack_low) ||
((void*)(frame+1) > NtCurrentTeb()->stack_top) ||
if (((void*)frame < NtCurrentTeb()->Tib.StackLimit) ||
((void*)(frame+1) > NtCurrentTeb()->Tib.StackBase) ||
(int)frame & 3)
{
newrec.ExceptionCode = STATUS_BAD_STACK;

View File

@ -150,16 +150,17 @@ int SYSDEPS_SpawnThread( void (*func)(TEB *), TEB *teb )
pthread_attr_t attr;
pthread_attr_init( &attr );
pthread_attr_setstack( &attr, teb->stack_base, (char *)teb->stack_top - (char *)teb->stack_base );
pthread_attr_setstack( &attr, teb->DeallocationStack,
(char *)teb->Tib.StackBase - (char *)teb->DeallocationStack );
if (pthread_create( &id, &attr, (void * (*)(void *))func, teb )) return -1;
return 0;
#elif defined(HAVE_CLONE)
if (clone( (int (*)(void *))func, teb->stack_top,
if (clone( (int (*)(void *))func, teb->Tib.StackBase,
CLONE_VM | CLONE_FS | CLONE_FILES | SIGCHLD, teb ) < 0)
return -1;
return 0;
#elif defined(HAVE_RFORK)
void **sp = (void **)teb->stack_top;
void **sp = (void **)teb->Tib.StackBase;
*--sp = teb;
*--sp = 0;
*--sp = func;
@ -180,7 +181,7 @@ int SYSDEPS_SpawnThread( void (*func)(TEB *), TEB *teb )
#elif defined(HAVE__LWP_CREATE)
ucontext_t context;
_lwp_makecontext( &context, (void(*)(void *))func, teb,
NULL, teb->stack_base, (char *)teb->stack_top - (char *)teb->stack_base );
NULL, teb->DeallocationStack, (char *)teb->Tib.StackBase - (char *)teb->DeallocationStack );
if ( _lwp_create( &context, 0, NULL ) )
return -1;
return 0;
@ -203,7 +204,7 @@ void DECLSPEC_NORETURN SYSDEPS_SwitchToThreadStack( void (*func)(void *), void *
__ASM_GLOBAL_FUNC( SYSDEPS_SwitchToThreadStack,
"movl 4(%esp),%ecx\n\t" /* func */
"movl 8(%esp),%edx\n\t" /* arg */
".byte 0x64\n\tmovl 0x04,%esp\n\t" /* teb->stack_top */
".byte 0x64\n\tmovl 0x04,%esp\n\t" /* teb->Tib.StackBase */
"pushl %edx\n\t"
"xorl %ebp,%ebp\n\t"
"call *%ecx\n\t"
@ -225,7 +226,7 @@ __ASM_GLOBAL_FUNC( SYSDEPS_SwitchToThreadStack,
"mov %o0, %l0\n\t" /* store first argument */
"call " __ASM_NAME("NtCurrentTeb") ", 0\n\t"
"mov %o1, %l1\n\t" /* delay slot: store second argument */
"ld [%o0+4], %sp\n\t" /* teb->stack_top */
"ld [%o0+4], %sp\n\t" /* teb->Tib.StackBase */
"call %l0, 0\n\t" /* call func */
"mov %l1, %o0\n\t" /* delay slot: arg for func */
"ta 0x01\n\t"); /* breakpoint - we never get here */
@ -233,7 +234,7 @@ __ASM_GLOBAL_FUNC( SYSDEPS_SwitchToThreadStack,
/* Darwin SYSDEPS_SwitchToThreadStack
Function Pointer to call is on r3, Args to pass on r4 and stack on r1 */
__ASM_GLOBAL_FUNC( SYSDEPS_SwitchToThreadStack,
"stw r1, 0x4(r13)\n\t" /* teb->stack_top */
"stw r1, 0x4(r13)\n\t" /* teb->Tib.StackBase */
"mr r12,r3\n\t"
"mtctr r12\n\t" /* func->ctr */
"mr r3,r4\n\t" /* args->function param 1 (r3) */
@ -243,7 +244,7 @@ __ASM_GLOBAL_FUNC( SYSDEPS_SwitchToThreadStack,
/* Linux SYSDEPS_SwitchToThreadStack
Function Pointer to call is on r3, Args to pass on r4 and stack on r1 */
__ASM_GLOBAL_FUNC( SYSDEPS_SwitchToThreadStack,
"stw 1, 0x4(13)\n\t" /* teb->stack_top */
"stw 1, 0x4(13)\n\t" /* teb->Tib.StackBase */
"mr 12,3\n\t"
"mtctr 12\n\t" /* func->ctr */
"mr 3,4\n\t" /* args->function param 1 (r3) */
@ -277,11 +278,11 @@ void SYSDEPS_ExitThread( int status )
void *ptr;
TRACE("freeing prev teb %p stack %p fs %04x\n",
free_teb, free_teb->stack_base, free_teb->teb_sel );
free_teb, free_teb->DeallocationStack, free_teb->teb_sel );
pthread_join( (pthread_t)free_teb->pthread_data, &ptr );
wine_ldt_free_fs( free_teb->teb_sel );
ptr = free_teb->stack_base;
ptr = free_teb->DeallocationStack;
NtFreeVirtualMemory( GetCurrentProcess(), &ptr, &size, MEM_RELEASE );
}
SIGNAL_Block();
@ -290,10 +291,10 @@ void SYSDEPS_ExitThread( int status )
struct thread_cleanup_info info;
MEMORY_BASIC_INFORMATION meminfo;
NtQueryVirtualMemory( GetCurrentProcess(), teb->stack_top, MemoryBasicInformation,
NtQueryVirtualMemory( GetCurrentProcess(), teb->Tib.StackBase, MemoryBasicInformation,
&meminfo, sizeof(meminfo), NULL );
info.stack_base = meminfo.AllocationBase;
info.stack_size = meminfo.RegionSize + ((char *)teb->stack_top - (char *)meminfo.AllocationBase);
info.stack_size = meminfo.RegionSize + ((char *)teb->Tib.StackBase - (char *)meminfo.AllocationBase);
info.status = status;
SIGNAL_Block();
@ -304,8 +305,8 @@ void SYSDEPS_ExitThread( int status )
close( teb->reply_fd );
close( teb->request_fd );
SIGNAL_Reset();
teb->stack_low = get_temp_stack();
teb->stack_top = (char *) teb->stack_low + TEMP_STACK_SIZE;
teb->Tib.StackLimit = get_temp_stack();
teb->Tib.StackBase = (char *)teb->Tib.StackLimit + TEMP_STACK_SIZE;
SYSDEPS_SwitchToThreadStack( cleanup_thread, &info );
#endif
}

View File

@ -53,16 +53,7 @@ struct debug_info
*/
typedef struct _TEB
{
/* start of NT_TIB */
EXCEPTION_REGISTRATION_RECORD *except; /* 12- 00 Head of exception handling chain */
void *stack_top; /* 12- 04 Top of thread stack */
void *stack_low; /* 12- 08 Stack low-water mark */
HTASK16 htask16; /* 1-- 0c Win16 task handle */
WORD stack_sel; /* 1-- 0e 16-bit stack selector */
struct fiber_data *fiber; /* -2- 10 Current fiber data (Win95: selector manager list) */
DWORD user_ptr; /* 12n 14 User pointer */
/* end of NT_TIB */
struct _TEB *self; /* 12- 18 Pointer to this structure */
NT_TIB Tib; /* 12- 00 Thread information block */
WORD tibflags; /* 1!n 1c Flags (NT: EnvironmentPointer) */
WORD mutex_count; /* 1-n 1e Win16 mutex count */
CLIENT_ID ClientId; /* -2- 20 Process and thread id (win95: debug context) */
@ -92,8 +83,8 @@ typedef struct _TEB
WORD current_ss; /* 1-n 7c Another 16-bit stack selector */
WORD pad2; /* --n 7e */
void *ss_table; /* --n 80 Pointer to info about 16-bit stack */
WORD thunk_ss; /* --n 84 Yet another 16-bit stack selector */
WORD pad3; /* --n 86 */
WORD stack_sel; /* --3 84 16-bit stack selector */
HTASK16 htask16; /* --3 86 Win16 task handle */
DWORD pad4[15]; /* --n 88 */
ULONG CurrentLocale; /* -2- C4 */
DWORD pad5[48]; /* --n C8 */

View File

@ -23,6 +23,7 @@
#include <setjmp.h>
#define NONAMELESSUNION
#include "winbase.h"
#include "winerror.h"
#include "wine/exception.h"
@ -30,14 +31,14 @@
struct fiber_data
{
LPVOID param; /* 00 fiber param */
void *except; /* 04 saved exception handlers list */
void *stack_top; /* 08 top of fiber stack */
void *stack_low; /* 0c fiber stack low-water mark */
void *stack_base; /* 10 base of the fiber stack */
jmp_buf jmpbuf; /* 14 setjmp buffer (on Windows: CONTEXT) */
DWORD flags; /* fiber flags */
LPFIBER_START_ROUTINE start; /* start routine */
LPVOID param; /* 00 fiber param */
void *except; /* 04 saved exception handlers list */
void *stack_base; /* 08 top of fiber stack */
void *stack_limit; /* 0c fiber stack low-water mark */
void *stack_allocation; /* 10 base of the fiber stack allocation */
jmp_buf jmpbuf; /* 14 setjmp buffer (on Windows: CONTEXT) */
DWORD flags; /* fiber flags */
LPFIBER_START_ROUTINE start; /* start routine */
};
@ -86,17 +87,17 @@ LPVOID WINAPI CreateFiberEx( SIZE_T stack_commit, SIZE_T stack_reserve, DWORD fl
/* FIXME: should use the thread stack allocation routines here */
if (!stack_reserve) stack_reserve = 1024*1024;
if(!(fiber->stack_base = VirtualAlloc( 0, stack_reserve, MEM_COMMIT, PAGE_EXECUTE_READWRITE )))
if(!(fiber->stack_allocation = VirtualAlloc( 0, stack_reserve, MEM_COMMIT, PAGE_EXECUTE_READWRITE )))
{
HeapFree( GetProcessHeap(), 0, fiber );
return NULL;
}
fiber->stack_top = (char *)fiber->stack_base + stack_reserve;
fiber->stack_low = fiber->stack_base;
fiber->param = param;
fiber->except = (void *)-1;
fiber->start = start;
fiber->flags = flags;
fiber->stack_base = (char *)fiber->stack_allocation + stack_reserve;
fiber->stack_limit = fiber->stack_allocation;
fiber->param = param;
fiber->except = (void *)-1;
fiber->start = start;
fiber->flags = flags;
return fiber;
}
@ -109,12 +110,12 @@ void WINAPI DeleteFiber( LPVOID fiber_ptr )
struct fiber_data *fiber = fiber_ptr;
if (!fiber) return;
if (fiber == NtCurrentTeb()->fiber)
if (fiber == NtCurrentTeb()->Tib.u.FiberData)
{
HeapFree( GetProcessHeap(), 0, fiber );
ExitThread(1);
}
VirtualFree( fiber->stack_base, 0, MEM_RELEASE );
VirtualFree( fiber->stack_allocation, 0, MEM_RELEASE );
HeapFree( GetProcessHeap(), 0, fiber );
}
@ -140,14 +141,14 @@ LPVOID WINAPI ConvertThreadToFiberEx( LPVOID param, DWORD flags )
SetLastError( ERROR_NOT_ENOUGH_MEMORY );
return NULL;
}
fiber->param = param;
fiber->except = NtCurrentTeb()->except;
fiber->stack_top = NtCurrentTeb()->stack_top;
fiber->stack_low = NtCurrentTeb()->stack_low;
fiber->stack_base = NtCurrentTeb()->DeallocationStack;
fiber->start = NULL;
fiber->flags = flags;
NtCurrentTeb()->fiber = fiber;
fiber->param = param;
fiber->except = NtCurrentTeb()->Tib.ExceptionList;
fiber->stack_base = NtCurrentTeb()->Tib.StackBase;
fiber->stack_limit = NtCurrentTeb()->Tib.StackLimit;
fiber->stack_allocation = NtCurrentTeb()->DeallocationStack;
fiber->start = NULL;
fiber->flags = flags;
NtCurrentTeb()->Tib.u.FiberData = fiber;
return fiber;
}
@ -157,11 +158,11 @@ LPVOID WINAPI ConvertThreadToFiberEx( LPVOID param, DWORD flags )
*/
BOOL WINAPI ConvertFiberToThread(void)
{
struct fiber_data *fiber = NtCurrentTeb()->fiber;
struct fiber_data *fiber = NtCurrentTeb()->Tib.u.FiberData;
if (fiber)
{
NtCurrentTeb()->fiber = NULL;
NtCurrentTeb()->Tib.u.FiberData = NULL;
HeapFree( GetProcessHeap(), 0, fiber );
}
return TRUE;
@ -174,20 +175,20 @@ BOOL WINAPI ConvertFiberToThread(void)
void WINAPI SwitchToFiber( LPVOID fiber )
{
struct fiber_data *new_fiber = fiber;
struct fiber_data *current_fiber = NtCurrentTeb()->fiber;
struct fiber_data *current_fiber = NtCurrentTeb()->Tib.u.FiberData;
current_fiber->except = NtCurrentTeb()->except;
current_fiber->stack_low = NtCurrentTeb()->stack_low;
/* stack_base and stack_top never change */
current_fiber->except = NtCurrentTeb()->Tib.ExceptionList;
current_fiber->stack_limit = NtCurrentTeb()->Tib.StackLimit;
/* stack_allocation and stack_base never change */
/* FIXME: should save floating point context if requested in fiber->flags */
if (!setjmp( current_fiber->jmpbuf ))
{
NtCurrentTeb()->fiber = new_fiber;
NtCurrentTeb()->except = new_fiber->except;
NtCurrentTeb()->stack_top = new_fiber->stack_top;
NtCurrentTeb()->stack_low = new_fiber->stack_low;
NtCurrentTeb()->DeallocationStack = new_fiber->stack_base;
NtCurrentTeb()->Tib.u.FiberData = new_fiber;
NtCurrentTeb()->Tib.ExceptionList = new_fiber->except;
NtCurrentTeb()->Tib.StackBase = new_fiber->stack_base;
NtCurrentTeb()->Tib.StackLimit = new_fiber->stack_limit;
NtCurrentTeb()->DeallocationStack = new_fiber->stack_allocation;
if (new_fiber->start) /* first time */
SYSDEPS_SwitchToThreadStack( start_fiber, new_fiber );
else

View File

@ -58,15 +58,15 @@ extern struct _PDB current_process;
*/
static BOOL THREAD_InitTEB( TEB *teb )
{
teb->except = (void *)~0UL;
teb->self = teb;
teb->Tib.ExceptionList = (void *)~0UL;
teb->Tib.StackBase = (void *)~0UL;
teb->Tib.Self = &teb->Tib;
teb->tibflags = TEBF_WIN32;
teb->exit_code = STILL_ACTIVE;
teb->request_fd = -1;
teb->reply_fd = -1;
teb->wait_fd[0] = -1;
teb->wait_fd[1] = -1;
teb->stack_top = (void *)~0UL;
teb->StaticUnicodeString.MaximumLength = sizeof(teb->StaticUnicodeBuffer);
teb->StaticUnicodeString.Buffer = (PWSTR)teb->StaticUnicodeBuffer;
teb->teb_sel = wine_ldt_alloc_fs();
@ -111,7 +111,7 @@ TEB *THREAD_InitStack( TEB *teb, DWORD stack_size )
if (teb)
stack_size = 1024 * 1024; /* no parent */
else
stack_size = ((char *)NtCurrentTeb()->stack_top - (char *)NtCurrentTeb()->DeallocationStack
stack_size = ((char *)NtCurrentTeb()->Tib.StackBase - (char *)NtCurrentTeb()->DeallocationStack
- SIGNAL_STACK_SIZE - 3 * page_size);
}
@ -146,10 +146,10 @@ TEB *THREAD_InitStack( TEB *teb, DWORD stack_size )
}
}
teb->stack_low = base;
teb->DeallocationStack = base;
teb->signal_stack = (char *)base + page_size;
teb->stack_top = (char *)base + 3 * page_size + SIGNAL_STACK_SIZE + stack_size;
teb->Tib.StackBase = (char *)base + 3 * page_size + SIGNAL_STACK_SIZE + stack_size;
teb->Tib.StackLimit = base; /* note: limit is lower than base since the stack grows down */
/* Setup guard pages */
@ -172,7 +172,7 @@ void THREAD_Init(void)
{
static struct debug_info info; /* debug info for initial thread */
if (!initial_teb.self) /* do it only once */
if (!initial_teb.Tib.Self) /* do it only once */
{
THREAD_InitTEB( &initial_teb );
assert( initial_teb.teb_sel );

View File

@ -486,15 +486,15 @@ static void BuildCallTo16Core( FILE *outfile, int reg_func )
/* Setup exception frame */
fprintf( outfile, "\t.byte 0x64\n\tpushl (%d)\n", STACKOFFSET );
fprintf( outfile, "\tpushl 16(%%ebp)\n" ); /* handler */
fprintf( outfile, "\t.byte 0x64\n\tpushl (%d)\n", STRUCTOFFSET(TEB,except) );
fprintf( outfile, "\t.byte 0x64\n\tmovl %%esp,(%d)\n", STRUCTOFFSET(TEB,except) );
fprintf( outfile, "\t.byte 0x64\n\tpushl (%d)\n", STRUCTOFFSET(TEB,Tib.ExceptionList) );
fprintf( outfile, "\t.byte 0x64\n\tmovl %%esp,(%d)\n", STRUCTOFFSET(TEB,Tib.ExceptionList) );
/* Call the actual CallTo16 routine (simulate a lcall) */
fprintf( outfile, "\tpushl %%cs\n" );
fprintf( outfile, "\tcall .L%s\n", name );
/* Remove exception frame */
fprintf( outfile, "\t.byte 0x64\n\tpopl (%d)\n", STRUCTOFFSET(TEB,except) );
fprintf( outfile, "\t.byte 0x64\n\tpopl (%d)\n", STRUCTOFFSET(TEB,Tib.ExceptionList) );
fprintf( outfile, "\taddl $4, %%esp\n" );
fprintf( outfile, "\t.byte 0x64\n\tpopl (%d)\n", STACKOFFSET );