From patchwork Wed May 9 14:54:37 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 157989 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id F069CB6FAF for ; Thu, 10 May 2012 00:54:59 +1000 (EST) Received: from localhost ([::1]:52788 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SS8I5-0005BB-Uf for incoming@patchwork.ozlabs.org; Wed, 09 May 2012 10:54:57 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48204) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SS8I0-0005AD-1y for qemu-devel@nongnu.org; Wed, 09 May 2012 10:54:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SS8Hq-000615-8J for qemu-devel@nongnu.org; Wed, 09 May 2012 10:54:51 -0400 Received: from mnementh.archaic.org.uk ([81.2.115.146]:42023) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SS8Hq-00060s-16 for qemu-devel@nongnu.org; Wed, 09 May 2012 10:54:42 -0400 Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1SS8Hl-0003La-LD; Wed, 09 May 2012 15:54:37 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Date: Wed, 9 May 2012 15:54:37 +0100 Message-Id: <1336575277-12840-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 81.2.115.146 Cc: =?UTF-8?q?Andreas=20F=C3=A4rber?= , patches@linaro.org Subject: [Qemu-devel] [PATCH for-1.1] target-arm: Fix crash when passed "-cpu foo" X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The macro definition of cpu_init meant that if cpu_arm_init() returned NULL this wouldn't result in cpu_init() itself returning NULL. This had the effect that "-cpu foo" for some unknown CPU name 'foo' would cause ARM targets to segfault rather than generating a useful error message. Fix this by making cpu_init a simple inline function. Signed-off-by: Peter Maydell Acked-by: Andreas Färber --- I did a quick grep and I think ARM is the only target at the moment where we've made this change to cpu_init -- is that right, Andreas? target-arm/cpu.h | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-) diff --git a/target-arm/cpu.h b/target-arm/cpu.h index 5eac070..d01285f 100644 --- a/target-arm/cpu.h +++ b/target-arm/cpu.h @@ -458,7 +458,15 @@ void cpu_arm_set_cp_io(CPUARMState *env, int cpnum, #define TARGET_PHYS_ADDR_SPACE_BITS 32 #define TARGET_VIRT_ADDR_SPACE_BITS 32 -#define cpu_init(model) (&cpu_arm_init(model)->env) +static inline CPUARMState *cpu_init(const char *cpu_model) +{ + ARMCPU *cpu = cpu_arm_init(cpu_model); + if (cpu) { + return &cpu->env; + } + return NULL; +} + #define cpu_exec cpu_arm_exec #define cpu_gen_code cpu_arm_gen_code #define cpu_signal_handler cpu_arm_signal_handler