Make more fixes and improvements

- Remove PAGESIZE constant
- Fix realloc() documentation
- Fix ttyname_r() error reporting
- Make forking more reliable on Windows
- Make execvp() a few microseconds faster
- Make system() a few microseconds faster
- Tighten up the socket-related magic numbers
- Loosen restrictions on mmap() offset alignment
- Improve GetProgramExecutableName() with getenv("_")
- Use mkstemp() as basis for mktemp(), tmpfile(), tmpfd()
- Fix flakes in pthread_cancel_test, unix_test, fork_test
- Fix recently introduced futex stack overflow regression
- Let sockets be passed as stdio to subprocesses on Windows
- Improve security of bind() on Windows w/ SO_EXCLUSIVEADDRUSE
This commit is contained in:
Justine Tunney 2023-07-29 18:44:15 -07:00
parent 140a8a52e5
commit 18bb5888e1
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
311 changed files with 1239 additions and 2622 deletions

View file

@ -31,8 +31,8 @@
#include "libc/fmt/itoa.h"
#include "libc/intrin/bits.h"
#include "libc/intrin/bsf.h"
#include "libc/intrin/bsr.h"
#include "libc/intrin/hilbert.h"
#include "libc/intrin/morton.h"
#include "libc/intrin/safemacros.internal.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
@ -188,6 +188,10 @@ static void LeaveScreen(void) {
Write("\e[H\e[J");
}
static unsigned long rounddown2pow(unsigned long x) {
return x ? 1ul << _bsrl(x) : 0;
}
static void GetTtySize(void) {
struct winsize wsize;
wsize.ws_row = tyn + 1;
@ -195,8 +199,8 @@ static void GetTtySize(void) {
tcgetwinsize(out, &wsize);
tyn = MAX(2, wsize.ws_row) - 1;
txn = MAX(17, wsize.ws_col) - 16;
tyn = _rounddown2pow(tyn);
txn = _rounddown2pow(txn);
tyn = rounddown2pow(tyn);
txn = rounddown2pow(txn);
tyn = MIN(tyn, txn);
}
@ -278,11 +282,30 @@ static void SetupCanvas(void) {
}
displaysize = ROUNDUP(ROUNDUP((tyn * txn) << zoom, 16), 1ul << zoom);
canvassize = ROUNDUP(displaysize, FRAMESIZE);
buffersize = ROUNDUP(tyn * txn * 16 + PAGESIZE, FRAMESIZE);
buffersize = ROUNDUP(tyn * txn * 16 + 4096, FRAMESIZE);
canvas = Allocate(canvassize);
buffer = Allocate(buffersize);
}
/**
* Interleaves bits.
* @see https://en.wikipedia.org/wiki/Z-order_curve
* @see unmorton()
*/
static unsigned long morton(unsigned long y, unsigned long x) {
x = (x | x << 020) & 0x0000FFFF0000FFFF;
x = (x | x << 010) & 0x00FF00FF00FF00FF;
x = (x | x << 004) & 0x0F0F0F0F0F0F0F0F;
x = (x | x << 002) & 0x3333333333333333;
x = (x | x << 001) & 0x5555555555555555;
y = (y | y << 020) & 0x0000FFFF0000FFFF;
y = (y | y << 010) & 0x00FF00FF00FF00FF;
y = (y | y << 004) & 0x0F0F0F0F0F0F0F0F;
y = (y | y << 002) & 0x3333333333333333;
y = (y | y << 001) & 0x5555555555555555;
return x | y << 1;
}
static long IndexSquare(long y, long x) {
switch (order) {
case LINEAR: