Received: from eggs.gnu.org ([140.186.70.92]:52037) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QcwjX-0005y1-2V for qemu-devel@nongnu.org; Sat, 02 Jul 2011 05:43:28 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QcwjV-0003Y0-UQ for qemu-devel@nongnu.org; Sat, 02 Jul 2011 05:43:27 -0400 Received: from fmmailgate01.web.de ([217.72.192.221]:57451) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QcwjV-0003Xv-F9 for qemu-devel@nongnu.org; Sat, 02 Jul 2011 05:43:25 -0400 Message-ID: <4E0EE837.1000605@web.de> Date: Sat, 02 Jul 2011 11:43:19 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <4E0CA885.2050308@siemens.com> <4E0ECDDB.9030001@web.de> In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig2318926B67EEDC92E50769CE" Sender: jan.kiszka@web.de 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: Blue Swirl Cc: TeLeMan , qemu-devel This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enig2318926B67EEDC92E50769CE Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 2011-07-02 11:08, Blue Swirl wrote: > On Sat, Jul 2, 2011 at 10:50 AM, Jan Kiszka wrote: >> 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 use= d >> 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. >=20 > Nice. Could you try if gcc flag -Wclobbered catches something using > your compiler without your patch: >=20 > commit f826f0d0f5cf5dd18a0d34159c1a3bc8f2e6ddf4 > Author: Blue Swirl > Date: Sun Sep 26 11:58:38 2010 +0000 >=20 > Add gcc warning -Wclobbered >=20 > Signed-off-by: Blue Swirl >=20 > diff --git a/configure b/configure > index 88159ac..2417205 100755 > --- a/configure > +++ b/configure > @@ -1038,7 +1038,7 @@ fi > gcc_flags=3D"-Wold-style-declaration -Wold-style-definition -Wtype-lim= its" > gcc_flags=3D"-Wformat-security -Wformat-y2k -Winit-self > -Wignored-qualifiers $gcc_flags" > gcc_flags=3D"-Wmissing-include-dirs -Wempty-body -Wnested-externs $gcc= _flags" > -gcc_flags=3D"-fstack-protector-all -Wendif-labels $gcc_flags" > +gcc_flags=3D"-fstack-protector-all -Wendif-labels -Wclobbered $gcc_fla= gs" > cat > $TMPC << EOF > int main(void) { return 0; } > EOF Neither native gcc 4.5.0 nor mingw's 4.6.0 detect this issue. However, 4.6 found this - and 3 false positives: diff --git a/monitor.c b/monitor.c index 67ceb46..d7edbbb 100644 --- a/monitor.c +++ b/monitor.c @@ -3253,6 +3253,7 @@ static const mon_cmd_t qmp_query_cmds[] =3D { /*******************************************************************/ =20 static const char *pch; +static char *saved_key; static jmp_buf expr_env; =20 #define MD_TLONG 0 @@ -4254,8 +4255,11 @@ static const mon_cmd_t *monitor_parse_command(Moni= tor *mon, } typestr++; } - if (get_expr(mon, &val, &p)) + saved_key =3D key; + if (get_expr(mon, &val, &p)) { + key =3D saved_key; goto fail; + } /* Check if 'i' is greater than 32-bit */ if ((c =3D=3D 'i') && ((val >> 32) & 0xffffffff)) { monitor_printf(mon, "\'%s\' has failed: ", cmdname);= But the right way to deal with it is to return error codes and get rid of this setjmp/longjmp mess for get_expr. Jan --------------enig2318926B67EEDC92E50769CE Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.15 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk4O6DsACgkQitSsb3rl5xSk+QCgqWBrskSbnOx+/7CYS0HTCZLA 0ZEAn0wK3PHsd3NXWVKDGmLnxQjh5cap =44zD -----END PGP SIGNATURE----- --------------enig2318926B67EEDC92E50769CE--