[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] tcg: Reload local variables after return from l
From: |
Blue Swirl |
Subject: |
Re: [Qemu-devel] [PATCH] tcg: Reload local variables after return from longjmp |
Date: |
Sat, 2 Jul 2011 12:08:17 +0300 |
On Sat, Jul 2, 2011 at 10:50 AM, Jan Kiszka <address@hidden> wrote:
> From: Jan Kiszka <address@hidden>
>
> 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 <address@hidden>
Date: Sun Sep 26 11:58:38 2010 +0000
Add gcc warning -Wclobbered
Signed-off-by: Blue Swirl <address@hidden>
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
> Signed-off-by: Jan Kiszka <address@hidden>
> ---
> 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(;;) */
>
>