From nobody Thu Dec 18 22:26:04 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.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=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1580401049346871.4029223906689; Thu, 30 Jan 2020 08:17:29 -0800 (PST) Received: from localhost ([::1]:35066 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ixCVU-0006zq-66 for importer@patchew.org; Thu, 30 Jan 2020 11:17:28 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42975) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ixCTl-0005D1-IV for qemu-devel@nongnu.org; Thu, 30 Jan 2020 11:15:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ixCTj-0002nh-I9 for qemu-devel@nongnu.org; Thu, 30 Jan 2020 11:15:41 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:35687) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ixCTj-0002ms-C9 for qemu-devel@nongnu.org; Thu, 30 Jan 2020 11:15:39 -0500 Received: by mail-wr1-x443.google.com with SMTP id g17so4826026wro.2 for ; Thu, 30 Jan 2020 08:15:39 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a22sm6994442wmd.20.2020.01.30.08.15.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Jan 2020 08:15:37 -0800 (PST) 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=toXoJk3kWKWDO6UmwWx0b6Nlul4ANvuG6q0d24EnKXQ=; b=X2XyrrVhUwOVshAUgEsnyTu9eoKCB57WH0tVejYJhQ5oYqupu2u15o8bcYq8F7ldH0 JgrTwyG2Dtm7+x/GJsCn66wOlOukQxLm9pxTbzrT/NWi/Zyk0KBi0nSsLRsRu5LKpDRP 47DDktESraA4iD8GtPWV2QSlVgFm4HpNcZV4AQSVDq6xQkxXFMZwaBaWx/nhfu3hk9fI SCJ7cLUjW8sZcQcJWswDx9KAMErdwg7uCGLGxOAbhVGRMsSuUKeoZVUnvSMqMfVmkqxN hhyUVa+su2JM3S8uHYWEpmh77gXoFIuzcKHkL4Wm351IjMP0lpFGCzYXr2G1ntpk/Cv/ y2Ag== 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=toXoJk3kWKWDO6UmwWx0b6Nlul4ANvuG6q0d24EnKXQ=; b=ass1DmNA24SnhbioEqIcWRwhcn2k6O92u/Dach0QkPmIoLJOAWn2ozydil7/RCjM03 WSkVJfcrUZzIglp3Z2zWP3aZ+k3AfXQBjilAOlaLWa0sUqP0CQRUU4sECFpT0JnOKb6r H19fYDZGoSYDl+E2LaisgEXE+ra4/jBpf6XPIKUtFgoGJ1ZFydKTeCxsCfSkTZETE5+U 5mGcgD4h+z3ybBMtTE4Gb711eKdDtAdBX6oXV6j8ooVvcREtDulel0ub/UZV5+/8Txf6 KdA8pmfaYhcb9eU1a/wZXUlr6tFpcMBeY7v12wKbV7od235bb5xVRI1fbTmPSN8Q1rgA y1bA== X-Gm-Message-State: APjAAAV2E0Y8oe2NMkmC7MSpPmEPrk3EhV87yXVdgV1YBuF82NV9SsV9 zRYbTLMZlA+/RNVETPzXNUzFhXKUkRB8dw== X-Google-Smtp-Source: APXvYqyd8wRwCRMYXC15aGDi6OfNDcsly+vVxS35QozWXkKJL0wi0aUQ10hikWYve1K8R3WpWwZqBQ== X-Received: by 2002:adf:f484:: with SMTP id l4mr6757720wro.207.1580400938111; Thu, 30 Jan 2020 08:15:38 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 02/26] target/arm/arm-semi: Don't let the guest close stdin/stdout/stderr Date: Thu, 30 Jan 2020 16:15:09 +0000 Message-Id: <20200130161533.8180-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200130161533.8180-1-peter.maydell@linaro.org> References: <20200130161533.8180-1-peter.maydell@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 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: pass (identity @linaro.org) The guest can use the semihosting API to open a handle corresponding to QEMU's own stdin, stdout, or stderr. When the guest closes this handle, we should not close the underlying host stdin/stdout/stderr the way we would do if the handle corresponded to a host fd we'd opened on behalf of the guest in SYS_OPEN. Signed-off-by: Peter Maydell Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Philippe Mathieu-Daud=C3=A9 Message-id: 20200124172954.28481-1-peter.maydell@linaro.org --- target/arm/arm-semi.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 788fe61b51a..8718fd01948 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -403,6 +403,15 @@ static uint32_t host_closefn(ARMCPU *cpu, GuestFD *gf) { CPUARMState *env =3D &cpu->env; =20 + /* + * Only close the underlying host fd if it's one we opened on behalf + * of the guest in SYS_OPEN. + */ + if (gf->hostfd =3D=3D STDIN_FILENO || + gf->hostfd =3D=3D STDOUT_FILENO || + gf->hostfd =3D=3D STDERR_FILENO) { + return 0; + } return set_swi_errno(env, close(gf->hostfd)); } =20 --=20 2.20.1