From 897ac569c84d9be42e0b4bbd718a3eb05663e4d9 Mon Sep 17 00:00:00 2001
From: Sebastian Lackner <sebastian@fds-team.de>
Date: Sat, 2 Jan 2016 04:40:46 +0100
Subject: [PATCH] ntdll: Check ContextFlags before restoring registers on
 x86_64.

Signed-off-by: Sebastian Lackner <sebastian@fds-team.de>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
---
 dlls/ntdll/signal_x86_64.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/dlls/ntdll/signal_x86_64.c b/dlls/ntdll/signal_x86_64.c
index 524de68954b..0c645414daf 100644
--- a/dlls/ntdll/signal_x86_64.c
+++ b/dlls/ntdll/signal_x86_64.c
@@ -1800,11 +1800,12 @@ __ASM_GLOBAL_FUNC( RtlCaptureContext,
                    "ret" );
 
 /***********************************************************************
- *           set_cpu_context
+ *           set_full_cpu_context
  *
  * Set the new CPU context.
  */
-__ASM_GLOBAL_FUNC( set_cpu_context,
+extern void set_full_cpu_context( const CONTEXT *context );
+__ASM_GLOBAL_FUNC( set_full_cpu_context,
                    "subq $40,%rsp\n\t"
                    __ASM_CFI(".cfi_adjust_cfa_offset 40\n\t")
                    "ldmxcsr 0x34(%rdi)\n\t"         /* context->MxCsr */
@@ -1852,6 +1853,25 @@ __ASM_GLOBAL_FUNC( set_cpu_context,
                    "movq 0xb0(%rdi),%rdi\n\t"       /* context->Rdi */
                    "iretq" );
 
+
+/***********************************************************************
+ *           set_cpu_context
+ *
+ * Set the new CPU context. Used by NtSetContextThread.
+ */
+void set_cpu_context( const CONTEXT *context )
+{
+    DWORD flags = context->ContextFlags & ~CONTEXT_AMD64;
+    if (flags & CONTEXT_FULL)
+    {
+        if (!(flags & CONTEXT_CONTROL))
+            FIXME( "setting partial context (%x) not supported\n", flags );
+        else
+            set_full_cpu_context( context );
+    }
+}
+
+
 /***********************************************************************
  *           copy_context
  *