From nobody Fri Apr 26 07:12:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1568126865; cv=none; d=zoho.com; s=zohoarc; b=biebnmwqo6u3jKmv35k0uWWvqzBVPf5aN39JISZV2chLXafqzA3CDE1GlgncTGrlOaSTmiOP4jVfS5Tc6U9PY8fb2AO4NtEohLoaWf7VVk4umweB4Zu8ltcTi/qvTjM6xcPYGB7l5VgRBYUFJ4qhXxv6y9boAUZvIL43uaNh1cY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568126865; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=+93zhnxV6y7awAg0ASSqV7pmnPcURr2F+yzvl9fZsA4=; b=jEkgjkvl0rVw7GD0If5/DGNb1hpt/CUketiOQ3vhLnHOWCxR/0ADL3VmbstovbqKZHaC9sfEAHUSmvxdEt9Z4+8Y4Yd4M0eJYM1m1EUt9Jlb1W6atgKp+LcaMix2eLenugn114YFWNgmvHAORHItB7u3NwHPNQwm0AeoWc0Vc4Y= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (209.51.188.17 [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568126865395538.8510462018656; Tue, 10 Sep 2019 07:47:45 -0700 (PDT) Received: from localhost ([::1]:40812 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hQZ-0007Qx-Kx for importer@patchew.org; Tue, 10 Sep 2019 10:47:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53877) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNi-0005Kt-Bo for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNh-0004xX-9k for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:34 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:46933) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNh-0004x4-3S for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:33 -0400 Received: by mail-wr1-x441.google.com with SMTP id d17so8066013wrq.13 for ; Tue, 10 Sep 2019 07:44:33 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=+93zhnxV6y7awAg0ASSqV7pmnPcURr2F+yzvl9fZsA4=; b=yjlgCfy9He+gTLDKlS4tw4uJ09J7Z4UDlHWsRjtbB+txmHoBkLZCVFMrmmsmTuh2NW rlmUYDsPDLwT6abct4DmFK3w9vnVVOmqK7dNdwZzduuRc7ceYZpHMpN6mYv2VPje1hX8 LUv8zHDO6H0C7IbQZ7lKKSWPisdiX9jbI1gx7JtgLDtDYbepW6gzfg8yifKqH7TlyaQn IDFNKgXt9L4uYdzZT3sBGEgSaoH91SkjAjOkSdzm7hUUnSw3fAQcW3V+xj4SBCvTBeaD uwFB2vzUsONxWrPeppaFOLM9bnBAhkckPPCYVh2W1XHxvqGJkv4It126hXq3BPWXRltt rSnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+93zhnxV6y7awAg0ASSqV7pmnPcURr2F+yzvl9fZsA4=; b=Um12oqQjEQuMMkNDLp34unzia1b5GtXgntf6MpBuG5KGHTvuiT4zH8IUs+Hj9McvXB Np/c4g+G6yJse547yl+JPL716KkJhixtzHDsUE9FOBGdf7UmG5FOxvYWxF4Be0HxtC3O UbwkYm8rWlxLfYDK8687zTTeoP/0/GuibqoDmUjC/wBrmD0Lu7hjF4mJRZFS0w4OQq5R 4AcBKeuf2lO2mpcBTikKn8X0MyF1lx/9wGWwMBWDDUGNc+ngsaTvuJVgvbJjLYZTndX9 Vabg8Yfjr/kKLoE+U9PisRt+spEnZBLdTRwbJZNSop9OW3Adi7IRGQSOwNaXnXJM1xFx MwtQ== X-Gm-Message-State: APjAAAWPlmpa5ztykVlOH5hCK13fr8daJ9fo3DygD8V1UJNSA60TrI0y nb/CBBoPOKIGheqZDaSHbv/oJQ== X-Google-Smtp-Source: APXvYqwDfJZDye6s/cJJl7O5fXxwtEpFQGB8eA317h5hQBd/3WFc+te2o/WxQ0Vm18OMGxwwdbe2sg== X-Received: by 2002:adf:f110:: with SMTP id r16mr4111003wro.152.1568126672093; Tue, 10 Sep 2019 07:44:32 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:16 +0100 Message-Id: <20190910144428.32597-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PATCH 01/13] target/arm/arm-semi: Capture errno in softmmu version of set_swi_errno() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The set_swi_errno() function is called to capture the errno from a host system call, so that we can return -1 from the semihosting function and later allow the guest to get a more specific error code with the SYS_ERRNO function. It comes in two versions, one for user-only and one for softmmu. We forgot to capture the errno in the softmmu version; fix the error. (Semihosting calls directed to gdb are unaffected because they go through a different code path that captures the error return from the gdbstub call in arm_semi_cb() or arm_semi_flen_cb().) Signed-off-by: Peter Maydell --- NB that a later commit will put in some cleanup of TaskState that will let us reduce the duplication between the two implementations of this function. --- target/arm/arm-semi.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 90423a35deb..03e60105c05 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -114,8 +114,13 @@ static inline uint32_t set_swi_errno(TaskState *ts, ui= nt32_t code) return code; } #else +static target_ulong syscall_err; + static inline uint32_t set_swi_errno(CPUARMState *env, uint32_t code) { + if (code =3D=3D (uint32_t)-1) { + syscall_err =3D errno; + } return code; } =20 @@ -124,10 +129,6 @@ static inline uint32_t set_swi_errno(CPUARMState *env,= uint32_t code) =20 static target_ulong arm_semi_syscall_len; =20 -#if !defined(CONFIG_USER_ONLY) -static target_ulong syscall_err; -#endif - static void arm_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) { ARMCPU *cpu =3D ARM_CPU(cs); --=20 2.20.1 From nobody Fri Apr 26 07:12:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1568126883; cv=none; d=zoho.com; s=zohoarc; b=aBuKSPUaLXtY/HxEdTpidgij54Huvh3syiw/mBQV3ZH4wcHFZIRh6LqutwP1m6KBIj53rGgQsf6ljutAd8vePh0Wwt+8agLeBdtU1wmpqy5lp7ku6IHosmeO2Jbi4gROADwaRMinQcpXR43TYS2r9/yJugKb/7zvq2tguCPJnHk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568126883; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=Z9gxd6ZnA/tu16GX4u76t9CmQTv6s8qenU28wrY9d9Y=; b=P5hPnNzZ2ILV0OezAFXEbz/WBDtYiJhaZ/qmZ5qivs3Vbi87JeZyEubVQEGv+qVsbaN5SY8Y0CpgRDEqp2L2GLM5GdkKpfsTPCZdt6hLzrpBGlNf50dHIus8WVbgegrKM1h4TLukDPOkKPuLvXJHF/vR8XuN0rzfVHqzKEcpA78= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568126883374392.9148714005188; Tue, 10 Sep 2019 07:48:03 -0700 (PDT) Received: from localhost ([::1]:40820 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hR1-0007rN-Rv for importer@patchew.org; Tue, 10 Sep 2019 10:47:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53915) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNk-0005Nb-21 for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNi-0004yO-JD for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:35 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:45992) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNi-0004xl-CG for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:34 -0400 Received: by mail-wr1-x444.google.com with SMTP id l16so20757129wrv.12 for ; Tue, 10 Sep 2019 07:44:34 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Z9gxd6ZnA/tu16GX4u76t9CmQTv6s8qenU28wrY9d9Y=; b=WgiYbb/m97Pv6ppe2CbKzjKpvS7dFJb+zzJ+DkMmn9q2TdNEUxLAo4aizxIfdunzfr 0hM9q+hAi3EHbk5AP37qhV8rBEDQkM6YA8JTF8wGv6vqDDeJ5d8esuUTbP0zdkx88l81 DvehzHc7ZCldsLYEEUoL5oanNjtjKcJvZatrEjWSa3h+x7/0LsRYm1SD3Zj2+51MI/AP 3pxqFfop6EMdCqsf3OOAjDuyqBgoV8Q+x3CzdML6uhQ0+3FZnP1O+D8rpnA389ezLgpd vWI25Ku1y+Z2Wkrdcwn2ZKBnwonO9MJjzDlOsg0AoGdJcqE5dw4syy4ABW7YJXXDU0u2 XRzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z9gxd6ZnA/tu16GX4u76t9CmQTv6s8qenU28wrY9d9Y=; b=oso/Ofr5YeS1J2rZbkDvMaHpUoVf3kmRUsmZE6JX0ywUss2ealOENpyAEC7NiJg34r M4vbb4o+o/n9n6GbFAwBuR3UJQC1Qy/JpDTsiM50UC1QCWaUn2a1r2h50fntju3Eb02Y ch0gFp5vDXD+/f/V4fCKQn8U1RAYWFf37kUP6bCRdZCNhyj0n9H0WvhvLQbdllKNVN+W gD4K9Ra7eHz1DmS3brMWvl17nYeXcd3LxZNDLMNfqthV/3hyrpDJxraROoWiCty9872v lJzS7XTtAbrFjSssv05noq+nUCLqHnOQa2JKKNRAjJrnj9esr0oF7FGVWffx1G0/LlhD 0Egw== X-Gm-Message-State: APjAAAUP5qEsrCKIJSxejlFcBonMQPPymmADX/9KGfI0rI4Fmo6byhhp Dsy5RH6MGIKRJM1ne50Wda82fg== X-Google-Smtp-Source: APXvYqz37Tlr0pxMNEb8HAnTxvTlANhfgH6rntGG7xY/w1m0zgR9k+RJY3Rz6SAtNKIywz9T29iMHQ== X-Received: by 2002:a5d:6302:: with SMTP id i2mr27913008wru.249.1568126673412; Tue, 10 Sep 2019 07:44:33 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:17 +0100 Message-Id: <20190910144428.32597-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH 02/13] target/arm/arm-semi: Always set some kind of errno for failed calls X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" If we fail a semihosting call we should always set the semihosting errno to something; we were failing to do this for some of the "check inputs for sanity" cases. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e --- target/arm/arm-semi.c | 45 ++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 03e60105c05..51b55816faf 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -232,11 +232,13 @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_= syscall_complete_cb cb, #define GET_ARG(n) do { \ if (is_a64(env)) { \ if (get_user_u64(arg ## n, args + (n) * 8)) { \ - return -1; \ + errno =3D EFAULT; \ + return set_swi_errno(ts, -1); \ } \ } else { \ if (get_user_u32(arg ## n, args + (n) * 4)) { \ - return -1; \ + errno =3D EFAULT; \ + return set_swi_errno(ts, -1); \ } \ } \ } while (0) @@ -287,12 +289,13 @@ target_ulong do_arm_semihosting(CPUARMState *env) GET_ARG(2); s =3D lock_user_string(arg0); if (!s) { - /* FIXME - should this error code be -TARGET_EFAULT ? */ - return (uint32_t)-1; + errno =3D EFAULT; + return set_swi_errno(ts, -1); } if (arg1 >=3D 12) { unlock_user(s, arg0, 0); - return (uint32_t)-1; + errno =3D EINVAL; + return set_swi_errno(ts, -1); } if (strcmp(s, ":tt") =3D=3D 0) { int result_fileno =3D arg1 < 4 ? STDIN_FILENO : STDOUT_FILENO; @@ -413,8 +416,8 @@ target_ulong do_arm_semihosting(CPUARMState *env) } else { s =3D lock_user_string(arg0); if (!s) { - /* FIXME - should this error code be -TARGET_EFAULT ? */ - return (uint32_t)-1; + errno =3D EFAULT; + return set_swi_errno(ts, -1); } ret =3D set_swi_errno(ts, remove(s)); unlock_user(s, arg0, 0); @@ -432,11 +435,12 @@ target_ulong do_arm_semihosting(CPUARMState *env) char *s2; s =3D lock_user_string(arg0); s2 =3D lock_user_string(arg2); - if (!s || !s2) - /* FIXME - should this error code be -TARGET_EFAULT ? */ - ret =3D (uint32_t)-1; - else + if (!s || !s2) { + errno =3D EFAULT; + ret =3D set_swi_errno(ts, -1); + } else { ret =3D set_swi_errno(ts, rename(s, s2)); + } if (s2) unlock_user(s2, arg2, 0); if (s) @@ -456,8 +460,8 @@ target_ulong do_arm_semihosting(CPUARMState *env) } else { s =3D lock_user_string(arg0); if (!s) { - /* FIXME - should this error code be -TARGET_EFAULT ? */ - return (uint32_t)-1; + errno =3D EFAULT; + return set_swi_errno(ts, -1); } ret =3D set_swi_errno(ts, system(s)); unlock_user(s, arg0, 0); @@ -517,19 +521,22 @@ target_ulong do_arm_semihosting(CPUARMState *env) =20 if (output_size > input_size) { /* Not enough space to store command-line arguments. */ - return -1; + errno =3D E2BIG; + return set_swi_errno(ts, -1); } =20 /* Adjust the command-line length. */ if (SET_ARG(1, output_size - 1)) { /* Couldn't write back to argument block */ - return -1; + errno =3D EFAULT; + return set_swi_errno(ts, -1); } =20 /* Lock the buffer on the ARM side. */ output_buffer =3D lock_user(VERIFY_WRITE, arg0, output_size, 0= ); if (!output_buffer) { - return -1; + errno =3D EFAULT; + return set_swi_errno(ts, -1); } =20 /* Copy the command-line arguments. */ @@ -544,7 +551,8 @@ target_ulong do_arm_semihosting(CPUARMState *env) =20 if (copy_from_user(output_buffer, ts->info->arg_start, output_size)) { - status =3D -1; + errno =3D EFAULT; + status =3D set_swi_errno(ts, -1); goto out; } =20 @@ -614,7 +622,8 @@ target_ulong do_arm_semihosting(CPUARMState *env) =20 if (fail) { /* Couldn't write back to argument block */ - return -1; + errno =3D EFAULT; + return set_swi_errno(ts, -1); } } return 0; --=20 2.20.1 From nobody Fri Apr 26 07:12:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1568127194; cv=none; d=zoho.com; s=zohoarc; b=XpYGMqVCLO6yMzNGyWcF4nimWfTuGsDJSHo8Z9frZzzqAQoKkejV/GH8keZ7NTBlPtnydIAr/pQlrbbSN9AwYSjSFICknuCQpZx/0pNQYg8qaNtDPLUmFlYsn5rY04UfI/0GO6i2orj5h+KKbJWfGFjaWXtblyobbxOKFusl5Sg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568127194; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=KUZg/wLKZ46VG6GAy4EjR/UMqLr/ow3tF/QTUuuGP6s=; b=MHwqweDsny8AQWA0+k1XpiawyY/3/kkQCfPGJ5hvKL2UANfGMrfKgRjhNRMUXHNecBCefQRvDoj65g2/DHkdswdD3ZcrbVDWuAWrhhBIhonWedSqYE7xFqvX8NGapOSxxEOm9brDxbXFu/rHXCKwfLOb54gRpfQLsJ/9vrI6y0g= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568127194730685.0768351353921; Tue, 10 Sep 2019 07:53:14 -0700 (PDT) Received: from localhost ([::1]:40942 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hW2-0004uX-Ki for importer@patchew.org; Tue, 10 Sep 2019 10:53:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54051) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNp-0005VA-Lx for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNj-0004zE-RP for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:41 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]:44607) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNj-0004yn-Ko for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:35 -0400 Received: by mail-wr1-x430.google.com with SMTP id k6so8680231wrn.11 for ; Tue, 10 Sep 2019 07:44:35 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=KUZg/wLKZ46VG6GAy4EjR/UMqLr/ow3tF/QTUuuGP6s=; b=LuBKYNJ2o5yuSO/JadJO497TvA6PWxuyGKpPqe4eEc2yMcDuqW4SEbEwTqyEC6nN23 wGxD0GFSQdHUixcTYy1RJ6epcEouLrlp6FiKKjBLy8wuNvWGTpuQANZ7bhHsZaVy2dUl PcK2tX5KGhAHwj0NJqFTpR6XgTdMQPKqstPxa2E0qRHw1lIe7qQI4S5HhqVhe9RzuSXn 0PdEBZAHs5uKAwwn5XBi38fL0Xo7XEy9nOFuQoM8ms+elJ6Jfzvs6fnBOXOOpfV5PfTs jj6OAfnZ8A1tKwcBV/222DiVGULl0oY2uJEVzadV3YgNHXIVwgo+9UpmpIRgO8INSAw2 mLhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KUZg/wLKZ46VG6GAy4EjR/UMqLr/ow3tF/QTUuuGP6s=; b=TApzCVbL45P3VNRlCWk7jrAY+8DSNespkrRicy1RPfgXLA6h7tQNRZmpu4+ki1vnN5 t5djhIxubjLFB91GfIBmULRdbScxSWoGzKqRBp5jnhlyJtfXSDMfwuGLdjC1HNuuPPVO 9OaUVU/QqZvtdma1gMuDg1dEIvO6bC/YeK/T5OSK8qSsDY9/B0V6iP9irp4rqzPzSX9t 2Z9Pm75njYaC54I2KBuXKbSIWcIRmnyVR+3A+0/WNXLrVK/cUa2AyYWsH1So1of7+OoY QlgNs3ZZjDDn34n9vqkeQfUPXvca+8GnTd56lP2LN48RebCvjwuf8a9ebig1qFBMFJD0 mXRw== X-Gm-Message-State: APjAAAVL9yybpDQ1sM1mDkbrwlvQYXBXS4sgwSsXjPwm48SEd+ty6QgS Mv6HnwdZ8h4Z1PYra+azB+am1PaOaSy2nQ== X-Google-Smtp-Source: APXvYqz6fj6i7q1gnuVUGw61bloat/7qqEawTK4ouVolIaV3M2ppksvMMat/Sx8B2xr2qLl8jPu3Zw== X-Received: by 2002:a5d:4907:: with SMTP id x7mr27816658wrq.72.1568126674549; Tue, 10 Sep 2019 07:44:34 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:18 +0100 Message-Id: <20190910144428.32597-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::430 Subject: [Qemu-devel] [PATCH 03/13] target/arm/arm-semi: Make semihosting code hand out its own file descriptors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Currently the Arm semihosting code returns the guest file descriptors (handles) which are simply the fd values from the host OS or the remote gdbstub. Part of the semihosting 2.0 specification requires that we implement special handling of opening a ":semihosting-features" filename. Guest fds which result from opening the special file won't correspond to host fds, so to ensure that we don't end up with duplicate fds we need to have QEMU code control the allocation of the fd values we give the guest. Add in an abstraction layer which lets us allocate new guest FD values, and translate from a guest FD value back to the host one. This also fixes an odd hole where a semihosting guest could use the semihosting API to read, write or close file descriptors that it had never allocated but which were being used by QEMU itself. (This isn't a security hole, because enabling semihosting permits the guest to do arbitrary file access to the whole host filesystem, and so should only be done if the guest is completely trusted.) Currently the only kind of guest fd is one which maps to a host fd, but in a following commit we will add one which maps to the :semihosting-features magic data. If the guest is migrated with an open semihosting file descriptor then subsequent attempts to use the fd will all fail; this is not a change from the previous situation (where the host fd being used on the source end would not be re-opened on the destination end). Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e --- target/arm/arm-semi.c | 201 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 186 insertions(+), 15 deletions(-) diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 51b55816faf..05491bf5248 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -106,6 +106,113 @@ static int open_modeflags[12] =3D { O_RDWR | O_CREAT | O_APPEND | O_BINARY }; =20 +typedef enum GuestFDType { + GuestFDUnused =3D 0, + GuestFDHost =3D 1, +} GuestFDType; + +/* + * Guest file descriptors are integer indexes into an array of + * these structures (we will dynamically resize as necessary). + */ +typedef struct GuestFD { + GuestFDType type; + int hostfd; +} GuestFD; + +static GArray *guestfd_array; + +/* + * Allocate a new guest file descriptor and return it; if we + * couldn't allocate a new fd then return -1. + * This is a fairly simplistic implementation because we don't + * expect that most semihosting guest programs will make very + * heavy use of opening and closing fds. + */ +static int alloc_guestfd(void) +{ + guint i; + + if (!guestfd_array) { + /* New entries zero-initialized, i.e. type GuestFDUnused */ + guestfd_array =3D g_array_new(FALSE, TRUE, sizeof(GuestFD)); + } + + for (i =3D 0; i < guestfd_array->len; i++) { + GuestFD *gf =3D &g_array_index(guestfd_array, GuestFD, i); + + if (gf->type =3D=3D GuestFDUnused) { + return i; + } + } + + /* All elements already in use: expand the array */ + g_array_set_size(guestfd_array, i + 1); + return i; +} + +/* + * Look up the guestfd in the data structure; return NULL + * for out of bounds, but don't check whether the slot is unused. + * This is used internally by the other guestfd functions. + */ +static GuestFD *do_get_guestfd(int guestfd) +{ + if (!guestfd_array) { + return NULL; + } + + if (guestfd < 0 || guestfd >=3D guestfd_array->len) { + return NULL; + } + + return &g_array_index(guestfd_array, GuestFD, guestfd); +} + +/* + * Associate the specified guest fd (which must have been + * allocated via alloc_fd() and not previously used) with + * the specified host fd. + */ +static void associate_guestfd(int guestfd, int hostfd) +{ + GuestFD *gf =3D do_get_guestfd(guestfd); + + assert(gf); + gf->type =3D GuestFDHost; + gf->hostfd =3D hostfd; +} + +/* + * Deallocate the specified guest file descriptor. This doesn't + * close the host fd, it merely undoes the work of alloc_fd(). + */ +static void dealloc_guestfd(int guestfd) +{ + GuestFD *gf =3D do_get_guestfd(guestfd); + + assert(gf); + gf->type =3D GuestFDUnused; +} + +/* + * Given a guest file descriptor, get the associated struct. + * If the fd is not valid, return NULL. This is the function + * used by the various semihosting calls to validate a handle + * from the guest. + * Note: calling alloc_guestfd() or dealloc_guestfd() will + * invalidate any GuestFD* obtained by calling this function. + */ +static GuestFD *get_guestfd(int guestfd) +{ + GuestFD *gf =3D do_get_guestfd(guestfd); + + if (!gf || gf->type =3D=3D GuestFDUnused) { + return NULL; + } + return gf; +} + #ifdef CONFIG_USER_ONLY static inline uint32_t set_swi_errno(TaskState *ts, uint32_t code) { @@ -272,6 +379,7 @@ target_ulong do_arm_semihosting(CPUARMState *env) #else CPUARMState *ts =3D env; #endif + GuestFD *gf; =20 if (is_a64(env)) { /* Note that the syscall number is in W0, not X0 */ @@ -284,6 +392,9 @@ target_ulong do_arm_semihosting(CPUARMState *env) =20 switch (nr) { case TARGET_SYS_OPEN: + { + int guestfd; + GET_ARG(0); GET_ARG(1); GET_ARG(2); @@ -297,10 +408,19 @@ target_ulong do_arm_semihosting(CPUARMState *env) errno =3D EINVAL; return set_swi_errno(ts, -1); } + + guestfd =3D alloc_guestfd(); + if (guestfd < 0) { + unlock_user(s, arg0, 0); + errno =3D EMFILE; + return set_swi_errno(ts, -1); + } + if (strcmp(s, ":tt") =3D=3D 0) { int result_fileno =3D arg1 < 4 ? STDIN_FILENO : STDOUT_FILENO; + associate_guestfd(guestfd, result_fileno); unlock_user(s, arg0, 0); - return result_fileno; + return guestfd; } if (use_gdb_syscalls()) { ret =3D arm_gdb_syscall(cpu, arm_semi_cb, "open,%s,%x,1a4", ar= g0, @@ -308,15 +428,31 @@ target_ulong do_arm_semihosting(CPUARMState *env) } else { ret =3D set_swi_errno(ts, open(s, open_modeflags[arg1], 0644)); } + if (ret =3D=3D (uint32_t)-1) { + dealloc_guestfd(guestfd); + } else { + associate_guestfd(guestfd, ret); + ret =3D guestfd; + } unlock_user(s, arg0, 0); return ret; + } case TARGET_SYS_CLOSE: GET_ARG(0); - if (use_gdb_syscalls()) { - return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", arg0); - } else { - return set_swi_errno(ts, close(arg0)); + + gf =3D get_guestfd(arg0); + if (!gf) { + errno =3D EBADF; + return set_swi_errno(ts, -1); } + + if (use_gdb_syscalls()) { + ret =3D arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->host= fd); + } else { + ret =3D set_swi_errno(ts, close(gf->hostfd)); + } + dealloc_guestfd(arg0); + return ret; case TARGET_SYS_WRITEC: qemu_semihosting_console_outc(env, args); return 0xdeadbeef; @@ -327,17 +463,24 @@ target_ulong do_arm_semihosting(CPUARMState *env) GET_ARG(1); GET_ARG(2); len =3D arg2; + + gf =3D get_guestfd(arg0); + if (!gf) { + errno =3D EBADF; + return set_swi_errno(ts, -1); + } + if (use_gdb_syscalls()) { arm_semi_syscall_len =3D len; return arm_gdb_syscall(cpu, arm_semi_cb, "write,%x,%x,%x", - arg0, arg1, len); + gf->hostfd, arg1, len); } else { s =3D lock_user(VERIFY_READ, arg1, len, 1); if (!s) { /* Return bytes not written on error */ return len; } - ret =3D set_swi_errno(ts, write(arg0, s, len)); + ret =3D set_swi_errno(ts, write(gf->hostfd, s, len)); unlock_user(s, arg1, 0); if (ret =3D=3D (uint32_t)-1) { ret =3D 0; @@ -350,10 +493,17 @@ target_ulong do_arm_semihosting(CPUARMState *env) GET_ARG(1); GET_ARG(2); len =3D arg2; + + gf =3D get_guestfd(arg0); + if (!gf) { + errno =3D EBADF; + return set_swi_errno(ts, -1); + } + if (use_gdb_syscalls()) { arm_semi_syscall_len =3D len; return arm_gdb_syscall(cpu, arm_semi_cb, "read,%x,%x,%x", - arg0, arg1, len); + gf->hostfd, arg1, len); } else { s =3D lock_user(VERIFY_WRITE, arg1, len, 0); if (!s) { @@ -361,7 +511,7 @@ target_ulong do_arm_semihosting(CPUARMState *env) return len; } do { - ret =3D set_swi_errno(ts, read(arg0, s, len)); + ret =3D set_swi_errno(ts, read(gf->hostfd, s, len)); } while (ret =3D=3D -1 && errno =3D=3D EINTR); unlock_user(s, arg1, len); if (ret =3D=3D (uint32_t)-1) { @@ -375,31 +525,52 @@ target_ulong do_arm_semihosting(CPUARMState *env) return 0; case TARGET_SYS_ISTTY: GET_ARG(0); + + gf =3D get_guestfd(arg0); + if (!gf) { + errno =3D EBADF; + return set_swi_errno(ts, -1); + } + if (use_gdb_syscalls()) { - return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", arg0); + return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->host= fd); } else { - return isatty(arg0); + return isatty(gf->hostfd); } case TARGET_SYS_SEEK: GET_ARG(0); GET_ARG(1); + + gf =3D get_guestfd(arg0); + if (!gf) { + errno =3D EBADF; + return set_swi_errno(ts, -1); + } + if (use_gdb_syscalls()) { return arm_gdb_syscall(cpu, arm_semi_cb, "lseek,%x,%x,0", - arg0, arg1); + gf->hostfd, arg1); } else { - ret =3D set_swi_errno(ts, lseek(arg0, arg1, SEEK_SET)); + ret =3D set_swi_errno(ts, lseek(gf->hostfd, arg1, SEEK_SET)); if (ret =3D=3D (uint32_t)-1) return -1; return 0; } case TARGET_SYS_FLEN: GET_ARG(0); + + gf =3D get_guestfd(arg0); + if (!gf) { + errno =3D EBADF; + return set_swi_errno(ts, -1); + } + if (use_gdb_syscalls()) { return arm_gdb_syscall(cpu, arm_semi_flen_cb, "fstat,%x,%x", - arg0, arm_flen_buf(cpu)); + gf->hostfd, arm_flen_buf(cpu)); } else { struct stat buf; - ret =3D set_swi_errno(ts, fstat(arg0, &buf)); + ret =3D set_swi_errno(ts, fstat(gf->hostfd, &buf)); if (ret =3D=3D (uint32_t)-1) return -1; return buf.st_size; --=20 2.20.1 From nobody Fri Apr 26 07:12:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1568127266; cv=none; d=zoho.com; s=zohoarc; b=ZqBBa4KEdKUZmLpOvwgrnCIdd9x6x/v4dD5AYpvGDuByr6Qf0cV1loSp3GCfCIh4P5M17gI3o7Zw+0H2vkIt1QVic7nQSTNQJzJLqGTqzfZZgD16aObim2NNgW6W4bsJ2mapqrfHZKZWSlGx5i4K+dVlY2wRYmvb2r9V3vCOXg8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568127266; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=fZA5qZtHref6EES7glsBu8W4zydJFLjuwr0G2I/qEek=; b=ZCYCsmfPHHzoUMujs533kgiJjX1lqmmRxLifcvaAqUGoQRKnWXEXw2cMWnzkzGF8S5Zcc7eIbQqurqCBDI7t0WRJ+WcP8bg77ZuXNJSRumxA3uNoFryKlomYu3ZDky2swW104397dQyOPvJ0x/9TD2Qu9C60zhIpPAwkbG0s7+M= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568127266960335.74218355796734; Tue, 10 Sep 2019 07:54:26 -0700 (PDT) Received: from localhost ([::1]:40968 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hXF-0006jn-Df for importer@patchew.org; Tue, 10 Sep 2019 10:54:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53956) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNl-0005PV-RP for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNk-0004zj-Gk for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:37 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:34246) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNk-0004z7-Am for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:36 -0400 Received: by mail-wr1-x441.google.com with SMTP id a11so11068229wrx.1 for ; Tue, 10 Sep 2019 07:44:36 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=fZA5qZtHref6EES7glsBu8W4zydJFLjuwr0G2I/qEek=; b=IX1Bn+L75xsE7wR97ujQGTwx7gERV6QZ/5uUFlJkg4cM3TAIGRuAZ2f8MUOuzmaH/l 7p/3UeB5SACUV7ULkrYPZf4l2JC6jj9Ia/1JBrdu/hhdk1juMbf8qBwLTe92d8CIm2NH WqRilXdkGprmhh3ov14IQ7t9hsiz58myU8OUi1MYToYLLjsE8dU5/PPSjzbfSGiJadSs odf3GudeX81c3LIKoUY4DDPGTQ+v4lqfc74WKRh2/Rk+9uigZLmqKWZKFn9C/RpQPWBT H58yH/v9YQlvo4v5LyWy2MbX0gUfHO+LhyDje0OVd5RAKY69sFsgMk0+YMYgWXUZ/p/I WqTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fZA5qZtHref6EES7glsBu8W4zydJFLjuwr0G2I/qEek=; b=ixugX+z0mqG66vfI4OGO/XOLf+l+SJOHKwsJM8jhWeqmsiUXwvOd8c+Zyba9i1NPiv E5BVJyEjKsgsRm1MO3HAZwBpKAtjr4ItgLjYHd6xf4D18QM4yVGEiSB80k/N+91mzicY wjjLjpcq5nbAtfh237hNR1qIToHMskbl9JEmpkUiaeOdf40iFb4z52Ecs9S8CH30mK2Q SG9vJF079+gudjxizzl2dr6/PW4I5TURjWpG2Yjn/uis2GdkmDZZj+HrisuAl2VOk/xC ATfCB0h2Dc/BwS2jygBzWZP5BVesvtBlNlh5/ISP8nImsQHwAUk85Oi3U9hLl7eT4SeC lSdw== X-Gm-Message-State: APjAAAVBNMSEB0jX5944EZh0WBSqN/nEMi1GYPR5ZiSgDqlgPX3SSB5j JXv+F4C+PfCfwmiH5Lk7tSJJEA== X-Google-Smtp-Source: APXvYqyjTDUzvzPnMlLUmbXH/biyEgBm1jIvMwQN4NQDq7w/thO6i/dyCQ8UT1ZuDnQfQbIgeCbTqA== X-Received: by 2002:adf:ebd0:: with SMTP id v16mr18411913wrn.352.1568126675477; Tue, 10 Sep 2019 07:44:35 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:19 +0100 Message-Id: <20190910144428.32597-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PATCH 04/13] target/arm/arm-semi: clean up TaskState* usage in non-user-only code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" The semihosting code has to build for both user-only and softmmu; for user-only it needs access to the TaskState struct that holds per-thread information. For softmmu we don't need it. Currently the softmmu set_swi_errno() takes a CPUARMState *, which it doesn't use, and the 'ts' variable in do_arm_semihosting() is set to either be a TaskState* or a CPUARMState* depending on whether CONFIG_USER_ONLY is set, so that the callsite always passes 'ts'. Since we don't actually need the CPUARMState *, we can instead make set_swi_errno() always take a TaskState*, by providing a local-to-this-file dummy typedef for the softmmu case and setting ts to NULL for softmmu. This will make it easier to have other functions which pass through the TaskState*, because now they can have the same prototype regardless of whether they're CONFIG_USER_ONLY or not. Signed-off-by: Peter Maydell --- target/arm/arm-semi.c | 48 ++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 05491bf5248..ce3ba554bef 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -36,6 +36,13 @@ #else #include "exec/gdbstub.h" #include "qemu/cutils.h" + +/* + * Dummy typedef so that we can have functions that take + * a TaskState* even if we're building for softmmu; in that + * case the argument will always be NULL. + */ +typedef void TaskState; #endif =20 #define TARGET_SYS_OPEN 0x01 @@ -213,27 +220,24 @@ static GuestFD *get_guestfd(int guestfd) return gf; } =20 -#ifdef CONFIG_USER_ONLY -static inline uint32_t set_swi_errno(TaskState *ts, uint32_t code) -{ - if (code =3D=3D (uint32_t)-1) - ts->swi_errno =3D errno; - return code; -} -#else +#ifndef CONFIG_USER_ONLY static target_ulong syscall_err; =20 -static inline uint32_t set_swi_errno(CPUARMState *env, uint32_t code) -{ - if (code =3D=3D (uint32_t)-1) { - syscall_err =3D errno; - } - return code; -} - #include "exec/softmmu-semi.h" #endif =20 +static inline uint32_t set_swi_errno(TaskState *ts, uint32_t code) +{ + if (code =3D=3D (uint32_t)-1) { +#ifdef CONFIG_USER_ONLY + ts->swi_errno =3D errno; +#else + syscall_err =3D errno; +#endif + } + return code; +} + static target_ulong arm_semi_syscall_len; =20 static void arm_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) @@ -374,13 +378,15 @@ target_ulong do_arm_semihosting(CPUARMState *env) int nr; uint32_t ret; uint32_t len; -#ifdef CONFIG_USER_ONLY - TaskState *ts =3D cs->opaque; -#else - CPUARMState *ts =3D env; -#endif + TaskState *ts; GuestFD *gf; =20 +#ifdef CONFIG_USER_ONLY + ts =3D cs->opaque; +#else + ts =3D NULL; +#endif + if (is_a64(env)) { /* Note that the syscall number is in W0, not X0 */ nr =3D env->xregs[0] & 0xffffffffU; --=20 2.20.1 From nobody Fri Apr 26 07:12:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1568127457; cv=none; d=zoho.com; s=zohoarc; b=afT/njE43iH6M2Ml7NrtQt+QT21zmmbe4i+fhnishhIBtsf+EOfyi1/sgn5AKWEPxjeyElewOLF071f+YyVBAg900Emwrs0u06qHCOHFHy90BCSuQtJxXV57CpejqMf9eurcL4YXKsUjDDWgO1g/OzfRSICLhcIL+gDaYV0naXg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568127457; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=zlo9vQHXYMdSRYQxbnaGFzeWoJMkmJsq2rf4IJ1ziW4=; b=nGNYeojLxnPFQ76ox4b6Hj37ctsyPObTfYpSV/WBAYHfwsoJIQItM6hHNPcBwdrpqUP/njNWcK7KvzQxxQZu4pGIftsrcvRixco8rN+GE4RNkVW+Yh5/eZICHXSiXmbIophA0UHoH1hetNMFrTkkP3v3/Wp+IdzhzsHsgDycdlo= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568127457700857.711835607497; Tue, 10 Sep 2019 07:57:37 -0700 (PDT) Received: from localhost ([::1]:41022 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7haK-00025b-A9 for importer@patchew.org; Tue, 10 Sep 2019 10:57:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53982) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNm-0005RB-Ve for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNl-00050Z-QG for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:38 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:39185) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNl-000506-Jl for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:37 -0400 Received: by mail-wr1-x444.google.com with SMTP id t16so20832403wra.6 for ; Tue, 10 Sep 2019 07:44:37 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=zlo9vQHXYMdSRYQxbnaGFzeWoJMkmJsq2rf4IJ1ziW4=; b=pun+1zY5WhN2o0gSnE577xUfjuVDwQhUVEkMW8GsvWdeh82xhKthM9G80PRZ0dZJMB GP3hgPkZvtMQujx48UjpE+VuU1MaxhtDM0V7KqsxgDIe3S4hvscuuRMG82ZI/l2UUnM7 ibzTgjoZtriyYo89qDZ4faNq6B20UfYbFYUH2PdZIv4IHQpRAlMSorG0jxSsqhogCkgy 28gtcUnYN6Apll4DQ8kPb6TqVLwRTC85fMQ8JESNfN7yhJMB9gwDyG+hJ1UKlPRXYPrx qoMxWzBQB2dSAHvbSKTvpbDta9Xt9beJN2pHPI0vEb2cVavqGbQCoo+4Vh00N6Lct+vX cxsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zlo9vQHXYMdSRYQxbnaGFzeWoJMkmJsq2rf4IJ1ziW4=; b=otDDvNiGuv2mXidwiNuqrsdt6GdXIp9BSbRvNmYXHtq/f6oQJ3ijfJenYCSnv49ln8 qyBJJh+KRA2GdiIbPIiBLKw/bZ8SoxUDJhfdcVMPeMbfhBXq0gkcL8V3jJJPJ/DAn4Xx cVoA1oGDKp7GFjVgqQYN+bqz+a/MHLcNOmjxeLpfdBA+a57vF/THAX8Adp0dLdRaPH1X 4gmVIbjtprQ3fOnElpsHNmmEpiHcdQGwDCIeb4GOVPxhnui073RK/5YeglVMhXfA6IP0 MdhPhGdHUrUo0upduGaKyaN3YwCe1ytCu+GvAbLwFuuj7rB56M576fDtqW3q5X1Dq40a lJ0A== X-Gm-Message-State: APjAAAUGEtn74mtrQXkvb3HFs2ryS7edFWcn0HJXoQuZm/oaDuWWWjuD NYT9CFWMV87dc6I7gEB57HQidanLITRdqw== X-Google-Smtp-Source: APXvYqx/HE1bCksu4ZOMV0myleKiDhQNvoIpA4CoALL5D9erjf+wDxA7j1W9ZJpPAadQdy4/y36B6A== X-Received: by 2002:a05:6000:142:: with SMTP id r2mr3251793wrx.212.1568126676765; Tue, 10 Sep 2019 07:44:36 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:20 +0100 Message-Id: <20190910144428.32597-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH 05/13] target/arm/arm-semi: Factor out implementation of SYS_CLOSE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Currently for the semihosting calls which take a file descriptor (SYS_CLOSE, SYS_WRITE, SYS_READ, SYS_ISTTY, SYS_SEEK, SYS_FLEN) we have effectively two implementations, one for real host files and one for when we indirect via the gdbstub. We want to add a third one to deal with the magic :semihosting-features file. Instead of having a three-way if statement in each of these cases, factor out the implementation of the calls to separate functions which we dispatch to via function pointers selected via the GuestFDType for the guest fd. In this commit, we set up the framework for the dispatch, and convert the SYS_CLOSE call to use it. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e --- target/arm/arm-semi.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index ce3ba554bef..f3e0bf77cd3 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -116,6 +116,7 @@ static int open_modeflags[12] =3D { typedef enum GuestFDType { GuestFDUnused =3D 0, GuestFDHost =3D 1, + GuestFDGDB =3D 2, } GuestFDType; =20 /* @@ -179,14 +180,14 @@ static GuestFD *do_get_guestfd(int guestfd) /* * Associate the specified guest fd (which must have been * allocated via alloc_fd() and not previously used) with - * the specified host fd. + * the specified host/gdb fd. */ static void associate_guestfd(int guestfd, int hostfd) { GuestFD *gf =3D do_get_guestfd(guestfd); =20 assert(gf); - gf->type =3D GuestFDHost; + gf->type =3D use_gdb_syscalls() ? GuestFDGDB : GuestFDHost; gf->hostfd =3D hostfd; } =20 @@ -337,6 +338,37 @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_s= yscall_complete_cb cb, return is_a64(env) ? env->xregs[0] : env->regs[0]; } =20 +/* + * Types for functions implementing various semihosting calls + * for specific types of guest file descriptor. These must all + * do the work and return the required return value for the guest, + * setting the guest errno if appropriate. + */ +typedef uint32_t sys_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf); + +static uint32_t host_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) +{ + return set_swi_errno(ts, close(gf->hostfd)); +} + +static uint32_t gdb_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) +{ + return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd); +} + +typedef struct GuestFDFunctions { + sys_closefn *closefn; +} GuestFDFunctions; + +static const GuestFDFunctions guestfd_fns[] =3D { + [GuestFDHost] =3D { + .closefn =3D host_closefn, + }, + [GuestFDGDB] =3D { + .closefn =3D gdb_closefn, + }, +}; + /* Read the input value from the argument block; fail the semihosting * call if the memory read fails. */ @@ -452,11 +484,7 @@ target_ulong do_arm_semihosting(CPUARMState *env) return set_swi_errno(ts, -1); } =20 - if (use_gdb_syscalls()) { - ret =3D arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->host= fd); - } else { - ret =3D set_swi_errno(ts, close(gf->hostfd)); - } + ret =3D guestfd_fns[gf->type].closefn(ts, cpu, gf); dealloc_guestfd(arg0); return ret; case TARGET_SYS_WRITEC: --=20 2.20.1 From nobody Fri Apr 26 07:12:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1568126883; cv=none; d=zoho.com; s=zohoarc; b=dxB9nNJZGy2oE9LF8zfC+6gJu1pjtchKAc7fsiOCql2tzz4OdNW4xa1zZVKQLdozYBsSQ6VPVmN0rn508TXTgOkGIZXSVqKxSATrsWks3hRclsjuoMXJKk/IOuPewdkw6QGTcQgpFhuYrcAz2yyjcdDvvBVJCJFNx4jvIMb/v6s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568126883; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=YWOXDYdgItfE8+407vkIvvnaRwn01B+C3RlPpmYpG/U=; b=DQh+bzGYhruFs8Wc1v5ppksf/WF4QQlkKDZ/WiXogs57mvcFcAca+IrF5udhWNKs2wsZH4dThLjjivDAp6ohFFjFtR6c/KjqmDN0r6P1HgAocE59Prn0AlhurUpdQNW+U/+M/YuezNK97uTWASeVdPfJkz85QH3PspP4n5+oy0Q= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568126883926232.99856251129347; Tue, 10 Sep 2019 07:48:03 -0700 (PDT) Received: from localhost ([::1]:40824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hR4-0007t3-N2 for importer@patchew.org; Tue, 10 Sep 2019 10:48:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54009) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNo-0005Sx-8E for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNm-00051D-Rc for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:39 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:40572) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNm-00050t-Lt for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:38 -0400 Received: by mail-wr1-x444.google.com with SMTP id w13so20818660wru.7 for ; Tue, 10 Sep 2019 07:44:38 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=YWOXDYdgItfE8+407vkIvvnaRwn01B+C3RlPpmYpG/U=; b=CPOae9hgzuSC0OuDGe9BwP3BNIZQOP1fwo3SjCfxBWaL621js/y1AppTZuhJF3YbXx TEQZHopJll6otD2jmKBXQ6+eldWQm2EOTurJXMwBt9IPolSIWRkthFi6Q6m25paKoNfI M+yvPrZXHR8w5y69dXowBN/1N22jRoAM61LgnZClKts3ccSs+x+hpFUJM+7wUiHUzWtN tG56sqp6K7DNFTHkrgKnQhZV/Z848IvOOQZe6ENchdYbKhzLdNeGGQP9NHQacBaeIddc V0XIDgJa7uBgT+7HH1etQGK45TbEws3VGphBaZ63UTv1Wm21qXQ0rcWZFw2nZJsTp1ub M39A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YWOXDYdgItfE8+407vkIvvnaRwn01B+C3RlPpmYpG/U=; b=uOtIsAqxKp/97xw4fttffkhPwZq5lH7EfVgkS5f/vWigjFnqehgqQoI1CmJtzbuQjl bs+3vj3VFvtyCE4+IFAQAU6szpAXCjDg2ui2oz3LmpTlQQTYz6aIvopCiqUlzYaBNYIH qwbj4VuuzYkpIgg6TuZiOczENut7nfZld6MJmaNQ1MZoT4JjMCvguEq4pbl3ElNHSFjQ 7K7c7ZOJCERnlBZJZfFJ7lO5PGQHmN19VaL3v9pEN+6JS/KLlrmxNbU5KDquNIfjjXg7 UiI5BEbLDL6dJLq1rqchtbSoG2MTbuA2j0TzPtIbNoIFEPK5002wSk+Mo6ezSdH1fhtD /JYw== X-Gm-Message-State: APjAAAVVwkO1aQCSyxlvqG5fA9pp6ze9W81cNTgYOpjQ+/+4K4oU8Tb3 mQhPGYSsnse8tX54VUusQpKnUg== X-Google-Smtp-Source: APXvYqxKsofOQZNo4pBVTaX1Za9eMs/R4U9WqJQdmm4UaZ99Zyq+vzjvdWa9QsTphSX1fARW9MZVCw== X-Received: by 2002:a5d:548d:: with SMTP id h13mr9677544wrv.215.1568126677826; Tue, 10 Sep 2019 07:44:37 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:21 +0100 Message-Id: <20190910144428.32597-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH 06/13] target/arm/arm-semi: Factor out implementation of SYS_WRITE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Factor out the implementation of SYS_WRITE via the new function tables. The #ifdef around the declaration/initialization of the local 'env' variable is unfortunate but necessary, because the softmmu-semi.h version of lock_user implicitly uses 'env', but the user-only version doesn't need it. Without the ifdefs we'd get a warning about the unused variable for the user-only compilation. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e --- target/arm/arm-semi.c | 53 ++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index f3e0bf77cd3..0dec4c04e2f 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -345,27 +345,61 @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_= syscall_complete_cb cb, * setting the guest errno if appropriate. */ typedef uint32_t sys_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf); +typedef uint32_t sys_writefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong buf, uint32_t len); =20 static uint32_t host_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) { return set_swi_errno(ts, close(gf->hostfd)); } =20 +static uint32_t host_writefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong buf, uint32_t len) +{ + uint32_t ret; +#ifndef CONFIG_USER_ONLY + CPUARMState *env =3D &cpu->env; +#endif + char *s =3D lock_user(VERIFY_READ, buf, len, 1); + if (!s) { + /* Return bytes not written on error */ + return len; + } + ret =3D set_swi_errno(ts, write(gf->hostfd, s, len)); + unlock_user(s, buf, 0); + if (ret =3D=3D (uint32_t)-1) { + ret =3D 0; + } + /* Return bytes not written */ + return len - ret; +} + static uint32_t gdb_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) { return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd); } =20 +static uint32_t gdb_writefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong buf, uint32_t len) +{ + arm_semi_syscall_len =3D len; + return arm_gdb_syscall(cpu, arm_semi_cb, "write,%x,%x,%x", + gf->hostfd, buf, len); +} + typedef struct GuestFDFunctions { sys_closefn *closefn; + sys_writefn *writefn; } GuestFDFunctions; =20 static const GuestFDFunctions guestfd_fns[] =3D { [GuestFDHost] =3D { .closefn =3D host_closefn, + .writefn =3D host_writefn, }, [GuestFDGDB] =3D { .closefn =3D gdb_closefn, + .writefn =3D gdb_writefn, }, }; =20 @@ -504,24 +538,7 @@ target_ulong do_arm_semihosting(CPUARMState *env) return set_swi_errno(ts, -1); } =20 - if (use_gdb_syscalls()) { - arm_semi_syscall_len =3D len; - return arm_gdb_syscall(cpu, arm_semi_cb, "write,%x,%x,%x", - gf->hostfd, arg1, len); - } else { - s =3D lock_user(VERIFY_READ, arg1, len, 1); - if (!s) { - /* Return bytes not written on error */ - return len; - } - ret =3D set_swi_errno(ts, write(gf->hostfd, s, len)); - unlock_user(s, arg1, 0); - if (ret =3D=3D (uint32_t)-1) { - ret =3D 0; - } - /* Return bytes not written */ - return len - ret; - } + return guestfd_fns[gf->type].writefn(ts, cpu, gf, arg1, len); case TARGET_SYS_READ: GET_ARG(0); GET_ARG(1); --=20 2.20.1 From nobody Fri Apr 26 07:12:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1568127728; cv=none; d=zoho.com; s=zohoarc; b=Bg1DzcnjSdLaj6AKnS5sf4PgI7clluxr5XoVDaY63ukMt7EgjD12PeqTCYe12k4F92hXdTPWeRKUBqegeEbZCathNKx5sAGHlPunPBwbNU3dg/LRAbcDykv5qQ3Rbt5wtA3oBiB7yrC7N+tIaJ8hDAimxtJZ7tt0Us2zJTRs56U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568127728; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=7yOOhdKlBIYO8WFMmpn39kOmkjcRHpZcI7p0s8duWdE=; b=Kws/UelwnQCxOGbdgZpPri4I6NwMq2ntXIM2IMun8euDcDegC297wR1nxSfi+ScWn2N3IPRxJoAykfAA+vXCv3PvJtUFdhRe/Td6FKfWDs1jouzLNyEzyOqpqZr5u48T+zvrPXJtczz39cXU+Alw7sCkbFzH787Em1anHeLpwn8= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568127728427117.1428821090011; Tue, 10 Sep 2019 08:02:08 -0700 (PDT) Received: from localhost ([::1]:41076 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7heg-00062U-6U for importer@patchew.org; Tue, 10 Sep 2019 11:02:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54034) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNp-0005UH-1a for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNn-00051t-QD for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:40 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:36223) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNn-00051U-Ki for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:39 -0400 Received: by mail-wr1-x442.google.com with SMTP id y19so20839190wrd.3 for ; Tue, 10 Sep 2019 07:44:39 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=7yOOhdKlBIYO8WFMmpn39kOmkjcRHpZcI7p0s8duWdE=; b=S1W9+GjIQ6Q1+v2erJ8a8p45+tj3PFe1rle3T4TYKuUvrNPQ7Kw88ydslBiCo08oJS AnFATCxYou1iuoeTX7wauXIkGk5wQ1hT0f7vKK0Ft8VVHUjTi9YSMz4yyspTLPhT1kv2 BmVqnCkOpefUdL5WOHjgRVj04HX5GjBuNJPCq23TvsNGBE0+p71t7L37o411Ad0GimlX OFN+SOpA24d92oo5LwlJdKVX0OtQlrbfZb502feAxRpcKkCnJ9ayL8YEslcX+mN1kt2M Lqz21sYS3zCpmNkXLLVB151z2FPn7UZAyTX8O2TgQWgAT0L0/JpYi4hCGakerpNXA/3+ iKrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7yOOhdKlBIYO8WFMmpn39kOmkjcRHpZcI7p0s8duWdE=; b=CvqypKaItjDyBNFbb7iQfuM05QBGKFdN0LhYQK/RxC90L/T6J6wncaaFGYVmNLqkHp JsAoTA/LLILUJV4+kHzwgz+RXQQDSWN454ji0Zzpx8gULkADQuXpY8ykl4tzU7Jp3ue8 ULFIhDyJw+66UcIkvc7esFyf4I1WEFXg0kSRYTAVkPegs0GDyC6ZXaJkTSN+W5lMilgC UHYa0aTce+rUgkPDqpV23hAPOgtGuH6xkPF61hQ3gdfUOtbLhkQGuEToqkb1eBXC0TAK 8SzR/1A+FgZH1VIiqCNfBkzQS/sMGpAaKA42oivPvdBg5oI5IGD1jAy1VfBLjUgI6IK2 z14w== X-Gm-Message-State: APjAAAWei3qBVeTblUSsfQtffxOaK43VjwEGJRBf6Hfky7xFdGVcJjeD WrffOrPrQKjEKv/prRzLBa6IVCM0L2TvdA== X-Google-Smtp-Source: APXvYqzH0+2tPkyNL7Q3ztPaK4uYqBJuC6i0Blg1Ihi3fBIF0jLBm/GHXUJ+mp4eEWSEFBRwZqCIMg== X-Received: by 2002:a5d:49c7:: with SMTP id t7mr276133wrs.229.1568126678753; Tue, 10 Sep 2019 07:44:38 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:22 +0100 Message-Id: <20190910144428.32597-8-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::442 Subject: [Qemu-devel] [PATCH 07/13] target/arm/arm-semi: Factor out implementation of SYS_READ X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Factor out the implementation of SYS_READ via the new function tables. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e --- target/arm/arm-semi.c | 57 ++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 0dec4c04e2f..48a10dd3c3a 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -347,6 +347,8 @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_sy= scall_complete_cb cb, typedef uint32_t sys_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf); typedef uint32_t sys_writefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, target_ulong buf, uint32_t len); +typedef uint32_t sys_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong buf, uint32_t len); =20 static uint32_t host_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) { @@ -374,6 +376,29 @@ static uint32_t host_writefn(TaskState *ts, ARMCPU *cp= u, GuestFD *gf, return len - ret; } =20 +static uint32_t host_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong buf, uint32_t len) +{ + uint32_t ret; +#ifndef CONFIG_USER_ONLY + CPUARMState *env =3D &cpu->env; +#endif + char *s =3D lock_user(VERIFY_WRITE, buf, len, 0); + if (!s) { + /* return bytes not read */ + return len; + } + do { + ret =3D set_swi_errno(ts, read(gf->hostfd, s, len)); + } while (ret =3D=3D -1 && errno =3D=3D EINTR); + unlock_user(s, buf, len); + if (ret =3D=3D (uint32_t)-1) { + ret =3D 0; + } + /* Return bytes not read */ + return len - ret; +} + static uint32_t gdb_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) { return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd); @@ -387,19 +412,30 @@ static uint32_t gdb_writefn(TaskState *ts, ARMCPU *cp= u, GuestFD *gf, gf->hostfd, buf, len); } =20 +static uint32_t gdb_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong buf, uint32_t len) +{ + arm_semi_syscall_len =3D len; + return arm_gdb_syscall(cpu, arm_semi_cb, "read,%x,%x,%x", + gf->hostfd, buf, len); +} + typedef struct GuestFDFunctions { sys_closefn *closefn; sys_writefn *writefn; + sys_readfn *readfn; } GuestFDFunctions; =20 static const GuestFDFunctions guestfd_fns[] =3D { [GuestFDHost] =3D { .closefn =3D host_closefn, .writefn =3D host_writefn, + .readfn =3D host_readfn, }, [GuestFDGDB] =3D { .closefn =3D gdb_closefn, .writefn =3D gdb_writefn, + .readfn =3D gdb_readfn, }, }; =20 @@ -551,26 +587,7 @@ target_ulong do_arm_semihosting(CPUARMState *env) return set_swi_errno(ts, -1); } =20 - if (use_gdb_syscalls()) { - arm_semi_syscall_len =3D len; - return arm_gdb_syscall(cpu, arm_semi_cb, "read,%x,%x,%x", - gf->hostfd, arg1, len); - } else { - s =3D lock_user(VERIFY_WRITE, arg1, len, 0); - if (!s) { - /* return bytes not read */ - return len; - } - do { - ret =3D set_swi_errno(ts, read(gf->hostfd, s, len)); - } while (ret =3D=3D -1 && errno =3D=3D EINTR); - unlock_user(s, arg1, len); - if (ret =3D=3D (uint32_t)-1) { - ret =3D 0; - } - /* Return bytes not read */ - return len - ret; - } + return guestfd_fns[gf->type].readfn(ts, cpu, gf, arg1, len); case TARGET_SYS_READC: qemu_log_mask(LOG_UNIMP, "%s: SYS_READC not implemented", __func__= ); return 0; --=20 2.20.1 From nobody Fri Apr 26 07:12:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1568127961; cv=none; d=zoho.com; s=zohoarc; b=QNthSeUrJM98dz3K8RBxHy+yloSQ95TjO/lM9xDWIRwYohrvhQ0MTpJVTvzXHApmLMdGoXC52BDoNNeBwv1tyLwn3sXwlJqwocGesXzAKMRMdwQ152vb0jjdmvIrUXzrJGntip6fmKbsSy5w5SOVbdthQFDnKYWlOTqtdTF2okw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568127961; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=LQ3XAKoDLhaOzqFCNhsIdDGJrHIQSVj/rNDcC6T2wTA=; b=T6hzA6w5yHvq+TxF7ZjTv+xKB9EpgRVrQjFbK0waK2y/JBi5DDQFvvwXtH6JUkGGYfIg6eSYM3sH8xeBg/wyI5/+raovo274RBhNWVHZ8vp8ON8grmE6pkQmJ7iY2v2p6GhLHcQYOpbV4tBb9OvfDj7aSnl6Xv7bJmuZDMTRNAk= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568127961464659.2868614238722; Tue, 10 Sep 2019 08:06:01 -0700 (PDT) Received: from localhost ([::1]:41140 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hiS-0001c3-58 for importer@patchew.org; Tue, 10 Sep 2019 11:06:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54052) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNp-0005VF-Pe for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNo-00052a-MJ for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:41 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:43945) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNo-000520-EV for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:40 -0400 Received: by mail-wr1-x443.google.com with SMTP id q17so16120282wrx.10 for ; Tue, 10 Sep 2019 07:44:40 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=LQ3XAKoDLhaOzqFCNhsIdDGJrHIQSVj/rNDcC6T2wTA=; b=CMo+23GR2ChsncBNW3AD8r9qGAl4f70kTqLT5aG9Jjdja+WFEdwIgiGRU3vUBkHmHK 6g7IHhCCIViRQ7itY+uX+uRkmdTbS6jFCe2GDsFiA+7VDFOPFiQxYrl3BdRIIszrHHQI 8xqKeC4nzfmjr0TuAA0vuez+W9rFcMyhKQLuda3bYuEg3kZ+5c5H0L88rNXiV72liMKa fx4/GDxi3zM6HrfmGQuymVW60BsHXb/JZcHUkYlhonw3vnfSqs/qmJJkUk4FDln6Bghu P/oCKXVqQvg1E+IBmwlHkY5bMUnoQJ4gMXT4SRE28PB1FLi+l7PL7ihgxIe/QOPEkN4F p4tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LQ3XAKoDLhaOzqFCNhsIdDGJrHIQSVj/rNDcC6T2wTA=; b=B2w7VyLQ16nPCj8Dedmjnwmsa7IczSkKa5GJNaU1Y5XgDy1TdzBJAWm6Z5CU206ogW dJKVdGQBtWKrouCA4krjuJKAtQGCHKiyxMmgdc6bV6i42mZ/trCx6v7jLDhfmn2yQxPS ak8yq/D10VGiVQCOr7A97qD8HsohYmbTfuQYo+dVoHoAWB27bdMumwVxGqRsG/U9PIts oQ8ntCfJs5y4YnKfjYKrfh2GDfDI9Gh11dnCdqbLR4y1QbeTdmq8ip6EsNUrbaKU8X+D af1UukRg87ysF4ZdFxc79zDF3/Ht58Hczi9Hjiv4fOljp5G4Ym0aw7jfe8tZM3vM0bEa DdzA== X-Gm-Message-State: APjAAAVcc6FG1CpeKgLPS1uS/YDZW6PL7w+9MFa3+vZULFO0mJtfT6HX k4/NwhhLurPI89KG3/JK2mtUyk0Pe1rhFg== X-Google-Smtp-Source: APXvYqwTSuSRoBntgDj/KzQenDx0sbxiUbk6vUV45WbULXuar7eWM9Ap2TYHPR6H7uvWX1QSDJ/FbQ== X-Received: by 2002:a5d:45c3:: with SMTP id b3mr27791244wrs.207.1568126679618; Tue, 10 Sep 2019 07:44:39 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:23 +0100 Message-Id: <20190910144428.32597-9-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 Subject: [Qemu-devel] [PATCH 08/13] target/arm/arm-semi: Factor out implementation of SYS_ISTTY X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Factor out the implementation of SYS_ISTTY via the new function tables. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e --- target/arm/arm-semi.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 48a10dd3c3a..64ed39fc075 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -349,6 +349,7 @@ typedef uint32_t sys_writefn(TaskState *ts, ARMCPU *cpu= , GuestFD *gf, target_ulong buf, uint32_t len); typedef uint32_t sys_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, target_ulong buf, uint32_t len); +typedef uint32_t sys_isattyfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf); =20 static uint32_t host_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) { @@ -399,6 +400,11 @@ static uint32_t host_readfn(TaskState *ts, ARMCPU *cpu= , GuestFD *gf, return len - ret; } =20 +static uint32_t host_isattyfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) +{ + return isatty(gf->hostfd); +} + static uint32_t gdb_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) { return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd); @@ -420,10 +426,16 @@ static uint32_t gdb_readfn(TaskState *ts, ARMCPU *cpu= , GuestFD *gf, gf->hostfd, buf, len); } =20 +static uint32_t gdb_isattyfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) +{ + return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->hostfd); +} + typedef struct GuestFDFunctions { sys_closefn *closefn; sys_writefn *writefn; sys_readfn *readfn; + sys_isattyfn *isattyfn; } GuestFDFunctions; =20 static const GuestFDFunctions guestfd_fns[] =3D { @@ -431,11 +443,13 @@ static const GuestFDFunctions guestfd_fns[] =3D { .closefn =3D host_closefn, .writefn =3D host_writefn, .readfn =3D host_readfn, + .isattyfn =3D host_isattyfn, }, [GuestFDGDB] =3D { .closefn =3D gdb_closefn, .writefn =3D gdb_writefn, .readfn =3D gdb_readfn, + .isattyfn =3D gdb_isattyfn, }, }; =20 @@ -600,11 +614,7 @@ target_ulong do_arm_semihosting(CPUARMState *env) return set_swi_errno(ts, -1); } =20 - if (use_gdb_syscalls()) { - return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->host= fd); - } else { - return isatty(gf->hostfd); - } + return guestfd_fns[gf->type].isattyfn(ts, cpu, gf); case TARGET_SYS_SEEK: GET_ARG(0); GET_ARG(1); --=20 2.20.1 From nobody Fri Apr 26 07:12:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1568127026; cv=none; d=zoho.com; s=zohoarc; b=BJf0e2CcDPacikrrce0IhI6/6KrDSVSDOWaQK2hRUPPmv+7Xa3Zn7qQfI0Wi/pvJUqrqJSRAO0K4VwboOvXvOnGLeSv+kogbaEGI3ZSrJxBnuVsvWg1RS3uXuOiq7R6LabbIPOF7EGXP8NMKVbshi2rsHA0Px5wod5laVq8wi4w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568127026; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=0rlPylnHuLKixhickeuo5/KvckwQXrJ/eGak0x254JU=; b=nwKee6cNWYnUXBJ5zDJjUVOfeSn4Z2fwOplQd9jw23eIV4Q/46fy/6qROvUvdaODxy1Hxw+QcRZpOgypnWVfgrBcTCR6wYCGQqluQCvxSqm9qdmjW3T2cQL1SGSy8BYz/E20o4BXwRQ5q0dqNWel56hv4OF+CQ9esT/kyXZiNV0= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568127026576999.5498138820395; Tue, 10 Sep 2019 07:50:26 -0700 (PDT) Received: from localhost ([::1]:40874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hTM-0001Zn-JI for importer@patchew.org; Tue, 10 Sep 2019 10:50:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54094) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNr-0005Xi-E4 for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNq-00053l-5I for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:43 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:38285) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNp-000533-VG for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:42 -0400 Received: by mail-wr1-x444.google.com with SMTP id l11so20811355wrx.5 for ; Tue, 10 Sep 2019 07:44:41 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=0rlPylnHuLKixhickeuo5/KvckwQXrJ/eGak0x254JU=; b=TP4FGPJnqWDNNaqsdxqiebobluuX7Dowm18Kz3kHyWoTByhD2xEyf5VfrTm/rDvUA8 FupOUbrQw0+PfwZNxK1C5jmqfo4RuUmi1Bl2Rq0vyb+Tg+wnEI/uhOfe9AbEDfF+pkQ+ VdUvNni/d3lHt/jkQYhNUFMbpYl6+LFoZQqROoYTMn0otdcxzIOdErz4i8mTxrjGhpva 3hbEbqy/JtSmIELAJAaMZ/cYuCu19CNmj34mt/4FsLvp+yLlqKz4uAj1XhG+eHiUEdRQ oumvSysknBVXtsNDO9c/QtZbRKbVRmUJv7SEgAai3fyPy0A9E7IZeC3eM48sRZA8FSK0 Gdxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0rlPylnHuLKixhickeuo5/KvckwQXrJ/eGak0x254JU=; b=iQcEazgp3/tPSab6XnjxQBo/37ppYIasxIfnkVZ/xVP5KEruAJg/5lHupWKUjVTms8 dN2wxhIeBiHdHpXc94An1XJydzdmOj4jEWjkJEbQZs673Sdkjkza4mia4NrxwjEWRw5c 2tiy5o+MU5tfteGywwIQMUxBcPOZbkXN0Fx08iovZqIodDgJnP1DZa1NpUcxI4LBV+/g DlMLJE/KHNop046h0L91/bTndvh91Xu1hose7/skeFI6wlRd7dqqpjg4Hge48cdbSfRZ zC2T+0S3nXEXzaDbqkxT5GCM/vc8qfpZnSqQCVxCKdWs76IN1NCy6Rz2buZUC3ttJrLK La+g== X-Gm-Message-State: APjAAAWIRFdGlMP1AGeEXEQA2Qm6ZHO+yLnie9tO3jXuJhiQMDTpxRLx p4AOgzDChGHE0RcPlUA4Ke1yu0fgV05oXQ== X-Google-Smtp-Source: APXvYqxzNnVOtPKBg+t745zaKlYoFew5shXjJTBch1ItMi5ciaoaQTknMZMn1P1JFsRcCZ3pPW41dg== X-Received: by 2002:adf:ef44:: with SMTP id c4mr28033411wrp.216.1568126681065; Tue, 10 Sep 2019 07:44:41 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:24 +0100 Message-Id: <20190910144428.32597-10-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH 09/13] target/arm/arm-semi: Factor out implementation of SYS_SEEK X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Factor out the implementation of SYS_SEEK via the new function tables. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e --- target/arm/arm-semi.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 64ed39fc075..c548ce849e7 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -350,6 +350,8 @@ typedef uint32_t sys_writefn(TaskState *ts, ARMCPU *cpu= , GuestFD *gf, typedef uint32_t sys_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, target_ulong buf, uint32_t len); typedef uint32_t sys_isattyfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf); +typedef uint32_t sys_seekfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong offset); =20 static uint32_t host_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) { @@ -405,6 +407,16 @@ static uint32_t host_isattyfn(TaskState *ts, ARMCPU *c= pu, GuestFD *gf) return isatty(gf->hostfd); } =20 +static uint32_t host_seekfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong offset) +{ + uint32_t ret =3D set_swi_errno(ts, lseek(gf->hostfd, offset, SEEK_SET)= ); + if (ret =3D=3D (uint32_t)-1) { + return -1; + } + return 0; +} + static uint32_t gdb_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) { return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd); @@ -431,11 +443,19 @@ static uint32_t gdb_isattyfn(TaskState *ts, ARMCPU *c= pu, GuestFD *gf) return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->hostfd); } =20 +static uint32_t gdb_seekfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong offset) +{ + return arm_gdb_syscall(cpu, arm_semi_cb, "lseek,%x,%x,0", + gf->hostfd, offset); +} + typedef struct GuestFDFunctions { sys_closefn *closefn; sys_writefn *writefn; sys_readfn *readfn; sys_isattyfn *isattyfn; + sys_seekfn *seekfn; } GuestFDFunctions; =20 static const GuestFDFunctions guestfd_fns[] =3D { @@ -444,12 +464,14 @@ static const GuestFDFunctions guestfd_fns[] =3D { .writefn =3D host_writefn, .readfn =3D host_readfn, .isattyfn =3D host_isattyfn, + .seekfn =3D host_seekfn, }, [GuestFDGDB] =3D { .closefn =3D gdb_closefn, .writefn =3D gdb_writefn, .readfn =3D gdb_readfn, .isattyfn =3D gdb_isattyfn, + .seekfn =3D gdb_seekfn, }, }; =20 @@ -625,15 +647,7 @@ target_ulong do_arm_semihosting(CPUARMState *env) return set_swi_errno(ts, -1); } =20 - if (use_gdb_syscalls()) { - return arm_gdb_syscall(cpu, arm_semi_cb, "lseek,%x,%x,0", - gf->hostfd, arg1); - } else { - ret =3D set_swi_errno(ts, lseek(gf->hostfd, arg1, SEEK_SET)); - if (ret =3D=3D (uint32_t)-1) - return -1; - return 0; - } + return guestfd_fns[gf->type].seekfn(ts, cpu, gf, arg1); case TARGET_SYS_FLEN: GET_ARG(0); =20 --=20 2.20.1 From nobody Fri Apr 26 07:12:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1568127355; cv=none; d=zoho.com; s=zohoarc; b=PySoKfyzEpGD10pF4VVqf53COZMrZ7/tx4Gd+joXfHxt+8FdvkDbMEzb7u1YU0VN2yo7c6u0vJMc70FcRCUW3QDH1X0GcJZPW8JPkIm/BKpr0HDhbwnXQnW4P+ASjS1+AGMyqDrx8uoA+iO7nHa2Nygb9emwszxzudJoFTpLxlg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568127355; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=sq8nSzuTSE3z6TeW22Jb/p8ysGSeKIUIld6DHEj34Ck=; b=Twql4N9mFTsv2QzA470bAzxjl+zyORw4MrCI256lAwGorjLvX+sh28P64qf72+lMd5RT0N4ISeBkndyrk3IQvmMvqhoTpbvpCCAsuxVydGa1OPpSxUTb5kmHFKITP6BdXwuRiyxOR8bP3gVDLyiz7qCJEiJHj4+CaWVhYDGq/aE= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568127355866959.7506642635037; Tue, 10 Sep 2019 07:55:55 -0700 (PDT) Received: from localhost ([::1]:40992 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hYg-0000Ie-Ay for importer@patchew.org; Tue, 10 Sep 2019 10:55:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54125) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNs-0005Zb-NJ for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNr-00054d-Gn for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:44 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:43945) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNr-000544-9I for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:43 -0400 Received: by mail-wr1-x441.google.com with SMTP id q17so16120609wrx.10 for ; Tue, 10 Sep 2019 07:44:43 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=sq8nSzuTSE3z6TeW22Jb/p8ysGSeKIUIld6DHEj34Ck=; b=vJRR4zhMarIJwOEag+GQp1yXeXT+q/UXt9Xtub70Zzd0iBgHFR+zDca6QkL3KyQrFF d6jtVtMtoVx0jQhhcNC7jmNK1/5GDty5Rk1Lbt04v/3Qg9d7SNU0govHcBdLEL1mawnW /jEdgOl/Fjh/WQ2YyxW8Wvuaus0ak96VghwQvvTVFYD0UUNfdvhFogYqvnXL9ydFz3Dw MHnuvpPut6aHKKU7jvwQEn7vihCg15FIrLr4OVkNUkQcAjgy9uMDn877ZPCHsiyOJ9FA 0U8/NfbaYmKxarb753GB18++ClK8tHper8pHlhsqg8dPa7hCksO/HE/LdgodaFfjNWjB 8Bqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sq8nSzuTSE3z6TeW22Jb/p8ysGSeKIUIld6DHEj34Ck=; b=n229NGgWoTvg7aw28L9CcEycfG/Gk74IoEsHvTfIKnkQeit0TjCYO6uYPKgNsy2tZN ji/dFjJWCknxbeVgyewhOFrtjjOozlDbJ80gbFsCFpoA+yCzzPv0GWPfzRg62XHDFXB/ qEh3LFJq4Ke3oQvoviY3Hjf8Yesk+20su5cUVbB1coMa80HBi3b4YhyIbsL+kqZeHgxW RGOUAAhye/i7fL15EZf8vFRehsT8siDVwfCcEx2yGvw5EIX47My3nyhBUZcUyCQbzDmT hDOFrLl5TOIaEAqBGSqaedUmO7dvnmxH6mbHdhzUSee96fFLaUHjDKKGszL5gakxP2zc oqAw== X-Gm-Message-State: APjAAAVJ/3Jg1abbjJtJvFf+jKLSnQcz1IltV5p0kTN3iATn2Bo8IMud 5437dHau03iGuLQUxppRBhdnRA== X-Google-Smtp-Source: APXvYqycuNOuLYNTE2MIV3o2Pt1YSPVSpDoNIll/5mv4AFS4W99T4R7+XNM9C6WCEJO4SKRziYs1Gw== X-Received: by 2002:adf:f812:: with SMTP id s18mr28610093wrp.32.1568126682426; Tue, 10 Sep 2019 07:44:42 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:25 +0100 Message-Id: <20190910144428.32597-11-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PATCH 10/13] target/arm/arm-semi: Factor out implementation of SYS_FLEN X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Factor out the implementation of SYS_FLEN via the new function tables. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e --- target/arm/arm-semi.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index c548ce849e7..f9019b00b8d 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -352,6 +352,7 @@ typedef uint32_t sys_readfn(TaskState *ts, ARMCPU *cpu,= GuestFD *gf, typedef uint32_t sys_isattyfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf); typedef uint32_t sys_seekfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, target_ulong offset); +typedef uint32_t sys_flenfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf); =20 static uint32_t host_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) { @@ -417,6 +418,16 @@ static uint32_t host_seekfn(TaskState *ts, ARMCPU *cpu= , GuestFD *gf, return 0; } =20 +static uint32_t host_flenfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) +{ + struct stat buf; + uint32_t ret =3D set_swi_errno(ts, fstat(gf->hostfd, &buf)); + if (ret =3D=3D (uint32_t)-1) { + return -1; + } + return buf.st_size; +} + static uint32_t gdb_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) { return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd); @@ -450,12 +461,19 @@ static uint32_t gdb_seekfn(TaskState *ts, ARMCPU *cpu= , GuestFD *gf, gf->hostfd, offset); } =20 +static uint32_t gdb_flenfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) +{ + return arm_gdb_syscall(cpu, arm_semi_flen_cb, "fstat,%x,%x", + gf->hostfd, arm_flen_buf(cpu)); +} + typedef struct GuestFDFunctions { sys_closefn *closefn; sys_writefn *writefn; sys_readfn *readfn; sys_isattyfn *isattyfn; sys_seekfn *seekfn; + sys_flenfn *flenfn; } GuestFDFunctions; =20 static const GuestFDFunctions guestfd_fns[] =3D { @@ -465,6 +483,7 @@ static const GuestFDFunctions guestfd_fns[] =3D { .readfn =3D host_readfn, .isattyfn =3D host_isattyfn, .seekfn =3D host_seekfn, + .flenfn =3D host_flenfn, }, [GuestFDGDB] =3D { .closefn =3D gdb_closefn, @@ -472,6 +491,7 @@ static const GuestFDFunctions guestfd_fns[] =3D { .readfn =3D gdb_readfn, .isattyfn =3D gdb_isattyfn, .seekfn =3D gdb_seekfn, + .flenfn =3D gdb_flenfn, }, }; =20 @@ -657,16 +677,7 @@ target_ulong do_arm_semihosting(CPUARMState *env) return set_swi_errno(ts, -1); } =20 - if (use_gdb_syscalls()) { - return arm_gdb_syscall(cpu, arm_semi_flen_cb, "fstat,%x,%x", - gf->hostfd, arm_flen_buf(cpu)); - } else { - struct stat buf; - ret =3D set_swi_errno(ts, fstat(gf->hostfd, &buf)); - if (ret =3D=3D (uint32_t)-1) - return -1; - return buf.st_size; - } + return guestfd_fns[gf->type].flenfn(ts, cpu, gf); case TARGET_SYS_TMPNAM: qemu_log_mask(LOG_UNIMP, "%s: SYS_TMPNAM not implemented", __func_= _); return -1; --=20 2.20.1 From nobody Fri Apr 26 07:12:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1568128068; cv=none; d=zoho.com; s=zohoarc; b=FkbGffWpYlfKW2QF9QH/ACzybn6jh/CXtpK8ub5yh8JTkz1y1KBG5ugv2RzipWIPgrP/db8ydY4Jbtm726KBsJ/9lZmCsPG0AOxczaST3xvsxMD/Ee5nvXjuFWTAzx2nR1k+vKsvBLhEzqBoJAC31QrdGhBx/iMvjTRRLZ5ulrg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568128068; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=HFFhnwi1XTh3mteeZB/9qILvDTOSvSbdeT/3s5BHyng=; b=UjCV7cO+98EHd/ekBW47C881aCBCgtaZgIaG0QMagLPhhKxh2NbPBlSvupFey0mWk00kzlf/sJjjWUzTzbLA4K3ySIpiPN9JZwoIk4UGBG8w6OmoLhxNQwxdbr4/hJzZn1L4obl2XTMO+elmqBs9X+iPI8Qj4vQoQC3aagNmi10= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568128068782885.4977565003297; Tue, 10 Sep 2019 08:07:48 -0700 (PDT) Received: from localhost ([::1]:41176 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hkB-0004RC-I5 for importer@patchew.org; Tue, 10 Sep 2019 11:07:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54160) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNu-0005bU-7l for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNs-00055f-ME for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:45 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:43947) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNs-000558-FA for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:44 -0400 Received: by mail-wr1-x443.google.com with SMTP id q17so16120736wrx.10 for ; Tue, 10 Sep 2019 07:44:44 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=HFFhnwi1XTh3mteeZB/9qILvDTOSvSbdeT/3s5BHyng=; b=z0OXDxHK0OAM37pLD3qWAdkOd2MXOAjoEsXOa6/rmAaP3RxEgFPj+MkEEe2R5xmLyT N6Dmh4rlbm6D6Vet9Hp894dXJC+t8qEmC71ryNd0RW+HVcQDe5iCzPxr5Rqn49TAm3BQ AnCXv1eZ/FxwkMeZZ3G9yrEB+uCz53JO9cRicduZQO+8o3IkG/xVTlzDVLZ73oYpZ/2C yyIn7kMqwf0R0pQ+jLcrTC9Xvh8cokBxF0bN/XtySXYZs1gcf+J/ah3cg1+P6ypD+r9H KYb6pKaqYnMWJMv7iiwLor32Ucz7L46Y+P7Myse0E7ivB/R5AWUPYDJMzRPmgZNFIxWE kdbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HFFhnwi1XTh3mteeZB/9qILvDTOSvSbdeT/3s5BHyng=; b=MQf6IAKMOqSPT4xVnmOKEdYQJaviyo/HFtt8MhhGOXWbvzk5Oii4mJJnUfEoIuNjgI Evg4Jz0t5TbWJFv2EF9YDdRRDeTcQeWHMrc4EyPqCyXxnOZEyW85m0uh7B1YVVc373Rp D+X0EUgZ87Invt8PEKg5y/PHe0TGQCMV/VROWm//ktLO1TvGp3aPana7L3jYV8998kub kctEHdG1d+cyqS0eiciVabE8r0s0ItSNuc0yzKGW0HgJaaosbIOzCteVBQNV/JO3Dlr6 UiiE2JGkwAa76cc6jlVInHuaRpcpYHZaYRU/0UJGeu0tW+chvQ0xAtojbYA9jLla4cq5 UjSg== X-Gm-Message-State: APjAAAXnza2FlBCFPistzKbP/pR8YHfLCIxKUZ4xU584+O7dtEYFl/jh XMe+AYo9fHnSwuAmdXVTPok5jQ== X-Google-Smtp-Source: APXvYqxOpSw0ENil0jtjZ3fVle80ExjXe/59M0PvW6ehdObFPjGLayobeFcun36dpUL6hl0rRdWCXA== X-Received: by 2002:adf:f543:: with SMTP id j3mr8291026wrp.243.1568126683569; Tue, 10 Sep 2019 07:44:43 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:26 +0100 Message-Id: <20190910144428.32597-12-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 Subject: [Qemu-devel] [PATCH 11/13] target/arm/arm-semi: Implement support for semihosting feature detection X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Version 2.0 of the semihosting specification added support for allowing a guest to detect whether the implementation supported particular features. This works by the guest opening a magic file ":semihosting-features", which contains a fixed set of data with some magic numbers followed by a sequence of bytes with feature flags. The file is expected to behave sensibly for the various semihosting calls which operate on files (SYS_FLEN, SYS_SEEK, etc). Implement this as another kind of guest FD using our function table dispatch mechanism. Initially we report no extended features, so we have just one feature flag byte which is zero. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e --- target/arm/arm-semi.c | 107 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-) diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index f9019b00b8d..531084b7799 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -117,6 +117,7 @@ typedef enum GuestFDType { GuestFDUnused =3D 0, GuestFDHost =3D 1, GuestFDGDB =3D 2, + GuestFDFeatureFile =3D 3, } GuestFDType; =20 /* @@ -125,7 +126,10 @@ typedef enum GuestFDType { */ typedef struct GuestFD { GuestFDType type; - int hostfd; + union { + int hostfd; + target_ulong featurefile_offset; + }; } GuestFD; =20 static GArray *guestfd_array; @@ -467,6 +471,87 @@ static uint32_t gdb_flenfn(TaskState *ts, ARMCPU *cpu,= GuestFD *gf) gf->hostfd, arm_flen_buf(cpu)); } =20 +#define SHFB_MAGIC_0 0x53 +#define SHFB_MAGIC_1 0x48 +#define SHFB_MAGIC_2 0x46 +#define SHFB_MAGIC_3 0x42 + +static const uint8_t featurefile_data[] =3D { + SHFB_MAGIC_0, + SHFB_MAGIC_1, + SHFB_MAGIC_2, + SHFB_MAGIC_3, + 0, /* Feature byte 0 */ +}; + +static void init_featurefile_guestfd(int guestfd) +{ + GuestFD *gf =3D do_get_guestfd(guestfd); + + assert(gf); + gf->type =3D GuestFDFeatureFile; + gf->featurefile_offset =3D 0; +} + +static uint32_t featurefile_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *g= f) +{ + /* Nothing to do */ + return 0; +} + +static uint32_t featurefile_writefn(TaskState *ts, ARMCPU *cpu, GuestFD *g= f, + target_ulong buf, uint32_t len) +{ + /* This fd can never be open for writing */ + errno =3D EBADF; + return set_swi_errno(ts, -1); +} + +static uint32_t featurefile_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong buf, uint32_t len) +{ + uint32_t i; +#ifndef CONFIG_USER_ONLY + CPUARMState *env =3D &cpu->env; +#endif + char *s; + + s =3D lock_user(VERIFY_WRITE, buf, len, 0); + if (!s) { + return len; + } + + for (i =3D 0; i < len; i++) { + if (gf->featurefile_offset >=3D sizeof(featurefile_data)) { + break; + } + s[i] =3D featurefile_data[gf->featurefile_offset]; + gf->featurefile_offset++; + } + + unlock_user(s, buf, len); + + /* Return number of bytes not read */ + return len - i; +} + +static uint32_t featurefile_isattyfn(TaskState *ts, ARMCPU *cpu, GuestFD *= gf) +{ + return 0; +} + +static uint32_t featurefile_seekfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong offset) +{ + gf->featurefile_offset =3D offset; + return 0; +} + +static uint32_t featurefile_flenfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) +{ + return sizeof(featurefile_data); +} + typedef struct GuestFDFunctions { sys_closefn *closefn; sys_writefn *writefn; @@ -493,6 +578,14 @@ static const GuestFDFunctions guestfd_fns[] =3D { .seekfn =3D gdb_seekfn, .flenfn =3D gdb_flenfn, }, + [GuestFDFeatureFile] =3D { + .closefn =3D featurefile_closefn, + .writefn =3D featurefile_writefn, + .readfn =3D featurefile_readfn, + .isattyfn =3D featurefile_isattyfn, + .seekfn =3D featurefile_seekfn, + .flenfn =3D featurefile_flenfn, + }, }; =20 /* Read the input value from the argument block; fail the semihosting @@ -586,6 +679,18 @@ target_ulong do_arm_semihosting(CPUARMState *env) unlock_user(s, arg0, 0); return guestfd; } + if (strcmp(s, ":semihosting-features") =3D=3D 0) { + unlock_user(s, arg0, 0); + /* We must fail opens for modes other than 0 ('r') or 1 ('rb')= */ + if (arg1 !=3D 0 && arg1 !=3D 1) { + dealloc_guestfd(guestfd); + errno =3D EINVAL; + return set_swi_errno(ts, -1); + } + init_featurefile_guestfd(guestfd); + return guestfd; + } + if (use_gdb_syscalls()) { ret =3D arm_gdb_syscall(cpu, arm_semi_cb, "open,%s,%x,1a4", ar= g0, (int)arg2+1, gdb_open_modeflags[arg1]); --=20 2.20.1 From nobody Fri Apr 26 07:12:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1568127242; cv=none; d=zoho.com; s=zohoarc; b=Tt4idBUq/QGF8tOcZpySYOU+lrgxA9gV7gL1g88ZdeaIB5ePQxbZ6PxPAubaNDc1c73Jurw7ACq4pHtOKKv3HaJahz3174Mn4rEn5TCuVZQQ3SUYLmHeV7VOnjIGIkwHOIPxUwU3W3Ihkmd9qkiWhIuApiaXdjjBZHgQ7Hv0hA0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568127242; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=LA9MpYwh3mZJWgj+jicjrA5Nt9K2oC0TJFXiZTBybLY=; b=daZKVvf4+C990+UkWKRRKW9b84ozwLV8Di19Y+ep9BWw4NcNpxeEl7G2jFykNIV7wVGsakHewzvhsyv9+LC//nsgVc9m4WFKVd2vOI7uCCau2gnQnCSlM0Hur/dPpwHUEJ37B6cTHNVsiCzD/aWy3PXEhSU2MzLlueVHDxMInek= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568127242804651.0934116200161; Tue, 10 Sep 2019 07:54:02 -0700 (PDT) Received: from localhost ([::1]:40956 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hWp-0006BF-3Q for importer@patchew.org; Tue, 10 Sep 2019 10:53:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54170) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNu-0005cO-NB for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNt-00056U-Id for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:46 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:38283) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNt-00055p-Cc for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:45 -0400 Received: by mail-wr1-x441.google.com with SMTP id l11so20811753wrx.5 for ; Tue, 10 Sep 2019 07:44:45 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=LA9MpYwh3mZJWgj+jicjrA5Nt9K2oC0TJFXiZTBybLY=; b=frJtnUdJmrWMbeMlSI4ZaC0DUyjKF0jSF2ar0QTkVt4vqGH414/fh6f4cec6hioWgF bVubc+ZbCy4Zo3wNxyPpHzUhpokvzCpCmZqwWqCC5mLxtYx/8FULeoW/FY/nU2iQN8Er DuGebK8eZNhACwvJFAoB/FGyYGaeS9Mn3OGNcHR9teG34gNKscxSXh8fHKYz46GrYXVX 6K2vRrSfWYqDa8BBT3sQlxmaAWLzAX8sS8nSRduDQaD4hoU9zMA8yMV6/Zp1tyewgaZx wOUO5rni+XYUAy7LrGmqcDGyquC9yi8NqaQxRq9I3qZPNDbdsqw36Kq1lYIbQmRxFSJD UGEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LA9MpYwh3mZJWgj+jicjrA5Nt9K2oC0TJFXiZTBybLY=; b=CcjyoUPpwu+Ut9fbSnMPaKtHsVQew+r3HUdODN6HbGP5X/znwaOoVYiC+xUMA3twNE 9HDxKNssh9bLjcJ4Lmom/dD6czrYwmj55eEvEfdbfkirEuUZW21nu9uvMgbkqEVGIeGi dVlb0A+iiu6AWFOhpH+O4Co7Gb7KPnw/khN8wXK8G1sJexOmk43GCFJ3Nm54zlyDPjC2 dxcC+NEf/Cnzk4LlEbZRdjo06PAUc56fJhQyxDi0utIHt6061BLT1Oi+7Yf2rUarQxUz NzrqOGwLlWAhPjl0/AZotiGlTumYaS+M8dQ4KBLp23JG16CXc2EO2J780zt3/BtltA9/ 9B5A== X-Gm-Message-State: APjAAAV91vJa1869WdwqGgNt/qpWfiIN5Ntz5gx8BVx+0ISoVCLkdOkZ XsLyCJhwgvy2TsALG1y6pjT1wg== X-Google-Smtp-Source: APXvYqzEu8Q/xrdaKHc4se1g7ZV8yWQprAf22K23XdhGAuPSd4Tojsw0iUdzXRFk92QuOuXniznGOg== X-Received: by 2002:adf:e392:: with SMTP id e18mr28592507wrm.87.1568126684565; Tue, 10 Sep 2019 07:44:44 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:27 +0100 Message-Id: <20190910144428.32597-13-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::441 Subject: [Qemu-devel] [PATCH 12/13] target/arm/arm-semi: Implement SH_EXT_STDOUT_STDERR extension X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" SH_EXT_STDOUT_STDERR is a v2.0 semihosting extension: the guest can open ":tt" with a file mode requesting append access in order to open stderr, in addition to the existing "open for read for stdin or write for stdout". Implement this and report it via the :semihosting-features data. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e --- target/arm/arm-semi.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 531084b7799..0df8d4d69d6 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -476,12 +476,16 @@ static uint32_t gdb_flenfn(TaskState *ts, ARMCPU *cpu= , GuestFD *gf) #define SHFB_MAGIC_2 0x46 #define SHFB_MAGIC_3 0x42 =20 +/* Feature bits reportable in feature byte 0 */ +#define SH_EXT_EXIT_EXTENDED (1 << 0) +#define SH_EXT_STDOUT_STDERR (1 << 1) + static const uint8_t featurefile_data[] =3D { SHFB_MAGIC_0, SHFB_MAGIC_1, SHFB_MAGIC_2, SHFB_MAGIC_3, - 0, /* Feature byte 0 */ + SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; =20 static void init_featurefile_guestfd(int guestfd) @@ -674,7 +678,21 @@ target_ulong do_arm_semihosting(CPUARMState *env) } =20 if (strcmp(s, ":tt") =3D=3D 0) { - int result_fileno =3D arg1 < 4 ? STDIN_FILENO : STDOUT_FILENO; + int result_fileno; + + /* + * We implement SH_EXT_STDOUT_STDERR, so: + * open for read =3D=3D stdin + * open for write =3D=3D stdout + * open for append =3D=3D stderr + */ + if (arg1 < 4) { + result_fileno =3D STDIN_FILENO; + } else if (arg1 < 8) { + result_fileno =3D STDOUT_FILENO; + } else { + result_fileno =3D STDERR_FILENO; + } associate_guestfd(guestfd, result_fileno); unlock_user(s, arg0, 0); return guestfd; --=20 2.20.1 From nobody Fri Apr 26 07:12:06 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1568127420; cv=none; d=zoho.com; s=zohoarc; b=JCJf6hZYfGke19ZkDSt5yXIr2eGlOeHTs6YB8lIJxD0Sb+zRDMUIGSNxebs7Dr5d8MbSvWJ1aWRKiK4nq/C6zQfVqYDuT/w9X57KLLzMZDpw3VRpqdCKh/iR/1TIrvKKQJAiXpDM6KEDcgMy9m0qP84Rfyiwd56SIAOIKtg5NRU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568127420; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=YNt4rzxDLZvJ3mLelApZg/g3aGU83zBv6U6suQNcbas=; b=PoT7V4zvXziCKW3EWR6kLPTUBAdV/1sMlTiYdOUUUEu4AQ6z8Z49SblFUO5ePNGEl/7a42fQ/uKADkDh/H0A+7htcKLec8GpgOWdXG2Mc3zRcypXu6Bh+1D70I642/pxdJBOuI7CPfkSHFa0VQzo/nXzw4B3Hci7KPUTBOfMb3Q= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568127420538172.4283810485341; Tue, 10 Sep 2019 07:57:00 -0700 (PDT) Received: from localhost ([::1]:41002 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hZj-0001Uc-2J for importer@patchew.org; Tue, 10 Sep 2019 10:56:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54202) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNv-0005e6-Nf for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNu-00057E-Je for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:47 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:33653) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNu-00056k-EE for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:46 -0400 Received: by mail-wr1-x444.google.com with SMTP id u16so20875157wrr.0 for ; Tue, 10 Sep 2019 07:44:46 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=YNt4rzxDLZvJ3mLelApZg/g3aGU83zBv6U6suQNcbas=; b=FpfoOZur9SeiO5+ovdwDYbHq6hgY6rbpK/dv9x8sQf3BJy2GaAu7MQuZ1a2E3E0XDT YVs0B5uMpkF9uag6dPn7MlYSKCo0zmuLggIJJVhvKllv10u96rc05E5vWgsdlLN4VaHZ sI15QxR7jvaDBR6COKIkQSCcPXZ6QSB2ssG4UvWxNzTLBT5x7GQ+mnRZLv2s0V5YQ3xI hpEvXUl3qo4W5YzjIBteUUC1YjXlUtpNrzrg3lzLyc6htpvPMs4D1YfpiL4sFYc9H4Hz +LUox7B3Sdu084rI+Z7jZqdkeE97Uj6xVJaObKt0+NwX34vUCz+rgQb5NlRVDXbyN38b W2Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YNt4rzxDLZvJ3mLelApZg/g3aGU83zBv6U6suQNcbas=; b=D6bEWIWeM1BtUe1giOFQTMZ00geRL16d/GW7jCeA/OdzNtI2E7OS8mRnWYM59RA2wi 5LpyjfxLd6nfLAeR7Dzfq0+NAXei69DSAwPNjGdJBSiVOgDCbIZsXgzGandkge5iUPCk DKadir44vyYqkD4KWX45MY39L8hthH8PFr4romXW3SSphoB7ZqUjogqwpVHu96xbULXZ 9zPjPv1IHHQK1zBdSY829iAe64be0Q4QBiBnfHvfpPqJz6SKnQrNJM3eviA1cdJYFpwO dGWo7UBy8AQ/F8WrvZbsr+E6Ge7LPSciCPKtpH020ZkP8AWBs0uycElPxqc67RjtHCMO M/bg== X-Gm-Message-State: APjAAAUbuAd4RwGYZVdRquUqvqLg0g4AZin9esjP2yYc62P2PAD5D9pJ Ek0PvBPLMVa6gFr4Mr5Uibzw8Q== X-Google-Smtp-Source: APXvYqwx169BXXSViKCvBrdjzswbjoKZruNrZlvFksLoy7E9pkzfI/C8dUbG9BwTNzoNOA/Qd5jcmg== X-Received: by 2002:a05:6000:1189:: with SMTP id g9mr28272944wrx.117.1568126685607; Tue, 10 Sep 2019 07:44:45 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:28 +0100 Message-Id: <20190910144428.32597-14-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::444 Subject: [Qemu-devel] [PATCH 13/13] target/arm/arm-semi: Implement SH_EXT_EXIT_EXTENDED extension X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" SH_EXT_EXIT_EXTENDED is a v2.0 semihosting extension: it indicates that the implementation supports the SYS_EXIT_EXTENDED function. This function allows both A64 and A32/T32 guests to exit with a specified exit status, unlike the older SYS_EXIT function which only allowed this for A64 guests. Implement this extension. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e --- target/arm/arm-semi.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 0df8d4d69d6..3900bd4e1e6 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -66,6 +66,7 @@ typedef void TaskState; #define TARGET_SYS_HEAPINFO 0x16 #define TARGET_SYS_EXIT 0x18 #define TARGET_SYS_SYNCCACHE 0x19 +#define TARGET_SYS_EXIT_EXTENDED 0x20 =20 /* ADP_Stopped_ApplicationExit is used for exit(0), * anything else is implemented as exit(1) */ @@ -485,7 +486,7 @@ static const uint8_t featurefile_data[] =3D { SHFB_MAGIC_1, SHFB_MAGIC_2, SHFB_MAGIC_3, - SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ + SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; =20 static void init_featurefile_guestfd(int guestfd) @@ -1026,11 +1027,14 @@ target_ulong do_arm_semihosting(CPUARMState *env) return 0; } case TARGET_SYS_EXIT: - if (is_a64(env)) { + case TARGET_SYS_EXIT_EXTENDED: + if (nr =3D=3D TARGET_SYS_EXIT_EXTENDED || is_a64(env)) { /* - * The A64 version of this call takes a parameter block, + * The A64 version of SYS_EXIT takes a parameter block, * so the application-exit type can return a subcode which * is the exit status code from the application. + * SYS_EXIT_EXTENDED is an a new-in-v2.0 optional function + * which allows A32/T32 guests to also provide a status code. */ GET_ARG(0); GET_ARG(1); @@ -1042,8 +1046,10 @@ target_ulong do_arm_semihosting(CPUARMState *env) } } else { /* - * ARM specifies only Stopped_ApplicationExit as normal - * exit, everything else is considered an error + * The A32/T32 version of SYS_EXIT specifies only + * Stopped_ApplicationExit as normal exit, but does not + * allow the guest to specify the exit status code. + * Everything else is considered an error. */ ret =3D (args =3D=3D ADP_Stopped_ApplicationExit) ? 0 : 1; } --=20 2.20.1