Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NlnnX-00022E-Vq for qemu-devel@nongnu.org; Sun, 28 Feb 2010 13:23:24 -0500 Received: from [199.232.76.173] (port=46947 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NlnnW-000225-Qv for qemu-devel@nongnu.org; Sun, 28 Feb 2010 13:23:22 -0500 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1NlnnU-0000R4-Uq for qemu-devel@nongnu.org; Sun, 28 Feb 2010 13:23:22 -0500 Received: from hall.aurel32.net ([88.191.82.174]:54527) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NlnnU-0000Qw-Fl for qemu-devel@nongnu.org; Sun, 28 Feb 2010 13:23:20 -0500 Date: Sun, 28 Feb 2010 19:23:13 +0100 From: Aurelien Jarno Subject: Re: [Qemu-devel] [PATCH 1/1] target-i386: fix crash on x86 32bit linux host with hw breakpoint exceptions Message-ID: <20100228182313.GP10291@volta.aurel32.net> References: <1264544990-7628-1-git-send-email-jason.wessel@windriver.com> <1264544990-7628-2-git-send-email-jason.wessel@windriver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Disposition: inline In-Reply-To: <1264544990-7628-2-git-send-email-jason.wessel@windriver.com> List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jason Wessel Cc: qemu-devel@nongnu.org On Tue, Jan 26, 2010 at 04:29:50PM -0600, Jason Wessel wrote: > If you make use of hw breakpoints on a 32bit x86 linux host, qemu > will segmentation fault when processing the exception. > > The problem is that the value of env is stored in $ebp in the op_helper > raise_exception() function, and it can have the wrong value when > calling it from non generated code. > > It is possible to work around the problem by restoring the value of > env before calling raise_exception() using a new helper function that > takes (CPUState *) as one of the arguments. Thanks, applied. > Signed-off-by: Jason Wessel > --- > target-i386/exec.h | 1 + > target-i386/helper.c | 6 +++--- > target-i386/op_helper.c | 5 +++++ > 3 files changed, 9 insertions(+), 3 deletions(-) > > diff --git a/target-i386/exec.h b/target-i386/exec.h > index 1fd74fd..4ff3c57 100644 > --- a/target-i386/exec.h > +++ b/target-i386/exec.h > @@ -73,6 +73,7 @@ void do_interrupt_user(int intno, int is_int, int error_code, > target_ulong next_eip); > void QEMU_NORETURN raise_exception_err(int exception_index, int error_code); > void QEMU_NORETURN raise_exception(int exception_index); > +void QEMU_NORETURN raise_exception_env(int exception_index, CPUState *nenv); > void do_smm_enter(void); > > /* n must be a constant to be efficient */ > diff --git a/target-i386/helper.c b/target-i386/helper.c > index 70762bb..736ef16 100644 > --- a/target-i386/helper.c > +++ b/target-i386/helper.c > @@ -1529,7 +1529,7 @@ int check_hw_breakpoints(CPUState *env, int force_dr6_update) > > static CPUDebugExcpHandler *prev_debug_excp_handler; > > -void raise_exception(int exception_index); > +void raise_exception_env(int exception_index, CPUState *env); > > static void breakpoint_handler(CPUState *env) > { > @@ -1539,7 +1539,7 @@ static void breakpoint_handler(CPUState *env) > if (env->watchpoint_hit->flags & BP_CPU) { > env->watchpoint_hit = NULL; > if (check_hw_breakpoints(env, 0)) > - raise_exception(EXCP01_DB); > + raise_exception_env(EXCP01_DB, env); > else > cpu_resume_from_signal(env, NULL); > } > @@ -1548,7 +1548,7 @@ static void breakpoint_handler(CPUState *env) > if (bp->pc == env->eip) { > if (bp->flags & BP_CPU) { > check_hw_breakpoints(env, 1); > - raise_exception(EXCP01_DB); > + raise_exception_env(EXCP01_DB, env); > } > break; > } > diff --git a/target-i386/op_helper.c b/target-i386/op_helper.c > index 5eea322..4bb4347 100644 > --- a/target-i386/op_helper.c > +++ b/target-i386/op_helper.c > @@ -1351,6 +1351,11 @@ void raise_exception(int exception_index) > raise_interrupt(exception_index, 0, 0, 0); > } > > +void raise_exception_env(int exception_index, CPUState *nenv) > +{ > + env = nenv; > + raise_exception(exception_index); > +} > /* SMM support */ > > #if defined(CONFIG_USER_ONLY) > -- > 1.6.3.3 > > > > -- Aurelien Jarno GPG: 1024D/F1BCDB73 aurelien@aurel32.net http://www.aurel32.net