diff options
author | Peter Maydell | 2020-01-30 17:02:01 +0100 |
---|---|---|
committer | Peter Maydell | 2020-01-30 17:02:01 +0100 |
commit | 16ab12a936ef96b25be7f5981c96548fa772f3df (patch) | |
tree | f0e22448b6c115ae3e4d7bb9d9e7f56e6820bfac /target/arm/arm-semi.c | |
parent | hw/core/or-irq: Fix incorrect assert forbidding num-lines == MAX_OR_LINES (diff) | |
download | qemu-16ab12a936ef96b25be7f5981c96548fa772f3df.tar.gz qemu-16ab12a936ef96b25be7f5981c96548fa772f3df.tar.xz qemu-16ab12a936ef96b25be7f5981c96548fa772f3df.zip |
target/arm/arm-semi: Don't let the guest close stdin/stdout/stderr
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
Diffstat (limited to 'target/arm/arm-semi.c')
-rw-r--r-- | target/arm/arm-semi.c | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 788fe61b51..8718fd0194 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 = &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)); } |