Alexandre Julliard : ntdll: Move NtSetContextThread implementation to the platform-specific files.

Alexandre Julliard julliard at winehq.org
Tue Jul 18 13:58:54 CDT 2017


Module: wine
Branch: master
Commit: 675e8218f0cdc3dbc30e2829d481d6591aebf67c
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=675e8218f0cdc3dbc30e2829d481d6591aebf67c

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Jul 18 11:08:37 2017 +0200

ntdll: Move NtSetContextThread implementation to the platform-specific files.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/ntdll/ntdll_misc.h     |  2 +-
 dlls/ntdll/signal_arm.c     | 16 ++++++++++++++++
 dlls/ntdll/signal_arm64.c   | 17 ++++++++++++++++-
 dlls/ntdll/signal_i386.c    | 27 ++++++++++++++++++++++++++-
 dlls/ntdll/signal_powerpc.c | 17 ++++++++++++++++-
 dlls/ntdll/signal_x86_64.c  | 19 +++++++++++++++++--
 dlls/ntdll/thread.c         | 38 +-------------------------------------
 7 files changed, 93 insertions(+), 43 deletions(-)

diff --git a/dlls/ntdll/ntdll_misc.h b/dlls/ntdll/ntdll_misc.h
index 5e4c39e..ee82cea 100644
--- a/dlls/ntdll/ntdll_misc.h
+++ b/dlls/ntdll/ntdll_misc.h
@@ -53,10 +53,10 @@ extern void wait_suspend( CONTEXT *context ) DECLSPEC_HIDDEN;
 extern NTSTATUS send_debug_event( EXCEPTION_RECORD *rec, int first_chance, CONTEXT *context ) DECLSPEC_HIDDEN;
 extern LONG call_vectored_handlers( EXCEPTION_RECORD *rec, CONTEXT *context ) DECLSPEC_HIDDEN;
 extern void raise_status( NTSTATUS status, EXCEPTION_RECORD *rec ) DECLSPEC_NORETURN DECLSPEC_HIDDEN;
-extern void set_cpu_context( const CONTEXT *context ) DECLSPEC_HIDDEN;
 extern void copy_context( CONTEXT *to, const CONTEXT *from, DWORD flags ) DECLSPEC_HIDDEN;
 extern NTSTATUS context_to_server( context_t *to, const CONTEXT *from ) DECLSPEC_HIDDEN;
 extern NTSTATUS context_from_server( CONTEXT *to, const context_t *from ) DECLSPEC_HIDDEN;
+extern NTSTATUS set_thread_context( HANDLE handle, const CONTEXT *context, BOOL *self ) DECLSPEC_HIDDEN;
 extern void call_thread_entry_point( LPTHREAD_START_ROUTINE entry, void *arg ) DECLSPEC_NORETURN DECLSPEC_HIDDEN;
 
 /* debug helpers */
diff --git a/dlls/ntdll/signal_arm.c b/dlls/ntdll/signal_arm.c
index cb5f67d..7210c8e 100644
--- a/dlls/ntdll/signal_arm.c
+++ b/dlls/ntdll/signal_arm.c
@@ -294,6 +294,7 @@ __ASM_STDCALL_FUNC( RtlCaptureContext, 4,
  * Set the new CPU context.
  */
 /* FIXME: What about the CPSR? */
+void set_cpu_context( const CONTEXT *context );
 __ASM_GLOBAL_FUNC( set_cpu_context,
                    "mov IP, r0\n\t"
                    "ldr r0,  [IP, #0x4]\n\t"  /* context->R0 */
@@ -427,6 +428,21 @@ NTSTATUS context_from_server( CONTEXT *to, const context_t *from )
     return STATUS_SUCCESS;
 }
 
+/***********************************************************************
+ *              NtSetContextThread  (NTDLL.@)
+ *              ZwSetContextThread  (NTDLL.@)
+ */
+NTSTATUS WINAPI NtSetContextThread( HANDLE handle, const CONTEXT *context )
+{
+    NTSTATUS ret;
+    BOOL self;
+
+    ret = set_thread_context( handle, context, &self );
+    if (self && ret == STATUS_SUCCESS) set_cpu_context( context );
+    return ret;
+}
+
+
 extern void raise_func_trampoline_thumb( EXCEPTION_RECORD *rec, CONTEXT *context, raise_func func );
 __ASM_GLOBAL_FUNC( raise_func_trampoline_thumb,
                    ".thumb\n\t"
diff --git a/dlls/ntdll/signal_arm64.c b/dlls/ntdll/signal_arm64.c
index ca169a1..77fc8dc 100644
--- a/dlls/ntdll/signal_arm64.c
+++ b/dlls/ntdll/signal_arm64.c
@@ -231,7 +231,7 @@ __ASM_STDCALL_FUNC( RtlCaptureContext, 8,
  *
  * Set the new CPU context.
  */
-void set_cpu_context( const CONTEXT *context )
+static void set_cpu_context( const CONTEXT *context )
 {
     FIXME( "Not implemented on ARM64\n" );
 }
@@ -331,6 +331,21 @@ NTSTATUS context_from_server( CONTEXT *to, const context_t *from )
 }
 
 /***********************************************************************
+ *              NtSetContextThread  (NTDLL.@)
+ *              ZwSetContextThread  (NTDLL.@)
+ */
+NTSTATUS WINAPI NtSetContextThread( HANDLE handle, const CONTEXT *context )
+{
+    NTSTATUS ret;
+    BOOL self;
+
+    ret = set_thread_context( handle, context, &self );
+    if (self && ret == STATUS_SUCCESS) set_cpu_context( context );
+    return ret;
+}
+
+
+/***********************************************************************
  *           setup_exception_record
  *
  * Setup the exception record and context on the thread stack.
diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c
index d9a0dec..ffb1318 100644
--- a/dlls/ntdll/signal_i386.c
+++ b/dlls/ntdll/signal_i386.c
@@ -1230,7 +1230,7 @@ __ASM_STDCALL_FUNC( RtlCaptureContext, 4,
  *
  * Set the new CPU context. Used by NtSetContextThread.
  */
-void set_cpu_context( const CONTEXT *context )
+static void set_cpu_context( const CONTEXT *context )
 {
     DWORD flags = context->ContextFlags & ~CONTEXT_i386;
 
@@ -1461,6 +1461,31 @@ NTSTATUS context_from_server( CONTEXT *to, const context_t *from )
 
 
 /***********************************************************************
+ *              NtSetContextThread  (NTDLL.@)
+ *              ZwSetContextThread  (NTDLL.@)
+ */
+NTSTATUS WINAPI NtSetContextThread( HANDLE handle, const CONTEXT *context )
+{
+    NTSTATUS ret = STATUS_SUCCESS;
+    BOOL self = (handle == GetCurrentThread());
+
+    /* debug registers require a server call */
+    if (self && (context->ContextFlags & (CONTEXT_DEBUG_REGISTERS & ~CONTEXT_i386)))
+        self = (ntdll_get_thread_data()->dr0 == context->Dr0 &&
+                ntdll_get_thread_data()->dr1 == context->Dr1 &&
+                ntdll_get_thread_data()->dr2 == context->Dr2 &&
+                ntdll_get_thread_data()->dr3 == context->Dr3 &&
+                ntdll_get_thread_data()->dr6 == context->Dr6 &&
+                ntdll_get_thread_data()->dr7 == context->Dr7);
+
+    if (!self) ret = set_thread_context( handle, context, &self );
+
+    if (self && ret == STATUS_SUCCESS) set_cpu_context( context );
+    return ret;
+}
+
+
+/***********************************************************************
  *           is_privileged_instr
  *
  * Check if the fault location is a privileged instruction.
diff --git a/dlls/ntdll/signal_powerpc.c b/dlls/ntdll/signal_powerpc.c
index 507490a..e44f0b4 100644
--- a/dlls/ntdll/signal_powerpc.c
+++ b/dlls/ntdll/signal_powerpc.c
@@ -267,7 +267,7 @@ void WINAPI RtlCaptureContext( CONTEXT *context )
  *
  * Set the new CPU context.
  */
-void set_cpu_context( const CONTEXT *context )
+static void set_cpu_context( const CONTEXT *context )
 {
     FIXME("not implemented\n");
 }
@@ -568,6 +568,21 @@ NTSTATUS context_from_server( CONTEXT *to, const context_t *from )
 }
 
 
+/***********************************************************************
+ *              NtSetContextThread  (NTDLL.@)
+ *              ZwSetContextThread  (NTDLL.@)
+ */
+NTSTATUS WINAPI NtSetContextThread( HANDLE handle, const CONTEXT *context )
+{
+    NTSTATUS ret;
+    BOOL self;
+
+    ret = set_thread_context( handle, context, &self );
+    if (self && ret == STATUS_SUCCESS) set_cpu_context( context );
+    return ret;
+}
+
+
 /**********************************************************************
  *           call_stack_handlers
  *
diff --git a/dlls/ntdll/signal_x86_64.c b/dlls/ntdll/signal_x86_64.c
index 86034c0..61d95eb 100644
--- a/dlls/ntdll/signal_x86_64.c
+++ b/dlls/ntdll/signal_x86_64.c
@@ -1858,7 +1858,7 @@ __ASM_GLOBAL_FUNC( set_full_cpu_context,
  *
  * Set the new CPU context. Used by NtSetContextThread.
  */
-void set_cpu_context( const CONTEXT *context )
+static void set_cpu_context( const CONTEXT *context )
 {
     DWORD flags = context->ContextFlags & ~CONTEXT_AMD64;
     if (flags & CONTEXT_FULL)
@@ -2063,6 +2063,21 @@ NTSTATUS context_from_server( CONTEXT *to, const context_t *from )
 }
 
 
+/***********************************************************************
+ *              NtSetContextThread  (NTDLL.@)
+ *              ZwSetContextThread  (NTDLL.@)
+ */
+NTSTATUS WINAPI NtSetContextThread( HANDLE handle, const CONTEXT *context )
+{
+    NTSTATUS ret;
+    BOOL self;
+
+    ret = set_thread_context( handle, context, &self );
+    if (self && ret == STATUS_SUCCESS) set_cpu_context( context );
+    return ret;
+}
+
+
 extern void raise_func_trampoline( EXCEPTION_RECORD *rec, CONTEXT *context, raise_func func );
 __ASM_GLOBAL_FUNC( raise_func_trampoline,
                    __ASM_CFI(".cfi_signal_frame\n\t")
@@ -3929,7 +3944,7 @@ __ASM_GLOBAL_FUNC( RtlRaiseException,
                    "movq %rcx,0x80(%rdx)\n\t"   /* context->Rcx */
                    "call " __ASM_NAME("__regs_RtlRaiseException") "\n\t"
                    "leaq 0x20(%rsp),%rdi\n\t"   /* context pointer */
-                   "call " __ASM_NAME("set_cpu_context") /* does not return */ );
+                   "call " __ASM_NAME("set_full_cpu_context") /* does not return */ );
 
 
 /*************************************************************************
diff --git a/dlls/ntdll/thread.c b/dlls/ntdll/thread.c
index 4e1a060..1caa1a3 100644
--- a/dlls/ntdll/thread.c
+++ b/dlls/ntdll/thread.c
@@ -771,7 +771,7 @@ NTSTATUS WINAPI NtQueueApcThread( HANDLE handle, PNTAPCFUNC func, ULONG_PTR arg1
 /***********************************************************************
  *              set_thread_context
  */
-static NTSTATUS set_thread_context( HANDLE handle, const CONTEXT *context, BOOL *self )
+NTSTATUS set_thread_context( HANDLE handle, const CONTEXT *context, BOOL *self )
 {
     NTSTATUS ret;
     DWORD dummy, i;
@@ -817,42 +817,6 @@ static NTSTATUS set_thread_context( HANDLE handle, const CONTEXT *context, BOOL
 }
 
 
-/***********************************************************************
- *              NtSetContextThread  (NTDLL.@)
- *              ZwSetContextThread  (NTDLL.@)
- */
-NTSTATUS WINAPI NtSetContextThread( HANDLE handle, const CONTEXT *context )
-{
-    NTSTATUS ret;
-    BOOL self;
-
-#ifdef __i386__
-    /* on i386 debug registers always require a server call */
-    self = (handle == GetCurrentThread());
-    if (self && (context->ContextFlags & (CONTEXT_DEBUG_REGISTERS & ~CONTEXT_i386)))
-    {
-        self = (ntdll_get_thread_data()->dr0 == context->Dr0 &&
-                ntdll_get_thread_data()->dr1 == context->Dr1 &&
-                ntdll_get_thread_data()->dr2 == context->Dr2 &&
-                ntdll_get_thread_data()->dr3 == context->Dr3 &&
-                ntdll_get_thread_data()->dr6 == context->Dr6 &&
-                ntdll_get_thread_data()->dr7 == context->Dr7);
-    }
-#else
-    self = FALSE;
-#endif
-
-    if (!self)
-    {
-        ret = set_thread_context( handle, context, &self );
-        if (ret) return ret;
-    }
-
-    if (self) set_cpu_context( context );
-    return STATUS_SUCCESS;
-}
-
-
 /* convert CPU-specific flags to generic server flags */
 static inline unsigned int get_server_context_flags( DWORD flags )
 {




More information about the wine-cvs mailing list