qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@web.de>
To: Blue Swirl <blauwirbel@gmail.com>
Cc: TeLeMan <geleman@gmail.com>, qemu-devel <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH] tcg: Reload local variables after return from longjmp
Date: Sat, 02 Jul 2011 11:43:19 +0200	[thread overview]
Message-ID: <4E0EE837.1000605@web.de> (raw)
In-Reply-To: <CAAu8pHuwnWf8njsyZEyTdK9zBoOYaHd7XJhn_6McVUPvDu7Hog@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2596 bytes --]

On 2011-07-02 11:08, Blue Swirl wrote:
> On Sat, Jul 2, 2011 at 10:50 AM, Jan Kiszka <jan.kiszka@web.de> wrote:
>> From: Jan Kiszka <jan.kiszka@siemens.com>
>>
>> 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.
> 
> Nice. Could you try if gcc flag -Wclobbered catches something using
> your compiler without your patch:
> 
> commit f826f0d0f5cf5dd18a0d34159c1a3bc8f2e6ddf4
> Author: Blue Swirl <blauwirbel@gmail.com>
> Date:   Sun Sep 26 11:58:38 2010 +0000
> 
>     Add gcc warning -Wclobbered
> 
>     Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
> 
> diff --git a/configure b/configure
> index 88159ac..2417205 100755
> --- a/configure
> +++ b/configure
> @@ -1038,7 +1038,7 @@ fi
>  gcc_flags="-Wold-style-declaration -Wold-style-definition -Wtype-limits"
>  gcc_flags="-Wformat-security -Wformat-y2k -Winit-self
> -Wignored-qualifiers $gcc_flags"
>  gcc_flags="-Wmissing-include-dirs -Wempty-body -Wnested-externs $gcc_flags"
> -gcc_flags="-fstack-protector-all -Wendif-labels $gcc_flags"
> +gcc_flags="-fstack-protector-all -Wendif-labels -Wclobbered $gcc_flags"
>  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[] = {
 /*******************************************************************/
 
 static const char *pch;
+static char *saved_key;
 static jmp_buf expr_env;
 
 #define MD_TLONG 0
@@ -4254,8 +4255,11 @@ static const mon_cmd_t *monitor_parse_command(Monitor *mon,
                     }
                     typestr++;
                 }
-                if (get_expr(mon, &val, &p))
+                saved_key = key;
+                if (get_expr(mon, &val, &p)) {
+                    key = saved_key;
                     goto fail;
+                }
                 /* Check if 'i' is greater than 32-bit */
                 if ((c == '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


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 262 bytes --]

  reply	other threads:[~2011-07-02  9:43 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-30 16:47 [Qemu-devel] "cpu-exec.c: avoid AREG0 use" breaks x86 emulation on x86-64 Jan Kiszka
2011-06-30 21:17 ` Stefan Weil
2011-07-01  1:44 ` TeLeMan
2011-07-01 20:15   ` Blue Swirl
2011-07-02  7:50     ` [Qemu-devel] [PATCH] tcg: Reload local variables after return from longjmp Jan Kiszka
2011-07-02  9:08       ` Blue Swirl
2011-07-02  9:43         ` Jan Kiszka [this message]
2011-07-03 14:09           ` Paolo Bonzini
2011-07-12 20:56       ` Blue Swirl
2011-08-11 11:30       ` Peter Maydell
2011-08-11 12:16         ` Paolo Bonzini
2011-08-11 12:40           ` Peter Maydell
2011-08-11 13:13             ` Paolo Bonzini
2011-08-11 13:31               ` Peter Maydell
2011-08-11 14:10                 ` Paolo Bonzini
2011-08-11 14:12                   ` David Gilbert
2011-08-11 14:24                   ` Peter Maydell
2011-08-11 14:32                     ` Paolo Bonzini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4E0EE837.1000605@web.de \
    --to=jan.kiszka@web.de \
    --cc=blauwirbel@gmail.com \
    --cc=geleman@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).