Received: from eggs.gnu.org ([208.118.235.92]:40944) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsEnC-0004Vl-Dg for qemu-devel@nongnu.org; Mon, 07 Jan 2013 10:39:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TsEn6-00074f-9s for qemu-devel@nongnu.org; Mon, 07 Jan 2013 10:39:14 -0500 From: Alexander Graf Date: Mon, 7 Jan 2013 16:38:35 +0100 Message-Id: <1357573140-8877-7-git-send-email-agraf@suse.de> In-Reply-To: <1357573140-8877-1-git-send-email-agraf@suse.de> References: <1357573140-8877-1-git-send-email-agraf@suse.de> Subject: [Qemu-devel] [PATCH 06/31] openpic: don't crash on a register access without a CPU context List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Blue Swirl , Scott Wood , qemu-ppc@nongnu.org, Aurelien Jarno From: Scott Wood If we access a register via the QEMU memory inspection commands (e.g. "xp") rather than from guest code, we won't have a CPU context. Gracefully fail to access the register in that case, rather than crashing. Signed-off-by: Scott Wood Signed-off-by: Alexander Graf --- hw/openpic.c | 16 +++++++++++++++- 1 files changed, 15 insertions(+), 1 deletions(-) diff --git a/hw/openpic.c b/hw/openpic.c index 10dbdf7..93e8208 100644 --- a/hw/openpic.c +++ b/hw/openpic.c @@ -161,7 +161,11 @@ static inline int test_bit(uint32_t *field, int bit) static int get_current_cpu(void) { - return cpu_single_env->cpu_index; + if (!cpu_single_env) { + return -1; + } + + return cpu_single_env->cpu_index; } static uint32_t openpic_cpu_read_internal(void *opaque, hwaddr addr, @@ -810,6 +814,11 @@ static void openpic_cpu_write_internal(void *opaque, hwaddr addr, DPRINTF("%s: cpu %d addr " TARGET_FMT_plx " <= %08x\n", __func__, idx, addr, val); + + if (idx < 0) { + return; + } + if (addr & 0xF) return; dst = &opp->dst[idx]; @@ -875,6 +884,11 @@ static uint32_t openpic_cpu_read_internal(void *opaque, hwaddr addr, DPRINTF("%s: cpu %d addr " TARGET_FMT_plx "\n", __func__, idx, addr); retval = 0xFFFFFFFF; + + if (idx < 0) { + return retval; + } + if (addr & 0xF) return retval; dst = &opp->dst[idx]; -- 1.6.0.2