]> git.proxmox.com Git - mirror_qemu.git/commitdiff
target/arm/arm-semi: Don't let the guest close stdin/stdout/stderr
authorPeter Maydell <peter.maydell@linaro.org>
Thu, 30 Jan 2020 16:02:01 +0000 (16:02 +0000)
committerPeter Maydell <peter.maydell@linaro.org>
Thu, 30 Jan 2020 16:02:01 +0000 (16:02 +0000)
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 <peter.maydell@linaro.org>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-id: 20200124172954.28481-1-peter.maydell@linaro.org

target/arm/arm-semi.c

index 788fe61b51add73e00684bece1eab810c3217934..8718fd019480fbf3f10ea0b01eb0d3f91b4131c5 100644 (file)
@@ -403,6 +403,15 @@ static uint32_t host_closefn(ARMCPU *cpu, GuestFD *gf)
 {
     CPUARMState *env = &cpu->env;
 
+    /*
+     * Only close the underlying host fd if it's one we opened on behalf
+     * of the guest in SYS_OPEN.
+     */
+    if (gf->hostfd == STDIN_FILENO ||
+        gf->hostfd == STDOUT_FILENO ||
+        gf->hostfd == STDERR_FILENO) {
+        return 0;
+    }
     return set_swi_errno(env, close(gf->hostfd));
 }