mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 03:08:31 +00:00
Make numerous improvements
- Python static hello world now 1.8mb - Python static fully loaded now 10mb - Python HTTPS client now uses MbedTLS - Python REPL now completes import stmts - Increase stack size for Python for now - Begin synthesizing posixpath and ntpath - Restore Python \N{UNICODE NAME} support - Restore Python NFKD symbol normalization - Add optimized code path for Intel SHA-NI - Get more Python unit tests passing faster - Get Python help() pagination working on NT - Python hashlib now supports MbedTLS PBKDF2 - Make memcpy/memmove/memcmp/bcmp/etc. faster - Add Mersenne Twister and Vigna to LIBC_RAND - Provide privileged __printf() for error code - Fix zipos opendir() so that it reports ENOTDIR - Add basic chmod() implementation for Windows NT - Add Cosmo's best functions to Python cosmo module - Pin function trace indent depth to that of caller - Show memory diagram on invalid access in MODE=dbg - Differentiate stack overflow on crash in MODE=dbg - Add stb_truetype and tools for analyzing font files - Upgrade to UNICODE 13 and reduce its binary footprint - COMPILE.COM now logs resource usage of build commands - Start implementing basic poll() support on bare metal - Set getauxval(AT_EXECFN) to GetModuleFileName() on NT - Add descriptions to strerror() in non-TINY build modes - Add COUNTBRANCH() macro to help with micro-optimizations - Make error / backtrace / asan / memory code more unbreakable - Add fast perfect C implementation of μ-Law and a-Law audio codecs - Make strtol() functions consistent with other libc implementations - Improve Linenoise implementation (see also github.com/jart/bestline) - COMPILE.COM now suppresses stdout/stderr of successful build commands
This commit is contained in:
parent
fa7b4f5bd1
commit
39bf41f4eb
806 changed files with 77494 additions and 63859 deletions
|
@ -28,13 +28,18 @@
|
|||
#include "libc/dce.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/intrin/asan.internal.h"
|
||||
#include "libc/log/backtrace.internal.h"
|
||||
#include "libc/log/color.internal.h"
|
||||
#include "libc/log/gdb.h"
|
||||
#include "libc/log/internal.h"
|
||||
#include "libc/log/libfatal.internal.h"
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/nexgen32e/bsr.h"
|
||||
#include "libc/nexgen32e/stackframe.h"
|
||||
#include "libc/nt/process.h"
|
||||
#include "libc/nt/runtime.h"
|
||||
#include "libc/runtime/internal.h"
|
||||
#include "libc/runtime/memtrack.internal.h"
|
||||
#include "libc/runtime/pc.internal.h"
|
||||
|
@ -42,6 +47,7 @@
|
|||
#include "libc/str/str.h"
|
||||
#include "libc/sysv/consts/auxv.h"
|
||||
#include "libc/sysv/consts/fileno.h"
|
||||
#include "libc/sysv/consts/nr.h"
|
||||
#include "libc/sysv/consts/o.h"
|
||||
#include "libc/sysv/consts/sig.h"
|
||||
#include "libc/sysv/consts/termios.h"
|
||||
|
@ -105,11 +111,9 @@ relegated static char *AddFlag(char *p, int b, const char *s) {
|
|||
return p;
|
||||
}
|
||||
|
||||
relegated static void DescribeCpuFlags(int fd, int flags, int x87sw,
|
||||
int mxcsr) {
|
||||
relegated static char *DescribeCpuFlags(char *p, int flags, int x87sw,
|
||||
int mxcsr) {
|
||||
unsigned i;
|
||||
char buf[64], *p;
|
||||
p = buf;
|
||||
for (i = 0; i < ARRAYLEN(kCpuFlags); ++i) {
|
||||
if (flags & 1) {
|
||||
*p++ = ' ';
|
||||
|
@ -130,47 +134,73 @@ relegated static void DescribeCpuFlags(int fd, int flags, int x87sw,
|
|||
p = AddFlag(p, x87sw & FPU_C1, " C1");
|
||||
p = AddFlag(p, x87sw & FPU_C2, " C2");
|
||||
p = AddFlag(p, x87sw & FPU_C3, " C3");
|
||||
write(fd, buf, p - buf);
|
||||
return p;
|
||||
}
|
||||
|
||||
relegated static void ShowGeneralRegisters(int fd, ucontext_t *ctx) {
|
||||
relegated static char *ShowGeneralRegisters(char *p, ucontext_t *ctx) {
|
||||
int64_t x;
|
||||
const char *s;
|
||||
size_t i, j, k;
|
||||
long double st;
|
||||
write(fd, "\n", 1);
|
||||
*p++ = '\n';
|
||||
for (i = 0, j = 0, k = 0; i < ARRAYLEN(kGregNames); ++i) {
|
||||
if (j > 0) write(fd, " ", 1);
|
||||
dprintf(fd, "%-3s %016lx", kGregNames[(unsigned)kGregOrder[i]],
|
||||
ctx->uc_mcontext.gregs[(unsigned)kGregOrder[i]]);
|
||||
if (j > 0) *p++ = ' ';
|
||||
if (!(s = kGregNames[(unsigned)kGregOrder[i]])[2]) *p++ = ' ';
|
||||
p = __stpcpy(p, s), *p++ = ' ';
|
||||
p = __fixcpy(p, ctx->uc_mcontext.gregs[(unsigned)kGregOrder[i]], 64);
|
||||
if (++j == 3) {
|
||||
j = 0;
|
||||
if (ctx->uc_mcontext.fpregs) {
|
||||
memcpy(&st, (char *)&ctx->uc_mcontext.fpregs->st[k], sizeof(st));
|
||||
} else {
|
||||
memset(&st, 0, sizeof(st));
|
||||
bzero(&st, sizeof(st));
|
||||
}
|
||||
dprintf(fd, " %s(%zu) %Lg", "ST", k, st);
|
||||
++k;
|
||||
write(fd, "\n", 1);
|
||||
p = __stpcpy(p, " ST(");
|
||||
p = __uintcpy(p, k++);
|
||||
p = __stpcpy(p, ") ");
|
||||
x = st * 1000;
|
||||
if (x < 0) x = -x, *p++ = '-';
|
||||
p = __uintcpy(p, x / 1000), *p++ = '.';
|
||||
p = __uintcpy(p, x % 1000), *p++ = '\n';
|
||||
}
|
||||
}
|
||||
DescribeCpuFlags(
|
||||
fd, ctx->uc_mcontext.gregs[REG_EFL],
|
||||
return DescribeCpuFlags(
|
||||
p, ctx->uc_mcontext.gregs[REG_EFL],
|
||||
ctx->uc_mcontext.fpregs ? ctx->uc_mcontext.fpregs->swd : 0,
|
||||
ctx->uc_mcontext.fpregs ? ctx->uc_mcontext.fpregs->mxcsr : 0);
|
||||
}
|
||||
|
||||
relegated static void ShowSseRegisters(int fd, ucontext_t *ctx) {
|
||||
relegated static char *ShowSseRegisters(char *p, ucontext_t *ctx) {
|
||||
size_t i;
|
||||
if (ctx->uc_mcontext.fpregs) {
|
||||
write(fd, "\n\n", 2);
|
||||
p = __stpcpy(p, "\n\n");
|
||||
for (i = 0; i < 8; ++i) {
|
||||
dprintf(fd, "%s%-2zu %016lx%016lx %s%-2d %016lx%016lx\n", "XMM", i + 0,
|
||||
ctx->uc_mcontext.fpregs->xmm[i + 0].u64[1],
|
||||
ctx->uc_mcontext.fpregs->xmm[i + 0].u64[0], "XMM", i + 8,
|
||||
ctx->uc_mcontext.fpregs->xmm[i + 8].u64[1],
|
||||
ctx->uc_mcontext.fpregs->xmm[i + 8].u64[0]);
|
||||
p = __stpcpy(p, "XMM");
|
||||
if (i >= 10) {
|
||||
*p++ = i / 10 + '0';
|
||||
*p++ = i % 10 + '0';
|
||||
} else {
|
||||
*p++ = i + '0';
|
||||
*p++ = ' ';
|
||||
}
|
||||
*p++ = ' ';
|
||||
p = __fixcpy(p, ctx->uc_mcontext.fpregs->xmm[i + 0].u64[1], 64);
|
||||
p = __fixcpy(p, ctx->uc_mcontext.fpregs->xmm[i + 0].u64[0], 64);
|
||||
p = __stpcpy(p, " XMM");
|
||||
if (i + 8 >= 10) {
|
||||
*p++ = (i + 8) / 10 + '0';
|
||||
*p++ = (i + 8) % 10 + '0';
|
||||
} else {
|
||||
*p++ = (i + 8) + '0';
|
||||
*p++ = ' ';
|
||||
}
|
||||
*p++ = ' ';
|
||||
p = __fixcpy(p, ctx->uc_mcontext.fpregs->xmm[i + 8].u64[1], 64);
|
||||
p = __fixcpy(p, ctx->uc_mcontext.fpregs->xmm[i + 8].u64[0], 64);
|
||||
*p++ = '\n';
|
||||
}
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
relegated static void ShowMemoryMappings(int outfd) {
|
||||
|
@ -181,7 +211,7 @@ relegated static void ShowMemoryMappings(int outfd) {
|
|||
PrintMemoryIntervals(outfd, &_mmi);
|
||||
if ((infd = open("/proc/self/maps", O_RDONLY)) != -1) {
|
||||
while ((rc = read(infd, buf, sizeof(buf))) > 0) {
|
||||
write(outfd, buf, rc);
|
||||
__write(buf, rc);
|
||||
}
|
||||
}
|
||||
close(infd);
|
||||
|
@ -190,41 +220,70 @@ relegated static void ShowMemoryMappings(int outfd) {
|
|||
|
||||
void ShowCrashReportHook(int, int, int, struct siginfo *, ucontext_t *);
|
||||
|
||||
relegated static void ShowCrashReport(int err, int fd, int sig,
|
||||
struct siginfo *si, ucontext_t *ctx) {
|
||||
relegated void ShowCrashReport(int err, int fd, int sig, struct siginfo *si,
|
||||
ucontext_t *ctx) {
|
||||
int i;
|
||||
char *p;
|
||||
bool colorful;
|
||||
char hostname[64];
|
||||
struct utsname names;
|
||||
static char buf[4096];
|
||||
if (weaken(ShowCrashReportHook)) {
|
||||
ShowCrashReportHook(err, fd, sig, si, ctx);
|
||||
}
|
||||
strcpy(hostname, "unknown");
|
||||
colorful = cancolor();
|
||||
__stpcpy(hostname, "unknown");
|
||||
gethostname(hostname, sizeof(hostname));
|
||||
dprintf(fd,
|
||||
"\n"
|
||||
"%serror%s: Uncaught SIG%s (%s) on %s\n"
|
||||
" %s\n"
|
||||
" %s\n",
|
||||
RED2, RESET, TinyStrSignal(sig),
|
||||
si ? GetSiCodeName(sig, si->si_code) : "???", hostname,
|
||||
program_invocation_name, strerror(err));
|
||||
if (uname(&names) != -1) {
|
||||
dprintf(fd, " %s %s %s %s\n", names.sysname, names.nodename, names.release,
|
||||
names.version);
|
||||
p = buf;
|
||||
p = __stpcpy(p, "\n");
|
||||
if (colorful) p = __stpcpy(p, "\e[30;101m");
|
||||
p = __stpcpy(p, "error");
|
||||
if (colorful) p = __stpcpy(p, "\e[0m");
|
||||
p = __stpcpy(p, ": Uncaught SIG");
|
||||
p = __stpcpy(p, TinyStrSignal(sig));
|
||||
if (si) {
|
||||
p = __stpcpy(p, " (");
|
||||
p = __stpcpy(p, GetSiCodeName(sig, si->si_code));
|
||||
p = __stpcpy(p, ")");
|
||||
}
|
||||
p = __stpcpy(p, " on ");
|
||||
p = __stpcpy(p, hostname);
|
||||
p = __stpcpy(p, " pid ");
|
||||
p = __intcpy(p, __getpid());
|
||||
p = __stpcpy(p, "\n ");
|
||||
p = __stpcpy(p, program_invocation_name);
|
||||
p = __stpcpy(p, "\n ");
|
||||
p = __stpcpy(p, strerror(err));
|
||||
*p++ = '\n';
|
||||
if (uname(&names) != -1) {
|
||||
p = __stpcpy(p, " ");
|
||||
p = __stpcpy(p, names.sysname), *p++ = ' ';
|
||||
p = __stpcpy(p, names.nodename), *p++ = ' ';
|
||||
p = __stpcpy(p, names.release), *p++ = ' ';
|
||||
p = __stpcpy(p, names.version), *p++ = '\n';
|
||||
}
|
||||
__write(buf, p - buf);
|
||||
ShowFunctionCalls(fd, ctx);
|
||||
if (ctx) {
|
||||
ShowGeneralRegisters(fd, ctx);
|
||||
ShowSseRegisters(fd, ctx);
|
||||
p = buf;
|
||||
p = ShowGeneralRegisters(p, ctx);
|
||||
p = ShowSseRegisters(p, ctx);
|
||||
*p++ = '\n';
|
||||
__write(buf, p - buf);
|
||||
}
|
||||
write(fd, "\n", 1);
|
||||
p = buf;
|
||||
*p++ = '\n';
|
||||
ShowMemoryMappings(fd);
|
||||
write(fd, "\n", 1);
|
||||
for (i = 0; i < __argc; ++i) {
|
||||
write(fd, __argv[i], strlen(__argv[i]));
|
||||
write(fd, " ", 1);
|
||||
__write(buf, p - buf);
|
||||
if (__argv) {
|
||||
for (i = 0; i < __argc; ++i) {
|
||||
if (!__argv[i]) continue;
|
||||
if (IsAsan() && !__asan_is_valid(__argv[i], 1)) continue;
|
||||
__write(__argv[i], strlen(__argv[i]));
|
||||
__write(" ", 1);
|
||||
}
|
||||
}
|
||||
write(fd, "\n", 1);
|
||||
__write("\n", 1);
|
||||
}
|
||||
|
||||
relegated static void RestoreDefaultCrashSignalHandlers(void) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue