Make read() and write() signal handling atomic

You would think this is an important bug fix, but unfortunately all UNIX
implementations I've evaluated have a bug in read that causes signals to
not be handled atomically. The only exception is the latest iteration of
Cosmopolitan's read/write polyfill on Windows, which is somewhat ironic.
This commit is contained in:
Justine Tunney 2024-09-15 00:03:48 -07:00
parent c260144843
commit baf70af780
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
12 changed files with 520 additions and 153 deletions

View file

@ -53,20 +53,17 @@ static textwindows ssize_t sys_write_nt_impl(int fd, void *data, size_t size,
bool isconsole = f->kind == kFdConsole;
// not implemented, XNU returns eperm();
if (f->kind == kFdDevRandom) {
if (f->kind == kFdDevRandom)
return eperm();
}
// determine win32 handle for writing
int64_t handle = f->handle;
if (isconsole && _weaken(GetConsoleOutputHandle)) {
if (isconsole && _weaken(GetConsoleOutputHandle))
handle = _weaken(GetConsoleOutputHandle)();
}
// intercept ansi tty configuration sequences
if (isconsole && _weaken(GetConsoleOutputHandle)) {
if (isconsole && _weaken(GetConsoleOutputHandle))
_weaken(InterceptTerminalCommands)(data, size);
}
// perform heavy lifting
ssize_t rc;