From 2e30f6ffa314634d21f5474e128138db45b4c9b9 Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Sun, 11 Oct 1998 18:59:11 +0000 Subject: [PATCH] Use emergency TEB selector to avoid debugger crashes when stepping through relay stubs (or when FS is invalid otherwise). --- include/sig_context.h | 6 ++++-- include/syslevel.h | 1 + scheduler/process.c | 4 ++++ scheduler/syslevel.c | 3 +++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/include/sig_context.h b/include/sig_context.h index 315564f47f4..ad9d192d9b7 100644 --- a/include/sig_context.h +++ b/include/sig_context.h @@ -219,8 +219,10 @@ typedef struct _CONTEXT /* Note 1 */ #ifdef FS_sig #include "syslevel.h" #define HANDLER_INIT() \ - SET_FS(IS_SELECTOR_SYSTEM(CS_sig(HANDLER_CONTEXT)) ? \ - FS_sig(HANDLER_CONTEXT) : SYSLEVEL_Win16CurrentTeb) + do { int fs = IS_SELECTOR_SYSTEM(CS_sig(HANDLER_CONTEXT)) ? \ + FS_sig(HANDLER_CONTEXT) : SYSLEVEL_Win16CurrentTeb; \ + if (!fs) fs = SYSLEVEL_EmergencyTeb; \ + SET_FS(fs); } while (0) #else #define HANDLER_INIT() /* nothing */ #endif diff --git a/include/syslevel.h b/include/syslevel.h index e1510758ea4..d2756dc3d97 100644 --- a/include/syslevel.h +++ b/include/syslevel.h @@ -11,6 +11,7 @@ #include "winbase.h" extern WORD SYSLEVEL_Win16CurrentTeb; +extern WORD SYSLEVEL_EmergencyTeb; void SYSLEVEL_Init(void); VOID SYSLEVEL_EnterWin16Lock(VOID); diff --git a/scheduler/process.c b/scheduler/process.c index 4ffcd1ff559..c9fa851affd 100644 --- a/scheduler/process.c +++ b/scheduler/process.c @@ -15,6 +15,7 @@ #include "heap.h" #include "task.h" #include "ldt.h" +#include "syslevel.h" #include "thread.h" #include "winerror.h" #include "pe_image.h" @@ -237,6 +238,9 @@ BOOL32 PROCESS_Init(void) if (!(thdb = THREAD_Create( pdb, 0, FALSE, NULL, NULL, NULL, NULL ))) return FALSE; thdb->unix_pid = getpid(); + /* Remember TEB selector of initial process for emergency use */ + SYSLEVEL_EmergencyTeb = thdb->teb_sel; + /* Create the environment DB of the first process */ if (!PROCESS_BuildEnvDB( pdb )) return FALSE; diff --git a/scheduler/syslevel.c b/scheduler/syslevel.c index f362f6cb59a..1b0aa0b5a27 100644 --- a/scheduler/syslevel.c +++ b/scheduler/syslevel.c @@ -16,6 +16,9 @@ static SEGPTR segpWin16Mutex; /* Global variable to save current TEB while in 16-bit code */ WORD SYSLEVEL_Win16CurrentTeb = 0; +/* TEB of initial process for emergency use */ +WORD SYSLEVEL_EmergencyTeb = 0; + /************************************************************************ * SYSLEVEL_Init