From nobody Mon Feb 9 04:10:55 2026 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 ARC-Seal: i=1; a=rsa-sha256; t=1579887097; cv=none; d=zohomail.com; s=zohoarc; b=VXICHzsZebFp0ENpWWg6YxngO7IEUiuuQq85z0ZgLcRFe8tTcopEQwQbpHt0NV8hHP84DSF548l23mKQPvFUkmmwf4jItAw70u50qwYyhHKl/hQf/C8HG6k/VfpJwCC/RDQfjkpLfY02PGiFbxZ5nOXkK9s7qzzAiUcwbaEU1Zw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1579887097; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=tb/hBOQ/Z9evM7DGTBEiJ196hd0t4e21Je7XZaNWrmU=; b=dpxX+F0j2/Jux8Ee9AE3eF+k+lXSYxoCnjIt6ZhLhHAPFqjbP+1r3VYQ5mYbzuBMtmisOV5dPXJODCTNKnqWrAsjgGlF5hX7b4BRO0uXG+hoRomRlqeitAGNGchBeTw83Inc9Kosr+j6yfY2zD+PlzjoB9smITA5g2SxdkMrm6g= ARC-Authentication-Results: i=1; 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 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 1579887097794858.4665543353562; Fri, 24 Jan 2020 09:31:37 -0800 (PST) Received: from localhost ([::1]:45770 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iv2nw-00013M-Iq for importer@patchew.org; Fri, 24 Jan 2020 12:31:36 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:55081) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iv2mP-0000AS-Jc for qemu-devel@nongnu.org; Fri, 24 Jan 2020 12:30:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iv2mO-0000v6-EE for qemu-devel@nongnu.org; Fri, 24 Jan 2020 12:30:01 -0500 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]:54355) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iv2mO-0000rv-7v for qemu-devel@nongnu.org; Fri, 24 Jan 2020 12:30:00 -0500 Received: by mail-wm1-x343.google.com with SMTP id g1so226079wmh.4 for ; Fri, 24 Jan 2020 09:29:58 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id x11sm7501504wmg.46.2020.01.24.09.29.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jan 2020 09:29:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tb/hBOQ/Z9evM7DGTBEiJ196hd0t4e21Je7XZaNWrmU=; b=iKF4oxnWP84MlYolKGatOyonemJkmGoaSaAr03QZ+jEFV/fPGwHDv3joyiKk8BtchE MXq0aHW0nRB3CkrWaTO0CHfJ1m9GqwjyskLYnW+ZTiLRw4v1579ch1aVjpMjH0NH+pI3 M0i78E8p7kTSi1yar2CRqdKMI2ldgtejlHSuoZjrTboG4c3uuTTo5mfge4tiXXDIuDZ7 nzxa3i1nSmmtD24cDUDAQzHd7cZOQaOcKDBtT0jmRJMkBAC43XCGDsLISaY2IpURuWtP VNrnD/zFHFBlfGI+l5pZWe/vpncXg+5n7iGbY0joVERzrNJ357VwbwE12QTSZEP6l1NV gqMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=tb/hBOQ/Z9evM7DGTBEiJ196hd0t4e21Je7XZaNWrmU=; b=NfpGW+xNSerhTY6spyJbQJt0rnGZQ2dLOnzj5eS6o6Hs9U9s1gxgJBPvxgnO5U86qC 0Q7XbE40mCm5E2rMcyW7n3NgsFZs0o4arE9NqEPFq2AnNSli6Icn2+KQNOjX5cPmzLrA o/kMDY2NAE1Rph7bJg1u/lAE7JG0YsVG7x8n7IahF4EldkEC35wcZ9yRDNbsOKkI9zmi 4ShuiTdT2j+/GKG0gMM2KuNBbF2X1RcfMLBgyIsf16FCx6mx/olijDgeS6nwKU00vrxL pJlpEPgZ+4nB2hfQUKJ0ijWbqNtVHhM3OI8EU+FRiofKUBzYpJzTOjdUhkhrCZuPNAW/ eEdQ== X-Gm-Message-State: APjAAAXe9tP8UK7NUGKPzOS0hmDyICgZS6B7kXBAjIp3olq3zWBRpAFo t7Jojv1rtvJvFIfo77JtQVpisw== X-Google-Smtp-Source: APXvYqzprLQgzsPoOViMeaJTy2NsMFrgToy5Mi9igaT59v6tbvyEN1q4wMHhg2cSALLFQJvdkTBpEQ== X-Received: by 2002:a1c:b603:: with SMTP id g3mr246049wmf.133.1579886997665; Fri, 24 Jan 2020 09:29:57 -0800 (PST) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Subject: [PATCH] target/arm/arm-semi: Don't let the guest close stdin/stdout/stderr Date: Fri, 24 Jan 2020 17:29:54 +0000 Message-Id: <20200124172954.28481-1-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 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::343 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: , Cc: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) Content-Type: text/plain; charset="utf-8" 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 --- 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