From patchwork Mon Oct 29 12:05:11 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 12561 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 240B423F56 for ; Mon, 29 Oct 2012 12:05:20 +0000 (UTC) Received: from mail-ia0-f180.google.com (mail-ia0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 9288EA1958A for ; Mon, 29 Oct 2012 12:05:19 +0000 (UTC) Received: by mail-ia0-f180.google.com with SMTP id f6so3677332iag.11 for ; Mon, 29 Oct 2012 05:05:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :x-gm-message-state; bh=/Nbk9gQumomkxuaJMbVujhLcOogtBzyb3A+wPi3wLds=; b=m3GlPvy2k+mK0gUb63aabU29iUUlgto7lbOdSN9RdJ08C1AS4LgjqKhC2Uuy3m2UAf 18ISqvCZMxceLqqRUSvNiyCswAbyE1kmFaFRYn2fsPhRSEOWEb154nvo9SzuX4rwY3PN +I45d3GII1oOGcrS0eQiMPYvtoASUlOO+SvpDj1hosbdY1UHBOdfvft0iOERs0+QD3nC D4nLUID+rq4N9pZDYxZwnSy/FW37jc1zERI/Vk1deTE6eLBzKzBYYagk0lYC1zpMaSDj dZjM3PYiYcU4JrJYLU9VxeZAQyy7ep7NPh7YsiKyblhvFNhqKRIGfwnJ9H/fXVtaHBIR bBNg== Received: by 10.42.21.68 with SMTP id j4mr6953174icb.18.1351512319043; Mon, 29 Oct 2012 05:05:19 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.67.148 with SMTP id n20csp195088igt; Mon, 29 Oct 2012 05:05:17 -0700 (PDT) Received: by 10.204.4.149 with SMTP id 21mr8887306bkr.122.1351512316838; Mon, 29 Oct 2012 05:05:16 -0700 (PDT) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id il13si12963311bkc.148.2012.10.29.05.05.16 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 29 Oct 2012 05:05:16 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Authentication-Results: mx.google.com; spf=neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) smtp.mail=pm215@archaic.org.uk Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.72) (envelope-from ) id 1TSo5f-0004yh-Hx; Mon, 29 Oct 2012 12:05:11 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Meador Inge , Paul Brook , Blue Swirl Subject: [PATCH 3/3] target-m68k/m68k-semi.c: Log when put_user for returning values fails Date: Mon, 29 Oct 2012 12:05:11 +0000 Message-Id: <1351512311-19106-4-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1351512311-19106-1-git-send-email-peter.maydell@linaro.org> References: <1351512311-19106-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQlOJD7j//3/V8fv1G6EYEOXflxEM3PLPixfuJskJvEkjgN9QUaeTetGYRprhbf1RcApQejQ Abstract out the use of put_user for returning semihosting call results, so that we can log when a guest erroneously attempts a semihosting call with an unwritable argument block. Signed-off-by: Peter Maydell --- target-m68k/m68k-semi.c | 47 +++++++++++++++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/target-m68k/m68k-semi.c b/target-m68k/m68k-semi.c index d569bf1..9f7a24c 100644 --- a/target-m68k/m68k-semi.c +++ b/target-m68k/m68k-semi.c @@ -133,24 +133,44 @@ static void translate_stat(CPUM68KState *env, target_ulong addr, struct stat *s) unlock_user(p, addr, sizeof(struct m68k_gdb_stat)); } +static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, uint32_t err) +{ + target_ulong args = env->dregs[1]; + if (put_user_u32(ret, args) || + put_user_u32(err, args + 4)) { + /* The m68k semihosting ABI does not provide any way to report this + * error to the guest, so the best we can do is log it in qemu. + * It is always a guest error not to pass us a valid argument block. + */ + qemu_log_mask(LOG_GUEST_ERROR, "m68k-semihosting: return value " + "discarded because argument block not writable\n"); + } +} + +static void m68k_semi_return_u64(CPUM68KState *env, uint64_t ret, uint32_t err) +{ + target_ulong args = env->dregs[1]; + if (put_user_u32(ret >> 32, args) || + put_user_u32(ret, args + 4) || + put_user_u32(err, args + 8)) { + /* No way to report this via m68k semihosting ABI; just log it */ + qemu_log_mask(LOG_GUEST_ERROR, "m68k-semihosting: return value " + "discarded because argument block not writable\n"); + } +} + static int m68k_semi_is_fseek; static void m68k_semi_cb(CPUM68KState *env, target_ulong ret, target_ulong err) { - target_ulong args; - - args = env->dregs[1]; if (m68k_semi_is_fseek) { /* FIXME: We've already lost the high bits of the fseek return value. */ - /* FIXME - handle put_user() failure */ - put_user_u32(0, args); - args += 4; + m68k_semi_return_u64(env, ret, err); m68k_semi_is_fseek = 0; + } else { + m68k_semi_return_u32(env, ret, err); } - /* FIXME - handle put_user() failure */ - put_user_u32(ret, args); - put_user_u32(err, args + 4); } /* Read the input value from the argument block; fail the semihosting @@ -269,10 +289,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) arg0, off, arg3); } else { off = lseek(arg0, off, arg3); - /* FIXME - handle put_user() failure */ - put_user_u32(off >> 32, args); - put_user_u32(off, args + 4); - put_user_u32(errno, args + 8); + m68k_semi_return_u64(env, off, errno); } return; } @@ -444,7 +461,5 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) result = 0; } failed: - /* FIXME - handle put_user() failure */ - put_user_u32(result, args); - put_user_u32(errno, args + 4); + m68k_semi_return_u32(env, result, errno); }