From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:49824) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QrUYp-0008Kc-SB for qemu-devel@nongnu.org; Thu, 11 Aug 2011 08:40:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QrUYm-0000yA-7S for qemu-devel@nongnu.org; Thu, 11 Aug 2011 08:40:31 -0400 Received: from mail-yx0-f173.google.com ([209.85.213.173]:45024) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QrUYm-0000y0-52 for qemu-devel@nongnu.org; Thu, 11 Aug 2011 08:40:28 -0400 Received: by yxt3 with SMTP id 3so1530969yxt.4 for ; Thu, 11 Aug 2011 05:40:27 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <4E43C80B.1050300@redhat.com> References: <4E0CA885.2050308@siemens.com> <4E0ECDDB.9030001@web.de> <4E43C80B.1050300@redhat.com> Date: Thu, 11 Aug 2011 13:40:27 +0100 Message-ID: From: Peter Maydell Content-Type: text/plain; charset=UTF-8 Subject: Re: [Qemu-devel] [PATCH] tcg: Reload local variables after return from longjmp List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Paolo Bonzini Cc: Blue Swirl , TeLeMan , Jan Kiszka , qemu-devel , David Gilbert On 11 August 2011 13:16, Paolo Bonzini wrote: > On 08/11/2011 01:30 PM, Peter Maydell wrote: >> Can you give more details of what compiler/platform this was >> a problem for? My reading of the C standard is that the compiler >> isn't allowed to trash env across this longjmp, because it's >> a variable of automatic scope which isn't modified between the >> setjmp and the longjmp... > > longjmp can destroy any non-volatile variable (-Wclobbered warns about > this). "All accessible objects have values [...] as of the time the longjmp function was called, except that the values of objects of automatic storage duration that are local to the function containing the invocation of the corresponding setjmp macro that do not have volatile-qualified type and have been changed between the setjmp invocation and longjmp call are indeterminate." -- C99 section 7.13.2.1 para 3. So variables may only be destroyed if they are all of: * local to the function calling setjmp * not volatile * changed between setjmp and longjmp We don't change env between the setjmp and longjmp so the compiler should not trash it. (Indeed according to Jan in http://lists.gnu.org/archive/html/qemu-devel/2011-07/msg00144.html -Wclobbered doesn't complain about this code.) -- PMM