From patchwork Sat Jul 2 07:50:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 102980 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 1E491B6F59 for ; Sat, 2 Jul 2011 17:53:07 +1000 (EST) Received: from localhost ([::1]:58616 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qcv0g-0005Ef-W7 for incoming@patchwork.ozlabs.org; Sat, 02 Jul 2011 03:53:03 -0400 Received: from eggs.gnu.org ([140.186.70.92]:47359) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qcuye-0005EX-S9 for qemu-devel@nongnu.org; Sat, 02 Jul 2011 03:50:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Qcuyd-0005vJ-RY for qemu-devel@nongnu.org; Sat, 02 Jul 2011 03:50:56 -0400 Received: from fmmailgate03.web.de ([217.72.192.234]:47504) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Qcuyd-0005vE-H1 for qemu-devel@nongnu.org; Sat, 02 Jul 2011 03:50:55 -0400 Received: from smtp03.web.de ( [172.20.0.65]) by fmmailgate03.web.de (Postfix) with ESMTP id 3AF9B1931B14A; Sat, 2 Jul 2011 09:50:53 +0200 (CEST) Received: from [88.65.33.44] (helo=mchn199C.mchp.siemens.de) by smtp03.web.de with asmtp (TLSv1:AES256-SHA:256) (WEB.DE 4.110 #2) id 1Qcuyb-00019c-00; Sat, 02 Jul 2011 09:50:53 +0200 Message-ID: <4E0ECDDB.9030001@web.de> Date: Sat, 02 Jul 2011 09:50:51 +0200 From: Jan Kiszka User-Agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666 MIME-Version: 1.0 To: Blue Swirl References: <4E0CA885.2050308@siemens.com> In-Reply-To: X-Enigmail-Version: 1.2 X-Sender: jan.kiszka@web.de X-Provags-ID: V01U2FsdGVkX1/OUvsZc9tYHVj5LL+MoH9eEOH4hy812YcAJXrV rSth9QpAmmwrEeTn850QxHmxreGppwO7ZGF6ITCqXyJfWtWXOq z4v+723Os= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 X-Received-From: 217.72.192.234 Cc: TeLeMan , qemu-devel Subject: [Qemu-devel] [PATCH] tcg: Reload local variables after return from longjmp 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 From: Jan Kiszka Recent compilers look deep into cpu_exec, find longjmp as a noreturn function and decide to smash some stack variables as they won't be used again. This may lead to env becoming invalid after return from setjmp, causing crashes. Fix it by reloading env from cpu_single_env in that case. Signed-off-by: Jan Kiszka --- cpu-exec.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/cpu-exec.c b/cpu-exec.c index 20e3ec4..de0d716 100644 --- a/cpu-exec.c +++ b/cpu-exec.c @@ -587,6 +587,10 @@ int cpu_exec(CPUState *env) /* reset soft MMU for next block (it can currently only be set by a memory fault) */ } /* for(;;) */ + } else { + /* Reload env after longjmp - the compiler may have smashed all + * local variables as longjmp is marked 'noreturn'. */ + env = cpu_single_env; } } /* for(;;) */