On 2021-03-01, Rainer Weikusat <
[email protected]> wrote:
To my bewilderment, I just discovered that both read and recvmsg are
required to be async-signal safe but readv isn't (some goes for
output routines).
Eek.
Does someone know a reason for this bizarrely asymetrical arrangement?
If it's not simply an oversight, could it have something to do with some
dumb user space simulations of these functions?
If you don't actually have readv as a kernel primitive, what can
go wrong, signal-wise?
The user space implementation has to intercept errno to determine
success, and then do the copying from the linear buffer to the iovec.
Well, so what?
The behavior is undefined if an unsafe function is interrupted by an
async signal handler which then calls an unsafe function, so what we
have to think about is how an interrupted and re-entered readv
could misbehave.
Looking at errno could be a problem if an async signal handler doesn't
save it and restore it, but that is generally required. POSIX says
"Operations which obtain the value of errno and operations which assign
a value to errno shall be async-signal-safe, provided that the
signal-catching function saves the value of errno upon entry and
restores it before it returns."
If we do a siglongjmp out of the handler which interrupted a readv,
the program can tell that its buffers were clobbered, though the
readv did not complete. But that's no what async safety is documented
as being about; that's more along the lines of atomicity in the
face of a signal.
--
TXR Programming Language:
http://nongnu.org/txr
Cygna: Cygwin Native Application Library:
http://kylheku.com/cygnal
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)