Alexandre Julliard : ntdll: Move the TEB register to the ntdll_thread_regs structure.

Alexandre Julliard julliard at wine.codeweavers.com
Fri Jan 20 13:20:23 CST 2006


Module: wine
Branch: refs/heads/master
Commit: a19e3eeb20fb3295f49352ad28a2e34c3a01dd92
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=a19e3eeb20fb3295f49352ad28a2e34c3a01dd92

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Fri Jan 20 16:18:06 2006 +0100

ntdll: Move the TEB register to the ntdll_thread_regs structure.

---

 dlls/ntdll/ntdll_misc.h  |    6 +++---
 dlls/ntdll/signal_i386.c |    4 ++--
 dlls/ntdll/thread.c      |   30 ++++++++++++++++++++----------
 3 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h
index c63b700..992df1d 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -119,14 +119,13 @@ struct debug_info
 
 struct ntdll_thread_data
 {
-    DWORD              teb_sel;       /* selector to TEB */
     struct debug_info *debug_info;    /* info for debugstr functions */
     int                request_fd;    /* fd for sending server requests */
     int                reply_fd;      /* fd for receiving server replies */
     int                wait_fd[2];    /* fd for sleeping server requests */
     void              *vm86_ptr;      /* data for vm86 mode */
 
-    void              *pad[3];        /* change this if you add fields! */
+    void              *pad[4];        /* change this if you add fields! */
 };
 
 static inline struct ntdll_thread_data *ntdll_get_thread_data(void)
@@ -137,13 +136,14 @@ static inline struct ntdll_thread_data *
 /* thread registers, stored in NtCurrentTeb()->SpareBytes1 */
 struct ntdll_thread_regs
 {
+    DWORD              fs;            /* TEB selector */
     DWORD              dr0;           /* debug registers */
     DWORD              dr1;
     DWORD              dr2;
     DWORD              dr3;
     DWORD              dr6;
     DWORD              dr7;
-    DWORD              spare[4];      /* change this if you add fields! */
+    DWORD              spare[3];      /* change this if you add fields! */
 };
 
 static inline struct ntdll_thread_regs *ntdll_get_thread_regs(void)
diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c
index 1b2e8f0..11e9dc9 100644
--- a/dlls/ntdll/signal_i386.c
+++ b/dlls/ntdll/signal_i386.c
@@ -648,7 +648,7 @@ inline static void *init_handler( const 
 {
     void *stack = (void *)ESP_sig(sigcontext);
     TEB *teb = get_current_teb();
-    struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
+    struct ntdll_thread_regs *thread_regs = (struct ntdll_thread_regs *)teb->SpareBytes1;
 
     /* get %fs and %gs at time of the fault */
 #ifdef FS_sig
@@ -662,7 +662,7 @@ inline static void *init_handler( const 
     *gs = wine_get_gs();
 #endif
 
-    wine_set_fs( thread_data->teb_sel );
+    wine_set_fs( thread_regs->fs );
 
     /* now restore a proper %gs for the fault handler */
     if (!wine_ldt_is_system(CS_sig(sigcontext)) ||
diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c
index d189bf7..760f849 100644
--- a/dlls/ntdll/thread.c
+++ b/dlls/ntdll/thread.c
@@ -67,6 +67,7 @@ struct wine_pthread_functions pthread_fu
 static inline NTSTATUS init_teb( TEB *teb )
 {
     struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
+    struct ntdll_thread_regs *thread_regs = (struct ntdll_thread_regs *)teb->SpareBytes1;
 
     teb->Tib.ExceptionList = (void *)~0UL;
     teb->Tib.StackBase     = (void *)~0UL;
@@ -75,7 +76,7 @@ static inline NTSTATUS init_teb( TEB *te
     teb->StaticUnicodeString.Buffer        = teb->StaticUnicodeBuffer;
     teb->StaticUnicodeString.MaximumLength = sizeof(teb->StaticUnicodeBuffer);
 
-    if (!(thread_data->teb_sel = wine_ldt_alloc_fs())) return STATUS_TOO_MANY_THREADS;
+    if (!(thread_regs->fs = wine_ldt_alloc_fs())) return STATUS_TOO_MANY_THREADS;
     thread_data->request_fd = -1;
     thread_data->reply_fd   = -1;
     thread_data->wait_fd[0] = -1;
@@ -92,10 +93,10 @@ static inline void free_teb( TEB *teb )
 {
     SIZE_T size = 0;
     void *addr = teb;
-    struct ntdll_thread_data *thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
+    struct ntdll_thread_regs *thread_regs = (struct ntdll_thread_regs *)teb->SpareBytes1;
 
     NtFreeVirtualMemory( NtCurrentProcess(), &addr, &size, MEM_RELEASE );
-    wine_ldt_free_fs( thread_data->teb_sel );
+    wine_ldt_free_fs( thread_regs->fs );
     munmap( teb, sigstack_total_size );
 }
 
@@ -113,6 +114,7 @@ void thread_init(void)
     void *addr;
     SIZE_T info_size;
     struct ntdll_thread_data *thread_data;
+    struct ntdll_thread_regs *thread_regs;
     struct wine_pthread_thread_info thread_info;
     static struct debug_info debug_info;  /* debug info for initial thread */
 
@@ -138,13 +140,14 @@ void thread_init(void)
     teb = addr;
     init_teb( teb );
     thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
+    thread_regs = (struct ntdll_thread_regs *)teb->SpareBytes1;
     thread_data->debug_info = &debug_info;
     InsertHeadList( &tls_links, &teb->TlsLinks );
 
     thread_info.stack_base = NULL;
     thread_info.stack_size = 0;
     thread_info.teb_base   = teb;
-    thread_info.teb_sel    = thread_data->teb_sel;
+    thread_info.teb_sel    = thread_regs->fs;
     wine_pthread_get_functions( &pthread_functions, sizeof(pthread_functions) );
     pthread_functions.init_current_teb( &thread_info );
     pthread_functions.init_thread( &thread_info );
@@ -243,7 +246,8 @@ NTSTATUS WINAPI RtlCreateUserThread( HAN
                                      PRTL_THREAD_START_ROUTINE start, void *param,
                                      HANDLE *handle_ptr, CLIENT_ID *id )
 {
-    struct ntdll_thread_data *thread_data = NULL;
+    struct ntdll_thread_data *thread_data;
+    struct ntdll_thread_regs *thread_regs = NULL;
     struct startup_info *info = NULL;
     void *addr;
     HANDLE handle = 0;
@@ -294,14 +298,20 @@ NTSTATUS WINAPI RtlCreateUserThread( HAN
     teb->ClientId.UniqueProcess = (HANDLE)GetCurrentProcessId();
     teb->ClientId.UniqueThread  = (HANDLE)tid;
 
-    /* inherit registers from parent thread */
-    memcpy( teb->SpareBytes1, ntdll_get_thread_regs(), sizeof(teb->SpareBytes1) );
-
     thread_data = (struct ntdll_thread_data *)teb->SystemReserved2;
+    thread_regs = (struct ntdll_thread_regs *)teb->SpareBytes1;
     thread_data->request_fd  = request_pipe[1];
 
     info->pthread_info.teb_base = teb;
-    info->pthread_info.teb_sel  = thread_data->teb_sel;
+    info->pthread_info.teb_sel  = thread_regs->fs;
+
+    /* inherit debug registers from parent thread */
+    thread_regs->dr0 = ntdll_get_thread_regs()->dr0;
+    thread_regs->dr1 = ntdll_get_thread_regs()->dr1;
+    thread_regs->dr2 = ntdll_get_thread_regs()->dr2;
+    thread_regs->dr3 = ntdll_get_thread_regs()->dr3;
+    thread_regs->dr6 = ntdll_get_thread_regs()->dr6;
+    thread_regs->dr7 = ntdll_get_thread_regs()->dr7;
 
     if (!stack_reserve || !stack_commit)
     {
@@ -333,7 +343,7 @@ NTSTATUS WINAPI RtlCreateUserThread( HAN
     return STATUS_SUCCESS;
 
 error:
-    if (thread_data) wine_ldt_free_fs( thread_data->teb_sel );
+    if (thread_regs) wine_ldt_free_fs( thread_regs->fs );
     if (addr)
     {
         SIZE_T size = 0;




More information about the wine-cvs mailing list