[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v3 09/49] semihosting: Adjust error checking in common_semi_c
From: |
Peter Maydell |
Subject: |
Re: [PATCH v3 09/49] semihosting: Adjust error checking in common_semi_cb |
Date: |
Mon, 23 May 2022 16:44:18 +0100 |
On Mon, 23 May 2022 at 16:35, Richard Henderson
<richard.henderson@linaro.org> wrote:
> On 5/23/22 05:13, Peter Maydell wrote:
> > The gdb implementation of the isatty call returns 0 or 1 on
> > success, and -1 on failure (though the only failure mode it has
> > is "you messed up the protocol packet format"):
> > https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gdb/remote-fileio.c;h=fe191fb6069a53a3844656a81e77069afa781946;hb=HEAD#l1039
>
> Technically, isatty = 0 is failure not success and should also set ENOTTY.
There are multiple different APIs here with similar names but
not necessarily always the exact same behaviour in all cases:
Arm semihosting SYS_ISTTY:
https://github.com/ARM-software/abi-aa/blob/main/semihosting/semihosting.rst#sys-istty-0x09
returns 1 if the handle identifies an interactive device.
0 if the handle identifies a file.
A value other than 1 or 0 if an error occurs
(and implicitly sets errno, I assume)
GDB File-I/O isatty:
https://sourceware.org/gdb/onlinedocs/gdb/isatty.html#isatty
Returns 1 if fd refers to the GDB console, 0 otherwise
Documentation doesn't say how it reports errors. Actual implementation
returns -1 and sets errno. (We should probably report some of these
spec issues as gdb bugs...)
isatty() POSIX function:
returns 1 for a terminal
0 with errno ENOTTY for not-a-terminal
0 with some other errno for error cases
It looks like our 'host' implementation of the semihosting SYS_ISTTY
doesn't correctly do the matching up between the semihosting spec
and the isatty() function, so it will return the wrong value for
the error case.
thanks
-- PMM
- [PATCH v3 01/49] semihosting: Move exec/softmmu-semi.h to semihosting/softmmu-uaccess.h, (continued)
- [PATCH v3 01/49] semihosting: Move exec/softmmu-semi.h to semihosting/softmmu-uaccess.h, Richard Henderson, 2022/05/20
- [PATCH v3 02/49] semihosting: Return failure from softmmu-uaccess.h functions, Richard Henderson, 2022/05/20
- [PATCH v3 10/49] semihosting: Clean up common_semi_flen_cb, Richard Henderson, 2022/05/20
- [PATCH v3 06/49] semihosting: Simplify softmmu_lock_user_string, Richard Henderson, 2022/05/20
- [PATCH v3 08/49] semihosting: Inline set_swi_errno into common_semi_cb, Richard Henderson, 2022/05/20
- [PATCH v3 09/49] semihosting: Adjust error checking in common_semi_cb, Richard Henderson, 2022/05/20
- [PATCH v3 05/49] semihosting: Add target_strlen for softmmu-uaccess.h, Richard Henderson, 2022/05/20
- [PATCH v3 11/49] semihosting: Clean up common_semi_open_cb, Richard Henderson, 2022/05/20
- [PATCH v3 07/49] semihosting: Split out guestfd.c, Richard Henderson, 2022/05/20
- [PATCH v3 04/49] semihosting: Move softmmu-uaccess.h functions out of line, Richard Henderson, 2022/05/20
- [PATCH v3 13/49] semihosting: Move common-semi.h to include/semihosting/, Richard Henderson, 2022/05/20
- [PATCH v3 24/49] semihosting: Split out semihost_sys_close, Richard Henderson, 2022/05/20
- [PATCH v3 16/49] include/exec: Define errno values in gdbstub.h, Richard Henderson, 2022/05/20