Make improvements

- Fix build flakes
- Polyfill SIGWINCH on Windows
- Fix an execve issue on Windows
- Make strerror show more information
- Improve cmd.exe setup/teardown on Windows
- Support bracketed paste mode in Blinkenlights
- Show keyboard shortcuts in Blinkenlights status bar
- Fixed copy_file_range() and copyfile() w/ zip filesystem
- Size optimize GetDosArgv() to keep life.com 12kb in size
- Improve Blinkenlights ability to load weird ELF executables
- Fix program_executable_name and add GetInterpreterExecutableName
- Make Python in tiny mode fail better if docstrings are requested
- Update Python test exclusions in tiny* modes such as tinylinux
- Add bulletproof unbreakable kprintf() troubleshooting function
- Remove "oldskool" keyword from ape.S for virus scanners
- Fix issue that caused backtraces to not print sometimes
- Improve Blinkenlights serial uart character i/o
- Make clock_gettime() not clobber errno on xnu
- Improve sha256 cpuid check for old computers
- Integrate some bestline linenoise fixes
- Show runit process names better in htop
- Remove SIGPIPE from ShowCrashReports()
- Make realpath() not clobber errno
- Avoid attaching GDB on non-Linux
- Improve img.com example
This commit is contained in:
Justine Tunney 2022-03-16 13:33:13 -07:00
parent 2a938b3eaa
commit b45d50b690
194 changed files with 4881 additions and 2966 deletions

View file

@ -23,6 +23,7 @@
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/memtrack.internal.h"
#include "libc/str/str.h"
#include "tool/build/lib/dis.h"
@ -86,8 +87,7 @@ static void DisLoadElfSyms(struct Dis *d, struct Elf *elf) {
ELF64_ST_TYPE(st[i].st_info) == STT_FILE || !st[i].st_name ||
startswith(d->syms.stab + st[i].st_name, "v_") ||
!(0 <= st[i].st_name && st[i].st_name < stablen) || !st[i].st_value ||
!(-0x800000000000 <= (int64_t)st[i].st_value &&
(int64_t)st[i].st_value < 0x800000000000)) {
!IsLegalPointer(st[i].st_value)) {
continue;
}
isabs = st[i].st_shndx == SHN_ABS;

View file

@ -237,6 +237,8 @@ const char *DisSpecMap0(struct XedDecodedInst *x, char *p) {
RCASE(0xCB, "lret");
RCASE(0xCC, "int3");
RCASE(0xCD, "int Ib");
RCASE(0xCE, "into");
RCASE(0xCF, "iret");
RCASE(0xD0, "BIT Eb");
RCASE(0xD1, "BIT Evqp");
RCASE(0xD2, "BIT Evqp %cl");

View file

@ -159,6 +159,25 @@ void EzHandshake(void) {
}
}
int EzHandshake2(void) {
int rc;
while ((rc = mbedtls_ssl_handshake(&ezssl))) {
if (rc == MBEDTLS_ERR_NET_CONN_RESET) {
return rc;
} else if (rc != MBEDTLS_ERR_SSL_WANT_READ) {
TlsDie("handshake failed", rc);
}
}
while ((rc = EzTlsFlush(&ezbio, 0, 0))) {
if (rc == MBEDTLS_ERR_NET_CONN_RESET) {
return rc;
} else if (rc != MBEDTLS_ERR_SSL_WANT_READ) {
TlsDie("handshake flush failed", rc);
}
}
return 0;
}
void EzInitialize(void) {
xsigaction(SIGPIPE, SIG_IGN, 0, 0, 0);
ezconf.disable_compression = 1; /* TODO(jart): Why does it behave weirdly? */

View file

@ -20,6 +20,7 @@ extern mbedtls_ctr_drbg_context ezrng;
void EzFd(int);
void EzHandshake(void);
int EzHandshake2(void);
void EzSetup(char[32]);
void EzInitialize(void);
int EzTlsFlush(struct EzTlsBio *, const unsigned char *, size_t);

View file

@ -1,6 +1,7 @@
#ifndef COSMOPOLITAN_TOOL_BUILD_LIB_FDS_H_
#define COSMOPOLITAN_TOOL_BUILD_LIB_FDS_H_
#include "libc/calls/struct/iovec.h"
#include "libc/sock/sock.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_
@ -14,17 +15,18 @@ struct MachineFdCb {
ssize_t (*readv)(int, const struct iovec *, int);
ssize_t (*writev)(int, const struct iovec *, int);
int (*ioctl)(int, uint64_t, void *);
int (*poll)(struct pollfd *, uint64_t, int32_t);
};
struct MachineFd {
int fd;
struct MachineFdCb * cb;
struct MachineFdCb *cb;
};
struct MachineFds {
size_t i, n;
struct MachineFd * p;
struct MachineFdClosed * closed;
struct MachineFd *p;
struct MachineFdClosed *closed;
};
int MachineFdAdd(struct MachineFds *);

View file

@ -17,8 +17,12 @@
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/calls/struct/iovec.h"
#include "libc/dce.h"
#include "libc/log/log.h"
#include "libc/nexgen32e/uart.internal.h"
#include "libc/sock/sock.h"
#include "libc/sysv/consts/fileno.h"
#include "libc/sysv/consts/poll.h"
#include "tool/build/lib/ioports.h"
static int OpE9Read(struct Machine *m) {
@ -42,7 +46,21 @@ static void OpE9Write(struct Machine *m, uint8_t b) {
m->fds.p[fd].cb->writev(m->fds.p[fd].fd, &(struct iovec){&b, 1}, 1);
}
static int OpE9Poll(struct Machine *m) {
int fd, rc;
struct pollfd pf;
fd = STDIN_FILENO;
if (fd >= m->fds.i) return -1;
if (!m->fds.p[fd].cb) return -1;
pf.fd = m->fds.p[fd].fd;
pf.events = POLLIN | POLLOUT;
rc = m->fds.p[fd].cb->poll(&pf, 1, 20);
if (rc <= 0) return rc;
return pf.revents;
}
static int OpSerialIn(struct Machine *m, int r) {
int p, s;
switch (r) {
case UART_DLL:
if (!m->dlab) {
@ -51,7 +69,15 @@ static int OpSerialIn(struct Machine *m, int r) {
return 0x01;
}
case UART_LSR:
return UART_TTYDA | UART_TTYTXR | UART_TTYIDL;
if (IsWindows()) {
p = POLLIN | POLLOUT; /* XXX */
} else {
if ((p = OpE9Poll(m)) == -1) return -1;
}
s = UART_TTYIDL;
if (p & POLLIN) s |= UART_TTYDA;
if (p & POLLOUT) s |= UART_TTYTXR;
return s;
default:
return 0;
}

View file

@ -43,7 +43,7 @@ static void LoadElfLoadSegment(struct Machine *m, void *code, size_t codesize,
int64_t align, bsssize;
int64_t felf, fstart, fend, vstart, vbss, vend;
align = MAX(phdr->p_align, PAGESIZE);
CHECK_EQ(1, popcnt(align));
if (popcnt(align) != 1) align = 8;
CHECK_EQ(0, (phdr->p_vaddr - phdr->p_offset) % align);
felf = (int64_t)(intptr_t)code;
vstart = ROUNDDOWN(phdr->p_vaddr, align);

View file

@ -288,6 +288,12 @@ static void OpJmpf(struct Machine *m, uint32_t rde) {
}
}
static void OpInto(struct Machine *m, uint32_t rde) {
if (GetFlag(m->flags, FLAGS_OF)) {
HaltMachine(m, kMachineOverflow);
}
}
static relegated void OpXlatAlBbb(struct Machine *m, uint32_t rde) {
uint64_t v;
v = MaskAddress(Eamode(rde), Read64(m->bx) + Read8(m->ax));
@ -1888,7 +1894,7 @@ static const nexgen32e_f kNexgen32e[] = {
[0x0CB] = OpRetf,
[0x0CC] = OpInterrupt3,
[0x0CD] = OpInterruptImm,
[0x0CE] = OpUd,
[0x0CE] = OpInto,
[0x0CF] = OpUd,
[0x0D0] = OpBsubi1,
[0x0D1] = OpBsuwi1,

View file

@ -13,6 +13,7 @@
#define kMachineFpuException -7
#define kMachineProtectionFault -8
#define kMachineSimdException -9
#define kMachineOverflow -10
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

View file

@ -21,6 +21,7 @@
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/runtime/memtrack.internal.h"
#include "libc/runtime/pc.internal.h"
#include "libc/str/str.h"
#include "libc/x/x.h"
@ -90,7 +91,7 @@ void *FindReal(struct Machine *m, int64_t virt) {
uint64_t table, entry, page;
unsigned skew, level, index, i;
if ((m->mode & 3) != XED_MODE_REAL) {
if (-0x800000000000 <= virt && virt < 0x800000000000) {
if (IsLegalPointer(virt)) {
if (!(entry = FindPage(m, virt))) return NULL;
return m->real.p + (entry & PAGE_TA) + (virt & 0xfff);
} else {

View file

@ -1167,10 +1167,45 @@ ssize_t PtyWrite(struct Pty *pty, const void *data, size_t n) {
}
ssize_t PtyWriteInput(struct Pty *pty, const void *data, size_t n) {
PtyConcatInput(pty, data, n);
if (!(pty->conf & kPtyNoecho)) {
PtyWrite(pty, data, n);
int c;
bool cr;
char *p;
const char *q;
size_t i, j, m;
q = data;
p = pty->input.p;
i = pty->input.i;
m = pty->input.n;
if (i + n * 2 + 1 > m) {
m = MAX(m, 8);
do m += m >> 1;
while (i + n * 2 + 1 > m);
if (!(p = realloc(p, m))) {
return -1;
}
pty->input.p = p;
pty->input.n = m;
}
cr = i && p[i - 1] == '\r';
for (j = 0; j < n; ++j) {
c = q[j] & 255;
if (c == '\r') {
cr = true;
} else if (cr) {
if (c != '\n') {
p[i++] = '\n';
}
cr = false;
}
p[i++] = c;
}
if (cr) {
p[i++] = '\n';
}
if (!(pty->conf & kPtyNoecho)) {
PtyWrite(pty, p + pty->input.i, i - pty->input.i);
}
pty->input.i = i;
return n;
}

View file

@ -102,6 +102,7 @@
const struct MachineFdCb kMachineFdCbHost = {
.close = close,
.readv = readv,
.poll = poll,
.writev = writev,
.ioctl = (void *)ioctl,
};

View file

@ -18,7 +18,9 @@
*/
#include "libc/calls/calls.h"
#include "libc/nexgen32e/rdtsc.h"
#include "libc/sock/sock.h"
#include "libc/sysv/consts/clock.h"
#include "libc/sysv/consts/poll.h"
#include "libc/time/time.h"
#include "tool/build/lib/endian.h"
#include "tool/build/lib/modrm.h"
@ -29,7 +31,19 @@
*/
void OpPause(struct Machine *m, uint32_t rde) {
sched_yield();
struct pollfd pf;
static bool once, interactive;
if (!once) {
interactive = isatty(0);
once = true;
}
if (!IsWindows() && interactive) {
pf.fd = 0;
pf.events = POLLIN;
poll(&pf, 1, 20); /* make spin loops less brutal */
} else {
sched_yield();
}
}
void OpRdtsc(struct Machine *m, uint32_t rde) {