* [PATCH] target/arm/arm-semi: Don't let the guest close stdin/stdout/stderr
@ 2020-01-24 17:29 Peter Maydell
2020-01-24 19:57 ` Alex Bennée
0 siblings, 1 reply; 3+ messages in thread
From: Peter Maydell @ 2020-01-24 17:29 UTC (permalink / raw)
To: qemu-arm, qemu-devel; +Cc: Alex Bennée
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>
---
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 = &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));
}
--
2.20.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] target/arm/arm-semi: Don't let the guest close stdin/stdout/stderr
2020-01-24 17:29 [PATCH] target/arm/arm-semi: Don't let the guest close stdin/stdout/stderr Peter Maydell
@ 2020-01-24 19:57 ` Alex Bennée
2020-01-27 7:49 ` Philippe Mathieu-Daudé
0 siblings, 1 reply; 3+ messages in thread
From: Alex Bennée @ 2020-01-24 19:57 UTC (permalink / raw)
To: Peter Maydell; +Cc: qemu-arm, qemu-devel
Peter Maydell <peter.maydell@linaro.org> writes:
> 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>
> ---
> 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 = &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));
> }
--
Alex Bennée
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] target/arm/arm-semi: Don't let the guest close stdin/stdout/stderr
2020-01-24 19:57 ` Alex Bennée
@ 2020-01-27 7:49 ` Philippe Mathieu-Daudé
0 siblings, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2020-01-27 7:49 UTC (permalink / raw)
To: Alex Bennée, Peter Maydell; +Cc: qemu-arm, qemu-devel
On 1/24/20 8:57 PM, Alex Bennée wrote:
> Peter Maydell <peter.maydell@linaro.org> writes:
>
>> 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>
>> ---
>> 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 = &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));
>> }
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-01-27 7:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-24 17:29 [PATCH] target/arm/arm-semi: Don't let the guest close stdin/stdout/stderr Peter Maydell
2020-01-24 19:57 ` Alex Bennée
2020-01-27 7:49 ` Philippe Mathieu-Daudé
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.