Improve synchronization

- Fix bugs in kDos2Errno definition
- malloc() should now be thread safe
- Fix bug in rollup.com header generator
- Fix open(O_APPEND) on the New Technology
- Fix select() on the New Technology and test it
- Work towards refactoring i/o for thread safety
- Socket reads and writes on NT now poll for signals
- Work towards i/o completion ports on the New Technology
- Make read() and write() intermittently check for signals
- Blinkenlights keyboard i/o so much better on NT w/ poll()
- You can now poll() files and sockets at the same time on NT
- Fix bug in appendr() that manifests with dlmalloc footers off
This commit is contained in:
Justine Tunney 2022-04-14 23:39:48 -07:00
parent 233144b19d
commit 933411ba99
266 changed files with 8761 additions and 4344 deletions

View file

@ -37,6 +37,7 @@
#include "libc/nt/process.h"
#include "libc/nt/runtime.h"
#include "libc/nt/thunk/msabi.h"
#include "libc/nt/winsock.h"
#include "libc/runtime/memtrack.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
@ -438,8 +439,7 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, va_list va,
i = 0;
m = (1 << base) - 1;
if (hash && x) sign = hash;
do
z[i++ & 127] = abet[x & m];
do z[i++ & 127] = abet[x & m];
while ((x >>= base) || (pdot && i < prec));
goto EmitNumber;
@ -487,17 +487,31 @@ privileged static size_t kformat(char *b, size_t n, const char *fmt, va_list va,
}
goto EmitChar;
case 'm':
if (!(x = errno) && sign == ' ' /* && */
/* (!IsWindows() || !__imp_GetLastError()) */) {
case 'm': {
int unixerr;
uint32_t winerr;
unixerr = errno;
winerr = 0;
if (IsWindows()) {
if (type == 1 && weaken(WSAGetLastError)) {
winerr = weaken(WSAGetLastError)();
} else if (weaken(GetLastError)) {
winerr = weaken(GetLastError)();
}
}
if (!unixerr && sign == ' ') {
break;
} else if (weaken(strerror_r) &&
!weaken(strerror_r)(x, z, sizeof(z))) {
} else if (weaken(strerror_wr) &&
!weaken(strerror_wr)(unixerr, winerr, z, sizeof(z))) {
s = z;
type = 0;
goto FormatString;
} else {
type = 0;
x = unixerr;
goto FormatDecimal;
}
}
case 'G':
x = va_arg(va, int);
@ -864,6 +878,13 @@ privileged void kvprintf(const char *fmt, va_list v) {
* - ` ` space leftpad if positive (aligns w/ negatives)
* - `#` represent value with literal syntax, e.g. 0x, 0b, quotes
*
* Error numbers:
*
* - `%m` formats error (if strerror_wr if is linked)
* - `%m` formats errno number (if strerror_wr isn't linked)
* - `% m` formats error with leading space if errno isn't zero
* - `%lm` means favor WSAGetLastError() over GetLastError() if linked
*
* @asyncsignalsafe
* @vforksafe
*/