From patchwork Mon Jun 22 21:54:15 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zavadovsky Yan X-Patchwork-Id: 487438 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A8A18140081 for ; Tue, 23 Jun 2015 09:50:21 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=WvDtFRAS; dkim-atps=neutral Received: from localhost ([::1]:42558 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7BTm-0000xC-Dv for incoming@patchwork.ozlabs.org; Mon, 22 Jun 2015 19:50:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34357) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z79fx-00035x-5l for qemu-devel@nongnu.org; Mon, 22 Jun 2015 17:54:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z79ft-0007Ye-To for qemu-devel@nongnu.org; Mon, 22 Jun 2015 17:54:45 -0400 Received: from mail-la0-x233.google.com ([2a00:1450:4010:c03::233]:33328) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z79ft-0007X8-Lb for qemu-devel@nongnu.org; Mon, 22 Jun 2015 17:54:41 -0400 Received: by laka10 with SMTP id a10so118389540lak.0 for ; Mon, 22 Jun 2015 14:54:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=k2vFfNRNjhebazixsVIK0uys+/Bl0eEw81Qvf1BfcJg=; b=WvDtFRASHBjjLf2FS6m+eoSepTudF01fFjWc9H2rFN64Qp0rkwKVRjmzOaLLv5IDM2 IeDCsMdM64L/wuQYiji0AXQ4tfPL07FdPjj7OrnJUBKz0l9oeHn95WOeVCVqV0n+zVXc LvT6gYvYBAeSqU0YsXQlBOpke5EKYLB0YJZF+0I4CRaxLTYNi3RNyEhkqkJwFWypHrle 93hiuYfe64OpZLJJyx7aho/JWdQHBjF5D9GTpAQzJZstJRrKiP/FiXNjEOugY8gGcrUH GfZKS5C649yRiw5Z4gNaL83mzFSprP0wJl46QwofjwcXrF4Gs5nUs0td9owFNjR72NOo iRcQ== X-Received: by 10.152.2.2 with SMTP id 2mr32841320laq.58.1435010079979; Mon, 22 Jun 2015 14:54:39 -0700 (PDT) Received: from localhost.localdomain ([91.151.189.65]) by mx.google.com with ESMTPSA id 4sm4985593lai.36.2015.06.22.14.54.38 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 22 Jun 2015 14:54:39 -0700 (PDT) From: Zavadovsky Yan To: qemu-devel@nongnu.org Date: Tue, 23 Jun 2015 00:54:15 +0300 Message-Id: <1435010055-4584-1-git-send-email-zavadovsky.yan@gmail.com> X-Mailer: git-send-email 2.4.4.windows.2 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::233 X-Mailman-Approved-At: Mon, 22 Jun 2015 19:46:28 -0400 Cc: sw@weilnetz.de, Zavadovsky Yan , pbonzini@redhat.com Subject: [Qemu-devel] [PATCH] thread-win32: fix GetThreadContext() permanently fails X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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; }