qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] thread-win32: fix GetThreadContext() permanently fails
@ 2015-06-22 21:54 Zavadovsky Yan
  2015-06-23  6:02 ` Stefan Weil
  0 siblings, 1 reply; 15+ messages in thread
From: Zavadovsky Yan @ 2015-06-22 21:54 UTC (permalink / raw)
  To: qemu-devel; +Cc: sw, Zavadovsky Yan, pbonzini

Calling SuspendThread() is not enough to suspend Win32 thread.
We need to call GetThreadContext() after SuspendThread()
to make sure that OS have really suspended target thread.
But GetThreadContext() needs for THREAD_GET_CONTEXT
access right on thread object.

This patch adds THREAD_GET_CONTEXT to OpenThread() arguments
and change 'while(GetThreadContext() == SUCCESS)' to
'while(GetThreadContext() == FAILED)'.
So this 'while' loop will stop only after successful grabbing
of thread context(i.e. when thread is really suspended).
Not after the one failed GetThreadContext() call.

Signed-off-by: Zavadovsky Yan <zavadovsky.yan@gmail.com>
---
 cpus.c                   | 2 +-
 util/qemu-thread-win32.c | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/cpus.c b/cpus.c
index b85fb5f..83d5eb5 100644
--- a/cpus.c
+++ b/cpus.c
@@ -1097,7 +1097,7 @@ static void qemu_cpu_kick_thread(CPUState *cpu)
          * suspended until we can get the context.
          */
         tcgContext.ContextFlags = CONTEXT_CONTROL;
-        while (GetThreadContext(cpu->hThread, &tcgContext) != 0) {
+        while (GetThreadContext(cpu->hThread, &tcgContext) == 0) {
             continue;
         }
 
diff --git a/util/qemu-thread-win32.c b/util/qemu-thread-win32.c
index 406b52f..823eca1 100644
--- a/util/qemu-thread-win32.c
+++ b/util/qemu-thread-win32.c
@@ -406,8 +406,8 @@ HANDLE qemu_thread_get_handle(QemuThread *thread)
 
     EnterCriticalSection(&data->cs);
     if (!data->exited) {
-        handle = OpenThread(SYNCHRONIZE | THREAD_SUSPEND_RESUME, FALSE,
-                            thread->tid);
+        handle = OpenThread(SYNCHRONIZE | THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT,
+                            FALSE, thread->tid);
     } else {
         handle = NULL;
     }
-- 
2.4.4.windows.2

^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2015-06-24 10:04 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-06-22 21:54 [Qemu-devel] [PATCH] thread-win32: fix GetThreadContext() permanently fails Zavadovsky Yan
2015-06-23  6:02 ` Stefan Weil
2015-06-23  9:49   ` Fabien Chouteau
2015-06-23 10:11     ` Ян Завадовский
2015-06-23  9:55   ` Ян Завадовский
2015-06-23 10:30     ` Peter Maydell
2015-06-23 10:46       ` Paolo Bonzini
2015-06-23 11:18         ` Daniel P. Berrange
2015-06-23 11:32           ` Paolo Bonzini
2015-06-23 11:43             ` Daniel P. Berrange
2015-06-23 11:52               ` Paolo Bonzini
2015-06-23 11:23         ` Peter Maydell
2015-06-23 17:07         ` Stefan Weil
2015-06-24  9:09           ` Fabien Chouteau
2015-06-24 10:03             ` Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).