[ATfE] Use semihosting SYS_READC for stdin with llvm libc#667
[ATfE] Use semihosting SYS_READC for stdin with llvm libc#667voltur01 merged 3 commits intoarm:arm-softwarefrom
Conversation
Semihosting SYS_READ call on stdin just returns immediately indicating no data was read, thus rendering stdin unusable with QEMU. SYS_READC blocks and waits for one symbol to be read from the terminal, however Enter key specifically is returned as '\r', thus the special case (that may not generalize well beyond QEMU).
|
I found a QEMU https://gitlab.com/qemu-project/qemu/-/issues/1963 and a Picolibc issue raised from that picolibc/picolibc#697 that mention SYS_READ and SYS_READC. If I've understood both issues, it seems like SYS_READ does not block in QEMU, but picolibc's read() may block indefinitely for an EOF in stdin. The picolibc response is that the IO implementation would need to use buffered IO to use QEMUs non-blocking SYS_READ. |
smithp35
left a comment
There was a problem hiding this comment.
Based on the Picolibc/QEMU discussion in https://gitlab.com/qemu-project/qemu/-/issues/1963, this looks good to me. It is mentioned that newlib only uses SYS_READ, which does indeed look like the case for libgloss/arm/syscalls.c however there may be higher-level code that is able to handle non-blocking IO in newlib, or it may just not work at all with QEMU!
| if (retval >= 0) | ||
| retval = size - retval; | ||
| return retval; | ||
| char *buf, size_t size) { |
There was a problem hiding this comment.
I think it will be worth a comment explaining why we are using SYS_READC. Something like:
Currently only supports reading from stdin. We use SYS_READC for reading from stdin as QEMUs SYS_READ does not block. For other files SYS_READ should be used as SYS_READC may block indefinitely in QEMU.
There was a problem hiding this comment.
Thank you! A comment added including a TODO for when there is regular file support in llvm libc.
|
Please review resolution of conflict with #665 |
smithp35
left a comment
There was a problem hiding this comment.
Conflict resolution LGTM
Semihosting SYS_READ call on stdin just returns immediately indicating no data was read, thus rendering stdin unusable with QEMU. SYS_READC blocks and waits for one symbol to be read from the terminal, however Enter key specifically is returned as '\r', thus the special case (that may not generalize well beyond QEMU). (cherry picked from commit b407fd6)
This applies the following changes to 22.x release branch: #667 [ATfE] Use semihosting SYS_READC for stdin with llvm libc #676 [ATfE] Remove __LLVM_LIBC__ define workaround for libcxx #678 [ATfE] Replace call to abort with __llvm_libc_exit in libc startup code #679 [ATfE] Update comment about handling cleanup for exit() #683 [ATfE] Provide nohost init and exit in llvmlibc startup code
Semihosting SYS_READ call on stdin just returns immediately indicating no data was read, thus rendering stdin unusable with QEMU.
SYS_READC blocks and waits for one symbol to be read from the terminal, however Enter key specifically is returned as '\r', thus the special case (that may not generalize well beyond QEMU).