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:
Justine Tunney 2021-09-27 22:58:51 -07:00
parent fa7b4f5bd1
commit 39bf41f4eb
806 changed files with 77494 additions and 63859 deletions

View file

@ -132,7 +132,7 @@ int main(int argc, char *argv[]) {
return 1;
}
memset(&args, 0, sizeof(args));
bzero(&args, sizeof(args));
for (i = 3; i < argc; ++i) {
if (argv[i][0] != '@') {
args.p = realloc(args.p, ++args.n * sizeof(*args.p));

View file

@ -649,7 +649,7 @@ static void ResolveBreakpoints(void) {
static void BreakAtNextInstruction(void) {
struct Breakpoint b;
memset(&b, 0, sizeof(b));
bzero(&b, sizeof(b));
b.addr = GetIp() + m->xedd->length;
b.oneshot = true;
PushBreakpoint(&breakpoints, &b);
@ -754,7 +754,7 @@ static bool IsXmmNonZero(long start, long end) {
long i;
uint8_t v1[16], vz[16];
for (i = start; i < end; ++i) {
memset(vz, 0, 16);
bzero(vz, 16);
memcpy(v1, m->xmm[i], 16);
pcmpeqb(v1, v1, vz);
if (pmovmskb(v1) != 0xffff) {
@ -1268,7 +1268,7 @@ static void DrawMemoryZoomed(struct Panel *p, struct MemoryView *view,
size = (p->bottom - p->top) * DUMPWIDTH;
canvas = xcalloc(1, size);
invalid = xcalloc(1, size);
memset(&ranges, 0, sizeof(ranges));
bzero(&ranges, sizeof(ranges));
FindContiguousMemoryRanges(m, &ranges);
for (k = i = 0; i < ranges.i; ++i) {
if ((a >= ranges.p[i].a && a < ranges.p[i].b) ||
@ -1279,7 +1279,7 @@ static void DrawMemoryZoomed(struct Panel *p, struct MemoryView *view,
n = ROUNDUP(ROUNDUP(d - c, 16), 1ull << view->zoom);
chunk = xmalloc(n);
VirtualSend(m, chunk, c, d - c);
memset(chunk + (d - c), 0, n - (d - c));
bzero(chunk + (d - c), n - (d - c));
for (j = 0; j < view->zoom; ++j) {
cDecimate2xUint8x8(ROUNDUP(n, 16), chunk, kThePerfectKernel);
n >>= 1;
@ -1549,7 +1549,7 @@ static void DrawStatus(struct Panel *p) {
a = &m->memstat;
b = &lastmemstat;
s = xmalloc(sizeof(struct Buffer));
memset(s, 0, sizeof(*s));
bzero(s, sizeof(*s));
if (ips > 0) rw += AppendStat(s, "ips", ips, false);
rw += AppendStat(s, "kb", m->real.n / 1024, false);
rw += AppendStat(s, "reserve", a->reserved, a->reserved != b->reserved);
@ -1734,7 +1734,7 @@ static void DrawDisplayOnly(struct Panel *p) {
p->lines[i].i = 0;
}
DrawDisplay(p);
memset(&b, 0, sizeof(b));
bzero(&b, sizeof(b));
tly = tyn / 2 - yn / 2;
tlx = txn / 2 - xn / 2;
AppendStr(&b, "\e[0m\e[H");
@ -1769,7 +1769,7 @@ static int OnPtyFdTiocgwinsz(int fd, struct winsize *ws) {
}
static int OnPtyFdTcgets(int fd, struct termios *c) {
memset(c, 0, sizeof(*c));
bzero(c, sizeof(*c));
if (!(pty->conf & kPtyNocanon)) c->c_iflag |= ICANON;
if (!(pty->conf & kPtyNoecho)) c->c_iflag |= ECHO;
if (!(pty->conf & kPtyNoopost)) c->c_oflag |= OPOST;
@ -2456,7 +2456,7 @@ static void OnHelp(void) {
static void ReadKeyboard(void) {
char buf[64], *p = buf;
memset(buf, 0, sizeof(buf));
bzero(buf, sizeof(buf));
dialog = NULL;
if (readansi(ttyin, buf, sizeof(buf)) == -1) {
if (errno == EINTR) {
@ -2544,7 +2544,7 @@ static int64_t ParseHexValue(const char *s) {
static void HandleBreakpointFlag(const char *s) {
struct Breakpoint b;
memset(&b, 0, sizeof(b));
bzero(&b, sizeof(b));
if (isdigit(*s)) {
b.addr = ParseHexValue(s);
} else {
@ -2764,6 +2764,7 @@ static void GetOpts(int argc, char *argv[]) {
react = true;
break;
case 'r':
m->ismetal = true;
m->mode = XED_MACHINE_MODE_REAL;
g_disisprog_disable = true;
break;
@ -2774,7 +2775,7 @@ static void GetOpts(int argc, char *argv[]) {
HandleBreakpointFlag(optarg);
break;
case 'H':
memset(&g_high, 0, sizeof(g_high));
bzero(&g_high, sizeof(g_high));
break;
case 'v':
++__log_level;

View file

@ -498,7 +498,7 @@ void AppendByte(struct Bytes *a, char b) {
void AppendHistory(void) {
struct Bytes line;
if (interactive) {
memset(&line, 0, sizeof(line));
bzero(&line, sizeof(line));
APPEND(&history.p, &history.i, &history.n, &line);
}
}

File diff suppressed because it is too large Load diff

View file

@ -46,5 +46,4 @@ void LoadDebugSymbols(struct Elf *elf) {
}
close(fd);
}
fprintf(stderr, "got here\n");
}

View file

@ -273,7 +273,7 @@ void DisFreeOps(struct DisOps *ops) {
DisFreeOp(&ops->p[i]);
}
free(ops->p);
memset(ops, 0, sizeof(*ops));
bzero(ops, sizeof(*ops));
}
void DisFree(struct Dis *d) {
@ -282,5 +282,5 @@ void DisFree(struct Dis *d) {
free(d->edges.p);
free(d->loads.p);
free(d->syms.p);
memset(d, 0, sizeof(*d));
bzero(d, sizeof(*d));
}

View file

@ -966,7 +966,7 @@ static void OpFrstor(struct Machine *m) {
a = Load(m, m->fpu.dp, sizeof(b), b);
GetFpuEnv(m, a);
for (i = 0; i < 8; ++i) {
memset(&x, 0, sizeof(x));
bzero(&x, sizeof(x));
memcpy(&x, a + 28 + i * 10, 10);
*FpuSt(m, i) = x;
}

View file

@ -44,12 +44,12 @@ static void DeleteLastEmptyLine(char *p, size_t n) {
static void AppendLine(struct Lines *lines) {
lines->p = realloc(lines->p, ++lines->n * sizeof(*lines->p));
memset(lines->p + lines->n - 1, 0, sizeof(*lines->p));
bzero(lines->p + lines->n - 1, sizeof(*lines->p));
}
static void AppendTag(struct JavadownTags *tags) {
tags->p = realloc(tags->p, ++tags->n * sizeof(*tags->p));
memset(tags->p + tags->n - 1, 0, sizeof(*tags->p));
bzero(tags->p + tags->n - 1, sizeof(*tags->p));
}
static unsigned GetSpacePrefixLen(const char *p, size_t n) {
@ -247,7 +247,7 @@ struct Javadown *ParseJavadown(const char *data, size_t size) {
char *p;
struct Lines lines;
struct Javadown *jd;
memset(&lines, 0, sizeof(lines));
bzero(&lines, sizeof(lines));
jd = calloc(1, sizeof(struct Javadown));
p = strndup(data, size);
SplitLines(&lines, p);

View file

@ -112,7 +112,7 @@ static void BootProgram(struct Machine *m, struct Elf *elf, size_t codesize) {
m->ip = 0x7c00;
elf->base = 0x7c00;
CHECK_NE(-1, ReserveReal(m, 0x00f00000));
memset(m->real.p, 0, 0x00f00000);
bzero(m->real.p, 0x00f00000);
Write16(m->real.p + 0x400, 0x3F8);
Write16(m->real.p + 0x40E, 0xb0000 >> 4);
Write16(m->real.p + 0x413, 0xb0000 / 1024);

View file

@ -1454,7 +1454,7 @@ static void OpDoubleShift(struct Machine *m, uint32_t rde) {
static void OpFxsave(struct Machine *m, uint32_t rde) {
int64_t v;
uint8_t buf[32];
memset(buf, 0, 32);
bzero(buf, 32);
Write16(buf + 0, m->fpu.cw);
Write16(buf + 2, m->fpu.sw);
Write8(buf + 4, m->fpu.tw);

View file

@ -160,6 +160,7 @@ struct Machine {
jmp_buf onhalt;
int64_t faultaddr;
bool dlab;
bool ismetal;
struct MachineFds fds;
uint8_t stash[4096];
uint8_t icache[1024][40];

View file

@ -58,7 +58,7 @@ void FreeMachine(struct Machine *m) {
void ResetMem(struct Machine *m) {
FreeMachineRealFree(m);
ResetTlb(m);
memset(&m->memstat, 0, sizeof(m->memstat));
bzero(&m->memstat, sizeof(m->memstat));
m->real.i = 0;
m->cr3 = 0;
}
@ -66,7 +66,7 @@ void ResetMem(struct Machine *m) {
long AllocateLinearPage(struct Machine *m) {
long page;
if ((page = AllocateLinearPageRaw(m)) != -1) {
memset(m->real.p + page, 0, 0x1000);
bzero(m->real.p + page, 0x1000);
}
return page;
}

View file

@ -45,7 +45,7 @@ void PrintMessageBox(int fd, const char *msg, long tyn, long txn) {
w = 4 + GetWidthOfLongestLine(lines) + 4;
x = lrint(txn / 2. - w / 2.);
y = lrint(tyn / 2. - h / 2.);
memset(&b, 0, sizeof(b));
bzero(&b, sizeof(b));
AppendFmt(&b, "\e[%d;%dH", y++, x);
for (i = 0; i < w; ++i) AppendStr(&b, " ");
AppendFmt(&b, "\e[%d;%dH ╔", y++, x);

View file

@ -45,7 +45,7 @@ ssize_t PrintPanels(int fd, long pn, struct Panel *p, long tyn, long txn) {
struct Buffer b, *l;
int x, y, i, j, width;
enum { kUtf8, kAnsi, kAnsiCsi } state;
memset(&b, 0, sizeof(b));
bzero(&b, sizeof(b));
AppendStr(&b, "\e[H");
for (y = 0; y < tyn; ++y) {
if (y) AppendStr(&b, "\r\n");

View file

@ -41,14 +41,14 @@
*
* \t TAB
* \a BELL
* \177 BACKSPACE
* \r CURSOR START
* \b CURSOR LEFT
* \177 CURSOR LEFT
* \b CURSOR LEFT OR CURSOR REWIND
* \n CURSOR DOWN AND START IF OPOST
* \f CURSOR DOWN AND START IF OPOST
* \v CURSOR DOWN AND START IF OPOST
* \eD CURSOR DOWN AND START
* \eE CURSOR DOWN
* \v CURSOR DOWN AND START OR \e[H\e[J
* \eE CURSOR DOWN AND START
* \eD CURSOR DOWN
* \eM CURSOR UP
* \ec FULL RESET
* \e7 SAVE CURSOR POSITION
@ -331,7 +331,7 @@ static void PtySetCodepage(struct Pty *pty, char id) {
void PtyErase(struct Pty *pty, long dst, long n) {
DCHECK_LE(dst + n, pty->yn * pty->xn);
wmemset((void *)(pty->wcs + dst), ' ', n);
wmemset((void *)(pty->prs + dst), 0, n);
bzero((void *)(pty->prs + dst), n);
}
void PtyMemmove(struct Pty *pty, long dst, long src, long n) {
@ -729,7 +729,7 @@ static void PtySelectGraphicsRendition(struct Pty *pty) {
x = 0;
t = kSgr;
p = pty->esc.s;
memset(code, 0, sizeof(code));
bzero(code, sizeof(code));
for (;;) {
c = *p++;
switch (c) {

View file

@ -58,7 +58,7 @@ static void ResetSse(struct Machine *m) {
m->sse.pm = true;
m->sse.rc = RINT;
m->sse.ftz = false;
memset(m->xmm, 0, sizeof(m->xmm));
bzero(m->xmm, sizeof(m->xmm));
}
void ResetInstructionCache(struct Machine *m) {
@ -81,16 +81,16 @@ void ResetCpu(struct Machine *m) {
m->flags = SetFlag(m->flags, FLAGS_F1, true);
m->flags = SetFlag(m->flags, FLAGS_F0, false);
m->flags = SetFlag(m->flags, FLAGS_IOPL, 3);
memset(m->reg, 0, sizeof(m->reg));
memset(m->bofram, 0, sizeof(m->bofram));
memset(&m->freelist, 0, sizeof(m->freelist));
bzero(m->reg, sizeof(m->reg));
bzero(m->bofram, sizeof(m->bofram));
bzero(&m->freelist, sizeof(m->freelist));
ResetSse(m);
ResetFpu(m);
}
void ResetTlb(struct Machine *m) {
m->tlbindex = 0;
memset(m->tlb, 0, sizeof(m->tlb));
bzero(m->tlb, sizeof(m->tlb));
m->codevirt = 0;
m->codehost = 0;
}

View file

@ -779,7 +779,7 @@ static void OpSsePalignrMmx(struct Machine *m, uint32_t rde) {
char t[24];
memcpy(t, GetModrmRegisterXmmPointerRead8(m, rde), 8);
memcpy(t + 8, XmmRexrReg(m, rde), 8);
memset(t + 16, 0, 8);
bzero(t + 16, 8);
memcpy(XmmRexrReg(m, rde), t + MIN(m->xedd->op.uimm0, 16), 8);
}

View file

@ -141,6 +141,13 @@ void OpPopZvq(struct Machine *m, uint32_t rde) {
}
static void OpCall(struct Machine *m, uint32_t rde, uint64_t func) {
if (!func) {
/*
* call null is technically possible but too fringe and disasterous
* to accommodate at least until our debugger has rewind capability
*/
HaltMachine(m, kMachineProtectionFault);
}
Push(m, rde, m->ip);
m->ip = func;
}

View file

@ -470,7 +470,7 @@ static int AppendIovsGuest(struct Machine *m, struct Iovs *iv, int64_t iovaddr,
static struct sigaction *CoerceSigactionToCosmo(
struct sigaction *dst, const struct sigaction_linux *src) {
if (!src) return NULL;
memset(dst, 0, sizeof(*dst));
bzero(dst, sizeof(*dst));
ASSIGN(dst->sa_handler, src->sa_handler);
ASSIGN(dst->sa_restorer, src->sa_restorer);
ASSIGN(dst->sa_flags, src->sa_flags);
@ -481,7 +481,7 @@ static struct sigaction *CoerceSigactionToCosmo(
static struct sigaction_linux *CoerceSigactionToLinux(
struct sigaction_linux *dst, const struct sigaction *src) {
if (!dst) return NULL;
memset(dst, 0, sizeof(*dst));
bzero(dst, sizeof(*dst));
ASSIGN(dst->sa_handler, src->sa_handler);
ASSIGN(dst->sa_restorer, src->sa_restorer);
ASSIGN(dst->sa_flags, src->sa_flags);
@ -1179,7 +1179,7 @@ static int OpSigsuspend(struct Machine *m, int64_t maskaddr) {
void *p;
sigset_t mask;
if (!(p = LoadBuf(m, maskaddr, 8))) return efault();
memset(&mask, 0, sizeof(mask));
bzero(&mask, sizeof(mask));
memcpy(&mask, p, 8);
return sigsuspend(&mask);
}
@ -1246,7 +1246,7 @@ static int OpSigprocmask(struct Machine *m, int how, int64_t setaddr,
sigset_t *set, oldset, ss;
if (setaddr) {
set = &ss;
memset(set, 0, sizeof(ss));
bzero(set, sizeof(ss));
VirtualSendRead(m, set, setaddr, 8);
} else {
set = NULL;
@ -1326,6 +1326,9 @@ static int DoAccept(struct Machine *m, int fd, int64_t addraddr,
void OpSyscall(struct Machine *m, uint32_t rde) {
uint64_t i, ax, di, si, dx, r0, r8, r9;
ax = Read64(m->ax);
if (m->ismetal) {
WARNF("metal syscall 0x%03x", ax);
}
di = Read64(m->di);
si = Read64(m->si);
dx = Read64(m->dx);
@ -1440,7 +1443,7 @@ void OpSyscall(struct Machine *m, uint32_t rde) {
SYSCALL(0x177, vmsplice(di, P(si), dx, r0));
CASE(0xE7, HaltMachine(m, di | 0x100));
default:
VERBOSEF("missing syscall 0x%03x", ax);
WARNF("missing syscall 0x%03x", ax);
ax = enosys();
break;
}

View file

@ -28,7 +28,7 @@
static bool IsHaltingInitialized(struct Machine *m) {
jmp_buf zb;
memset(zb, 0, sizeof(zb));
bzero(zb, sizeof(zb));
return memcmp(m->onhalt, zb, sizeof(m->onhalt)) != 0;
}

View file

@ -18,7 +18,6 @@
*/
#include "libc/errno.h"
#include "libc/mem/mem.h"
#include "libc/runtime/carsort.h"
#include "tool/build/lib/xlaterrno.h"
struct thatispacked LinuxErrno {

View file

@ -161,7 +161,7 @@ int main(int argc, char *argv[]) {
unsigned char ch = data[i];
if (col == 0) {
fprintf(fout, "\t.byte\t");
memset(glyphs, 0, sizeof(glyphs));
bzero(glyphs, sizeof(glyphs));
}
/* TODO(jart): Fix Emacs */
glyphs[col] = kCp437[ch == '"' || ch == '#' ? '.' : ch];

View file

@ -178,7 +178,7 @@ unsigned GetSourceId(const char *name, size_t len) {
do {
i = (hash + step * (step + 1) / 2) & (sources.n - 1);
if (sources.p[i].hash == hash &&
memcmp(name, &strings.p[sources.p[i].name], len) == 0) {
!timingsafe_bcmp(name, &strings.p[sources.p[i].name], len)) {
return sources.p[i].id;
}
step++;
@ -252,7 +252,7 @@ void LoadRelationships(int argc, char *argv[]) {
CHECK_NE(-1, (rc = read(fd, buf, MAX_READ)));
close(fd);
size = rc;
memset(buf + size, 0, 16);
bzero(buf + size, 16);
for (p = buf, pe = p + size; p < pe; ++p) {
p = strstr(p, kIncludePrefix);
if (!p) break;
@ -385,7 +385,7 @@ int main(int argc, char *argv[]) {
needprefix = !startswith(path, "o/");
prefix = !needprefix ? "" : buildroot;
fprintf(fout, "\n%s%s.o: \\\n\t%s", prefix, StripExt(path), path);
memset(visited, 0, bitmaplen);
bzero(visited, bitmaplen);
bts(visited, i);
Dive(i);
fprintf(fout, "\n");

View file

@ -266,7 +266,7 @@ void IndexSections(struct Object *obj) {
const Elf64_Shdr *shdr;
struct XedDecodedInst xedd;
for (i = 0; i < obj->elf->e_shnum; ++i) {
memset(&sect, 0, sizeof(sect));
bzero(&sect, sizeof(sect));
CHECK_NOTNULL((shdr = GetElfSectionHeaderAddress(obj->elf, obj->size, i)));
if (shdr->sh_type != SHT_NULL) {
CHECK_NOTNULL((name = GetElfSectionName(obj->elf, obj->size, shdr)));
@ -450,7 +450,7 @@ void CheckStrictDeps(struct Package *pkg, struct Packages *deps) {
}
}
free(pkg->undefs.p);
memset(&pkg->undefs, 0, sizeof(pkg->undefs));
bzero(&pkg->undefs, sizeof(pkg->undefs));
}
forceinline bool IsRipRelativeModrm(uint8_t modrm) {
@ -609,7 +609,7 @@ void CompressLowEntropyReadOnlyDataSections(struct Package *pkg,
Elf64_Shdr *shdr;
struct RlEncoder rle;
bool haverldecode, isprofitable;
memset(&rle, 0, sizeof(rle));
bzero(&rle, sizeof(rle));
haverldecode = IsSymbolDirectlyReachable(pkg, deps, "rldecode");
for (i = 0; i < obj->elf->e_shnum; ++i) {
if ((shdr = GetElfSectionHeaderAddress(obj->elf, obj->size, i)) &&
@ -625,7 +625,8 @@ void CompressLowEntropyReadOnlyDataSections(struct Package *pkg,
INFOF("%s(%s): rlencode()%s on %s is%s profitable (%,zu → %,zu bytes)",
&pkg->strings.p[pkg->path], &pkg->strings.p[obj->path],
haverldecode ? "" : " [NOT LINKED]", name,
isprofitable ? "" : " NOT", shdr->sh_size, rle.i * sizeof(rle.p[0]));
isprofitable ? "" : " NOT", shdr->sh_size,
rle.i * sizeof(rle.p[0]));
}
}
free(rle.p);
@ -681,8 +682,8 @@ int main(int argc, char *argv[]) {
struct Packages deps;
if (argc == 2 && !strcmp(argv[1], "-n")) exit(0);
showcrashreports();
memset(&pkg, 0, sizeof(pkg));
memset(&deps, 0, sizeof(deps));
bzero(&pkg, sizeof(pkg));
bzero(&deps, sizeof(deps));
Package(argc, argv, &pkg, &deps);
return 0;
}

View file

@ -80,7 +80,7 @@
L.c += L.c >> 1; \
L.p = realloc(L.p, L.c * sizeof(*L.p)); \
} \
memset(L.p + L.n - 1, 0, sizeof(*L.p)); \
bzero(L.p + L.n - 1, sizeof(*L.p)); \
} while (0)
struct Trace {
@ -705,7 +705,7 @@ static void Parse(struct Trace *t, const char *line, long lineno) {
}
CHECK_LT((arg = t->events.p[event].arity++), 6);
if (isalpha(*p) && !startswith(p, "NULL")) {
memset(&b, 0, sizeof(b));
bzero(&b, sizeof(b));
for (; isalpha(*p) || *p == '_'; ++p) {
AppendSlice(&b, *p);
}
@ -732,7 +732,7 @@ static void Parse(struct Trace *t, const char *line, long lineno) {
CHECK_NOTNULL((p = strchr(p, '}')), DEBUG);
++p;
} else if (*p == '"') {
memset(&b, 0, sizeof(b));
bzero(&b, sizeof(b));
for (j = 0; (c = p[++j]);) {
if (c == '"') {
p += j + 1;
@ -762,7 +762,7 @@ static void Parse(struct Trace *t, const char *line, long lineno) {
if (*p == ',') ++p;
if (*p == ' ') ++p;
CHECK_EQ('"', *p, DEBUG);
memset(&b, 0, sizeof(b));
bzero(&b, sizeof(b));
for (k = 0; (c = p[++k]);) {
if (c == '"') {
p += k + 1;

View file

@ -148,7 +148,9 @@ int RunLengthEncode1(void) {
return feof(fin_) ? 0 : -1;
}
int RunLengthEncode2(void) { return fputc(0, fout_) | fputc(0, fout_); }
int RunLengthEncode2(void) {
return fputc(0, fout_) | fputc(0, fout_);
}
int EmitRun(unsigned char count, unsigned char byte) {
do {

View file

@ -349,7 +349,7 @@ int ReadResponse(void) {
unsigned char b[512];
for (res = -1; res == -1;) {
if (!Recv(b, 5)) break;
CHECK_EQ(RUNITD_MAGIC, READ32BE(b));
CHECK_EQ(RUNITD_MAGIC, READ32BE(b), "%#.5s", b);
switch (b[4]) {
case kRunitExit:
if (!Recv(b, 1)) break;

View file

@ -215,12 +215,12 @@ void StartTcpServer(void) {
void SendExitMessage(int rc) {
unsigned char msg[4 + 1 + 1];
msg[0 + 0] = (unsigned char)((unsigned)RUNITD_MAGIC >> 030);
msg[0 + 1] = (unsigned char)((unsigned)RUNITD_MAGIC >> 020);
msg[0 + 2] = (unsigned char)((unsigned)RUNITD_MAGIC >> 010);
msg[0 + 3] = (unsigned char)((unsigned)RUNITD_MAGIC >> 000);
msg[0 + 0] = (RUNITD_MAGIC & 0xff000000) >> 030;
msg[0 + 1] = (RUNITD_MAGIC & 0x00ff0000) >> 020;
msg[0 + 2] = (RUNITD_MAGIC & 0x0000ff00) >> 010;
msg[0 + 3] = (RUNITD_MAGIC & 0x000000ff) >> 000;
msg[4] = kRunitExit;
msg[5] = (unsigned char)rc;
msg[5] = rc;
CHECK_EQ(sizeof(msg), mbedtls_ssl_write(&ezssl, msg, sizeof(msg)));
CHECK_EQ(0, EzTlsFlush(&ezbio, 0, 0));
}
@ -230,15 +230,15 @@ void SendOutputFragmentMessage(enum RunitCommand kind, unsigned char *buf,
ssize_t rc;
size_t sent;
unsigned char msg[4 + 1 + 4];
msg[0 + 0] = (unsigned char)((unsigned)RUNITD_MAGIC >> 030);
msg[0 + 1] = (unsigned char)((unsigned)RUNITD_MAGIC >> 020);
msg[0 + 2] = (unsigned char)((unsigned)RUNITD_MAGIC >> 010);
msg[0 + 3] = (unsigned char)((unsigned)RUNITD_MAGIC >> 000);
msg[0 + 0] = (RUNITD_MAGIC & 0xff000000) >> 030;
msg[0 + 1] = (RUNITD_MAGIC & 0x00ff0000) >> 020;
msg[0 + 2] = (RUNITD_MAGIC & 0x0000ff00) >> 010;
msg[0 + 3] = (RUNITD_MAGIC & 0x000000ff) >> 000;
msg[4 + 0] = kind;
msg[5 + 0] = (unsigned char)((unsigned)size >> 030);
msg[5 + 1] = (unsigned char)((unsigned)size >> 020);
msg[5 + 2] = (unsigned char)((unsigned)size >> 010);
msg[5 + 3] = (unsigned char)((unsigned)size >> 000);
msg[5 + 0] = (size & 0xff000000) >> 030;
msg[5 + 1] = (size & 0x00ff0000) >> 020;
msg[5 + 2] = (size & 0x0000ff00) >> 010;
msg[5 + 3] = (size & 0x000000ff) >> 000;
CHECK_EQ(sizeof(msg), mbedtls_ssl_write(&ezssl, msg, sizeof(msg)));
while (size) {
CHECK_NE(-1, (rc = mbedtls_ssl_write(&ezssl, buf, size)));

View file

@ -45,6 +45,7 @@ bool basenamify_;
int64_t image_base_;
int strip_components_;
const char *path_prefix_;
struct timespec timestamp;
wontreturn void PrintUsage(int rc, FILE *f) {
fprintf(f, "%s%s%s\n", "Usage: ", program_invocation_name,
@ -106,7 +107,6 @@ void ProcessFile(struct ElfWriter *elf, const char *path) {
size_t pathlen;
struct stat st;
const char *name;
struct timespec timestamp;
CHECK_NE(-1, (fd = open(path, O_RDONLY)));
CHECK_NE(-1, fstat(fd, &st));
if (S_ISDIR(st.st_mode)) {
@ -127,11 +127,11 @@ void ProcessFile(struct ElfWriter *elf, const char *path) {
if (path_prefix_) name = gc(xjoinpaths(path_prefix_, name));
}
if (S_ISDIR(st.st_mode)) {
st.st_size = 0;
if (!endswith(name, "/")) {
name = gc(xasprintf("%s/", name));
}
}
memset(&timestamp, 0, sizeof(timestamp));
elfwriter_zip(elf, name, name, strlen(name), map, st.st_size, st.st_mode,
timestamp, timestamp, timestamp, nocompress_, image_base_);
if (st.st_size) CHECK_NE(-1, munmap(map, st.st_size));

View file

@ -82,6 +82,8 @@
#define IsPlus(C) ((C) == '+' || (C) == u'┼')
#define IsHyphen(C) ((C) == '-' || (C) == u'─')
#define IsTick(C) ((C) == '`' || (C) == u'└')
#define IsPipe(C) ((C) == '|' || (C) == u'│')
#define IsEquals(C) ((C) == '=' || (C) == u'═')
int n;
int yn;
@ -98,6 +100,9 @@ static void DoIt(int y, int x) {
if (IsPipe(L[y - 1][x]) && IsHyphen(L[y][x - 1]) && IsPlus(L[y][x]) &&
IsHyphen(L[y][x + 1]) && IsPipe(L[y + 1][x])) {
L[y][x] = u'';
} else if (IsPipe(L[y - 1][x]) && IsEquals(L[y][x - 1]) && IsPlus(L[y][x]) &&
IsEquals(L[y][x + 1]) && IsPipe(L[y + 1][x])) {
L[y][x] = u'';
} else if (IsSpace(L[y - 1][x]) && IsHyphen(L[y][x - 1]) &&
IsHyphen(L[y][x]) && IsHyphen(L[y][x + 1]) &&
IsPipe(L[y + 1][x])) {
@ -127,10 +132,12 @@ static void DoIt(int y, int x) {
} else if (IsTick(L[y][x]) && IsPipe(L[y - 1][x]) && IsHyphen(L[y][x + 1]) &&
IsSpace(L[y + 1][x]) && IsSpace(L[y][x - 1])) {
L[y][x] = u'';
} else if (L[y][x] == '-') {
} else if (IsHyphen(L[y][x])) {
L[y][x] = u'';
} else if (L[y][x] == '|') {
} else if (IsPipe(L[y][x])) {
L[y][x] = u'';
} else if (IsEquals(L[y][x])) {
L[y][x] = u'';
} else {
return;
}

View file

@ -263,6 +263,8 @@
"__builtin_mempcpy"
"__builtin_memmove"
"__builtin_memcmp"
"__builtin_bcmp"
"__builtin_bzero"
"__builtin_memset"
"__builtin_strlen"))

View file

@ -104,7 +104,9 @@
"FLT_MAX"))
(defconst cosmo-c-constants-math
'("M_E"
'("NAN"
"INFINITY"
"M_E"
"M_LOG2_10"
"M_LOG10_2"
"M_LOG2E"

View file

@ -173,10 +173,10 @@
(file (file-relative-name this root)) ;; e.g. "libc/crc32c.c"
(name (file-name-sans-extension file)) ;; e.g. "libc/crc32c"
(buddy (format "test/%s_test.c" name))
(runs (format "o/$m/%s.com.runs TESTARGS=-b" name))
(buns (format "o/$m/test/%s_test.com.runs TESTARGS=-b" name)))
(runs (format "o/$m/%s.com.runs V=5 TESTARGS=-b" name))
(buns (format "o/$m/test/%s_test.com.runs V=5 TESTARGS=-b" name)))
(cond ((not (member ext '("c" "cc" "s" "S" "rl" "f")))
(format "m=%s; make -j8 -O MODE=$m V=1 o/$m/%s"
(format "m=%s; make -j8 -O MODE=$m o/$m/%s"
mode
(directory-file-name
(file-name-directory
@ -189,7 +189,7 @@
(file-exists-p (format "%s" buddy)))
(format (cosmo-join
" && "
'("m=%s; n=%s; make -j8 -O o/$m/$n%s.o MODE=$m V=1"
'("m=%s; n=%s; make -j8 -O o/$m/$n%s.o MODE=$m"
;; "bloat o/$m/%s.o | head"
;; "nm -C --size o/$m/%s.o | sort -r"
"echo"
@ -201,7 +201,7 @@
(cosmo-join
" && "
`("m=%s; f=o/$m/%s.com"
,(concat "make -j8 -O $f MODE=$m V=1")
,(concat "make -j8 -O $f MODE=$m")
"./$f"))
mode name))
((eq kind 'run-win7)
@ -209,7 +209,7 @@
(cosmo-join
" && "
`("m=%s; f=o/$m/%s.com"
,(concat "make -j8 -O $f MODE=$m V=1")
,(concat "make -j8 -O $f MODE=$m")
"scp $f $f.dbg win7:"
"ssh win7 ./%s.com"))
mode name (file-name-nondirectory name)))
@ -218,7 +218,7 @@
(cosmo-join
" && "
`("m=%s; f=o/$m/%s.com"
,(concat "make -j8 -O $f MODE=$m V=1")
,(concat "make -j8 -O $f MODE=$m")
"scp $f $f.dbg win10:"
"ssh win10 ./%s.com"))
mode name (file-name-nondirectory name)))
@ -230,7 +230,7 @@
(cosmo-join
" && "
`("m=%s; f=o/$m/%s%s.o"
,(concat "make -j8 -O $f MODE=$m V=1")
,(concat "make -j8 -O $f MODE=$m")
;; "nm -C --size $f | sort -r"
"echo"
"size -A $f | grep '^[.T]' | grep -v 'debug\\|command.line\\|stack' | sort -rnk2"
@ -439,7 +439,7 @@
(error "don't know how to show assembly for non c/c++ source file"))
(let* ((default-directory root)
(compile-command
(format "make %s V=1 -j8 -O MODE=%s %s %s"
(format "make %s -j8 -O MODE=%s %s %s"
(or extra-make-flags "") mode asm-gcc asm-clang)))
(save-buffer)
(set-visited-file-modtime (current-time))
@ -492,7 +492,7 @@
(defun cosmo-assembly-balanced (arg)
(interactive "P")
(cosmo--assembly (or arg 5) "CFLAGS='-O2 -ftrapv' CPPFLAGS='-DSTACK_FRAME_UNLIMITED' V=1"))
(cosmo--assembly (or arg 5) "CFLAGS='-O2 -ftrapv' CPPFLAGS='-DSTACK_FRAME_UNLIMITED'"))
(defun cosmo-mca (arg)
(interactive "P")
@ -596,8 +596,8 @@
((and (eq major-mode 'python-mode)
(cosmo-startswith "third_party/python/Lib/test/" file))
(let ((mode (cosmo--make-mode arg)))
(compile (format "make -j8 MODE=%s o/%s/%s.com.runs" mode mode
(file-name-sans-extension file)))))
(compile (format "make -j8 MODE=%s PYHARNESSARGS=-vv PYTESTARGS=-v o/%s/%s.py.runs"
mode mode (file-name-sans-extension file)))))
((eq major-mode 'python-mode)
(compile (format "python3 %s" file)))
('t

View file

@ -147,7 +147,7 @@ void GetListeningAddressesFromCommandLine(int argc, char *argv[]) {
int i;
for (i = optind; i < argc; ++i) {
struct Socket server;
memset(&server, 0, sizeof(server));
bzero(&server, sizeof(server));
char scheme[4];
unsigned char *ip4 = (unsigned char *)&server.addr.sin_addr.s_addr;
uint16_t port;
@ -196,7 +196,7 @@ void BeginListeningForIncomingTraffic(void) {
void AcceptConnection(size_t i) {
struct Socket *server = &g_sockets.p[i];
struct Socket client;
memset(&client, 0, sizeof(client));
bzero(&client, sizeof(client));
client.kind = kSocketClient;
client.type = server->type;
client.protocol = server->protocol;
@ -211,7 +211,7 @@ bool ReceiveData(size_t i) {
ssize_t got;
struct Message msg;
bool isudp = g_sockets.p[i].protocol == IPPROTO_UDP;
memset(&msg, 0, sizeof(msg));
bzero(&msg, sizeof(msg));
msg.destsize = sizeof(msg.dest);
msg.data.iov_len = PAGESIZE;
msg.data.iov_base = xmalloc(msg.data.iov_len);
@ -287,7 +287,7 @@ int main(int argc, char *argv[]) {
GetListeningAddressesFromCommandLine(argc, argv);
BeginListeningForIncomingTraffic();
struct InterruptibleCall icall;
memset(&icall, 0, sizeof(icall));
bzero(&icall, sizeof(icall));
interruptiblecall(&icall, (void *)EchoServer, 0, 0, 0, 0);
fputc('\r', stderr);
INFOF("%s", "shutting down...");

View file

@ -94,7 +94,7 @@ o/$(MODE)/tool/net/redbean.com.dbg: \
o/$(MODE)/tool/net/redbean.com: \
o/$(MODE)/tool/net/redbean.com.dbg \
o/$(MODE)/host/third_party/infozip/zip.com \
o/$(MODE)/third_party/infozip/zip.com \
tool/net/net.mk \
tool/net/help.txt \
tool/net/.init.lua \
@ -102,7 +102,7 @@ o/$(MODE)/tool/net/redbean.com: \
tool/net/redbean.png
@$(COMPILE) -AOBJCOPY -T$@ $(OBJCOPY) -S -O binary $< $@
@$(COMPILE) -ADD -T$@ dd if=$@ of=o/$(MODE)/tool/net/.ape bs=64 count=11 conv=notrunc 2>/dev/null
@$(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -qj $@ o/$(MODE)/tool/net/.ape tool/net/help.txt tool/net/.init.lua tool/net/favicon.ico tool/net/redbean.png
@$(COMPILE) -AZIP -T$@ o/$(MODE)/third_party/infozip/zip.com -qj $@ o/$(MODE)/tool/net/.ape tool/net/help.txt tool/net/.init.lua tool/net/favicon.ico tool/net/redbean.png
# REDBEAN-DEMO.COM
#
@ -175,7 +175,7 @@ o/$(MODE)/tool/net/redbean-demo.com: \
@$(COMPILE) -AOBJCOPY -T$@ $(OBJCOPY) -S -O binary $< $@
@$(COMPILE) -AMKDIR -T$@ mkdir -p o/$(MODE)/tool/net/.redbean-demo
@$(COMPILE) -ADD -T$@ dd if=$@ of=o/$(MODE)/tool/net/.redbean-demo/.ape bs=64 count=11 conv=notrunc 2>/dev/null
@$(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -qj $@ o/$(MODE)/tool/net/.redbean-demo/.ape
@$(COMPILE) -AZIP -T$@ o/$(MODE)/third_party/infozip/zip.com -qj $@ o/$(MODE)/tool/net/.redbean-demo/.ape
# REDBEAN-STATIC.COM
#
@ -184,14 +184,14 @@ o/$(MODE)/tool/net/redbean-demo.com: \
o/$(MODE)/tool/net/redbean-static.com: \
o/$(MODE)/tool/net/redbean-static.com.dbg \
o/$(MODE)/host/third_party/infozip/zip.com \
o/$(MODE)/third_party/infozip/zip.com \
tool/net/help.txt \
tool/net/favicon.ico \
tool/net/redbean.png
@$(COMPILE) -AOBJCOPY -T$@ $(OBJCOPY) -S -O binary $< $@
@$(COMPILE) -AMKDIR -T$@ mkdir -p o/$(MODE)/tool/net/.redbean-static
@$(COMPILE) -ADD -T$@ dd if=$@ of=o/$(MODE)/tool/net/.redbean-static/.ape bs=64 count=11 conv=notrunc 2>/dev/null
@$(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -qj $@ o/$(MODE)/tool/net/.redbean-static/.ape tool/net/help.txt tool/net/favicon.ico tool/net/redbean.png
@$(COMPILE) -AZIP -T$@ o/$(MODE)/third_party/infozip/zip.com -qj $@ o/$(MODE)/tool/net/.redbean-static/.ape tool/net/help.txt tool/net/favicon.ico tool/net/redbean.png
o/$(MODE)/tool/net/redbean-static.com.dbg: \
$(TOOL_NET_DEPS) \
@ -212,14 +212,14 @@ o/$(MODE)/tool/net/redbean-static.o: tool/net/redbean.c o/$(MODE)/tool/net/redbe
o/$(MODE)/tool/net/redbean-unsecure.com: \
o/$(MODE)/tool/net/redbean-unsecure.com.dbg \
o/$(MODE)/host/third_party/infozip/zip.com \
o/$(MODE)/third_party/infozip/zip.com \
tool/net/help.txt \
tool/net/favicon.ico \
tool/net/redbean.png
@$(COMPILE) -AOBJCOPY -T$@ $(OBJCOPY) -S -O binary $< $@
@$(COMPILE) -AMKDIR -T$@ mkdir -p o/$(MODE)/tool/net/.redbean-unsecure
@$(COMPILE) -ADD -T$@ dd if=$@ of=o/$(MODE)/tool/net/.redbean-unsecure/.ape bs=64 count=11 conv=notrunc 2>/dev/null
@$(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -qj $@ o/$(MODE)/tool/net/.redbean-unsecure/.ape tool/net/help.txt tool/net/favicon.ico tool/net/redbean.png
@$(COMPILE) -AZIP -T$@ o/$(MODE)/third_party/infozip/zip.com -qj $@ o/$(MODE)/tool/net/.redbean-unsecure/.ape tool/net/help.txt tool/net/favicon.ico tool/net/redbean.png
o/$(MODE)/tool/net/redbean-unsecure.com.dbg: \
$(TOOL_NET_DEPS) \
@ -241,14 +241,14 @@ o/$(MODE)/tool/net/redbean-unsecure.o: tool/net/redbean.c o/$(MODE)/tool/net/red
o/$(MODE)/tool/net/redbean-original.com: \
o/$(MODE)/tool/net/redbean-original.com.dbg \
o/$(MODE)/host/third_party/infozip/zip.com \
o/$(MODE)/third_party/infozip/zip.com \
tool/net/help.txt \
tool/net/favicon.ico \
tool/net/redbean.png
@$(COMPILE) -AOBJCOPY -T$@ $(OBJCOPY) -S -O binary $< $@
@$(COMPILE) -AMKDIR -T$@ mkdir -p o/$(MODE)/tool/net/.redbean-original
@$(COMPILE) -ADD -T$@ dd if=$@ of=o/$(MODE)/tool/net/.redbean-original/.ape bs=64 count=11 conv=notrunc 2>/dev/null
@$(COMPILE) -AZIP -T$@ o/$(MODE)/host/third_party/infozip/zip.com -qj $@ o/$(MODE)/tool/net/.redbean-original/.ape tool/net/help.txt tool/net/favicon.ico tool/net/redbean.png
@$(COMPILE) -AZIP -T$@ o/$(MODE)/third_party/infozip/zip.com -qj $@ o/$(MODE)/tool/net/.redbean-original/.ape tool/net/help.txt tool/net/favicon.ico tool/net/redbean.png
o/$(MODE)/tool/net/redbean-original.com.dbg: \
$(TOOL_NET_DEPS) \

View file

@ -1633,38 +1633,34 @@ static struct Cert GetKeySigningKey(void) {
static struct Cert GenerateEcpCertificate(struct Cert *ca) {
mbedtls_pk_context *key;
mbedtls_md_type_t md_alg;
mbedtls_ctr_drbg_context kr;
mbedtls_x509write_cert wcert;
InitializeRng(&kr);
md_alg = suiteb ? MBEDTLS_MD_SHA384 : MBEDTLS_MD_SHA256;
key = InitializeKey(ca, &wcert, md_alg, MBEDTLS_PK_ECKEY);
CHECK_EQ(0, mbedtls_ecp_gen_key(
suiteb ? MBEDTLS_ECP_DP_SECP384R1 : MBEDTLS_ECP_DP_SECP256R1,
mbedtls_pk_ec(*key), mbedtls_ctr_drbg_random, &kr));
GenerateCertificateSerial(&wcert, &kr);
mbedtls_pk_ec(*key), GenerateHardRandom, 0));
GenerateCertificateSerial(&wcert);
ConfigureCertificate(&wcert, ca, MBEDTLS_X509_KU_DIGITAL_SIGNATURE,
MBEDTLS_X509_NS_CERT_TYPE_SSL_SERVER |
MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT);
return FinishCertificate(ca, &wcert, &kr, key);
return FinishCertificate(ca, &wcert, key);
}
static struct Cert GenerateRsaCertificate(struct Cert *ca) {
mbedtls_pk_context *key;
mbedtls_md_type_t md_alg;
mbedtls_ctr_drbg_context kr;
mbedtls_x509write_cert wcert;
InitializeRng(&kr);
md_alg = suiteb ? MBEDTLS_MD_SHA384 : MBEDTLS_MD_SHA256;
key = InitializeKey(ca, &wcert, md_alg, MBEDTLS_PK_RSA);
CHECK_EQ(0, mbedtls_rsa_gen_key(mbedtls_pk_rsa(*key), mbedtls_ctr_drbg_random,
&kr, suiteb ? 4096 : 2048, 65537));
GenerateCertificateSerial(&wcert, &kr);
CHECK_EQ(0, mbedtls_rsa_gen_key(mbedtls_pk_rsa(*key), GenerateHardRandom, 0,
suiteb ? 4096 : 2048, 65537));
GenerateCertificateSerial(&wcert);
ConfigureCertificate(
&wcert, ca,
MBEDTLS_X509_KU_DIGITAL_SIGNATURE | MBEDTLS_X509_KU_KEY_ENCIPHERMENT,
MBEDTLS_X509_NS_CERT_TYPE_SSL_SERVER |
MBEDTLS_X509_NS_CERT_TYPE_SSL_CLIENT);
return FinishCertificate(ca, &wcert, &kr, key);
return FinishCertificate(ca, &wcert, key);
}
static void LoadCertificates(void) {
@ -2363,7 +2359,6 @@ static ssize_t DeflateGenerator(struct iovec v[3]) {
static char *ServeAssetCompressed(struct Asset *a) {
char *p;
uint32_t crc;
uint8_t rando[2];
LockInc(&shared->c.deflates);
LockInc(&shared->c.compressedresponses);
DEBUGF("(srvr) ServeAssetCompressed()");
@ -2371,15 +2366,15 @@ static char *ServeAssetCompressed(struct Asset *a) {
dg.i = 0;
dg.c = 0;
if (usessl) {
mbedtls_ctr_drbg_random(&rng, rando, sizeof(rando));
dg.z = 512 + (READ16LE(rando) & 1023);
dg.z = 512 + (rand64() & 1023);
} else {
dg.z = 65536;
}
gzipped = true;
generator = DeflateGenerator;
CHECK_EQ(Z_OK, deflateInit2(memset(&dg.s, 0, sizeof(dg.s)), 4, Z_DEFLATED,
-MAX_WBITS, DEF_MEM_LEVEL, Z_DEFAULT_STRATEGY));
bzero(&dg.s, sizeof(dg.s));
CHECK_EQ(Z_OK, deflateInit2(&dg.s, 4, Z_DEFLATED, -MAX_WBITS, DEF_MEM_LEVEL,
Z_DEFAULT_STRATEGY));
dg.b = FreeLater(malloc(dg.z));
p = SetStatus(200, "OK");
p = stpcpy(p, "Content-Encoding: gzip\r\n");
@ -2667,7 +2662,7 @@ td { padding-right: 3em; }\r\n\
"<pre>\r\n",
strnlen(GetZipCdirComment(zcdir), GetZipCdirCommentSize(zcdir)),
GetZipCdirComment(zcdir));
memset(w, 0, sizeof(w));
bzero(w, sizeof(w));
n = GetZipCdirRecords(zcdir);
for (zcf = zbase + GetZipCdirOffset(zcdir); n--;
zcf += ZIP_CFILE_HDRSIZE(zcf)) {
@ -3398,7 +3393,7 @@ static wontreturn void LuaThrowTlsError(lua_State *L, const char *s, int r) {
const char *code;
code = gc(xasprintf("-0x%04x", -r));
if (!IsTiny()) {
luaL_error(L, "tls %s failed (%s %s)", s, code, TlsError(r));
luaL_error(L, "tls %s failed (%s %s)", s, code, GetTlsError(r));
} else {
luaL_error(L, "tls %s failed (grep %s)", s, code);
}
@ -3701,7 +3696,7 @@ static int LuaFetch(lua_State *L) {
/*
* Handle response.
*/
memset(&inbuf, 0, sizeof(inbuf));
bzero(&inbuf, sizeof(inbuf));
InitHttpMessage(&msg, kHttpResponse);
for (hdrsize = paylen = t = 0;;) {
if (inbuf.n == inbuf.c) {
@ -3768,7 +3763,7 @@ static int LuaFetch(lua_State *L) {
!HeaderEqualCase(kHttpTransferEncoding, "identity")) {
if (HeaderEqualCase(kHttpTransferEncoding, "chunked")) {
t = kHttpClientStateBodyChunked;
memset(&u, 0, sizeof(u));
bzero(&u, sizeof(u));
goto Chunked;
} else {
WARNF("(ftch) HTTP client %s error", "Transfer-Encoding");
@ -4216,8 +4211,9 @@ static int LuaSetCookie(lua_State *L) {
keylen > strlen(securepref) &&
SlicesEqual(key, strlen(securepref), securepref, strlen(securepref));
if ((ishostpref || issecurepref) && !usessl) {
luaL_argerror(L, 1,
gc(xasprintf("%s and %s prefixes require SSL", hostpref, securepref)));
luaL_argerror(
L, 1,
gc(xasprintf("%s and %s prefixes require SSL", hostpref, securepref)));
unreachable;
}
@ -4354,7 +4350,7 @@ static int LuaParseParams(lua_State *L) {
const char *data;
struct UrlParams h;
data = luaL_checklstring(L, 1, &size);
memset(&h, 0, sizeof(h));
bzero(&h, sizeof(h));
m = ParseParams(data, size, &h);
LuaPushUrlParams(L, &h);
free(h.p);
@ -4394,7 +4390,7 @@ static int LuaParseHost(lua_State *L) {
size_t n;
struct Url h;
const char *p;
memset(&h, 0, sizeof(h));
bzero(&h, sizeof(h));
p = luaL_checklstring(L, 1, &n);
m = ParseHost(p, n, &h);
lua_newtable(L);
@ -4411,7 +4407,7 @@ static int LuaEncodeUrl(lua_State *L) {
int i, j, k, n;
const char *data;
if (!lua_isnil(L, 1)) {
memset(&h, 0, sizeof(h));
bzero(&h, sizeof(h));
luaL_checktype(L, 1, LUA_TTABLE);
if (lua_getfield(L, 1, "scheme"))
h.scheme.p = lua_tolstring(L, -1, &h.scheme.n);
@ -6187,7 +6183,7 @@ static bool StreamResponse(char *p) {
if (logmessages) {
LogMessage("sending", hdrbuf.p, p - hdrbuf.p);
}
memset(iov, 0, sizeof(iov));
bzero(iov, sizeof(iov));
if (msg.version >= 10) {
iov[0].iov_base = hdrbuf.p;
iov[0].iov_len = p - hdrbuf.p;
@ -6595,7 +6591,7 @@ static void Listen(void) {
servers.p = malloc(ips.n * ports.n * sizeof(*servers.p));
for (n = i = 0; i < ips.n; ++i) {
for (j = 0; j < ports.n; ++j, ++n) {
memset(servers.p + n, 0, sizeof(*servers.p));
bzero(servers.p + n, sizeof(*servers.p));
servers.p[n].addr.sin_family = AF_INET;
servers.p[n].addr.sin_port = htons(ports.p[j]);
servers.p[n].addr.sin_addr.s_addr = htonl(ips.p[i]);

View file

@ -251,7 +251,7 @@ SendAnother:
!HeaderEqualCase(kHttpTransferEncoding, "identity")) {
if (HeaderEqualCase(kHttpTransferEncoding, "chunked")) {
t = kHttpClientStateBodyChunked;
memset(&u, 0, sizeof(u));
bzero(&u, sizeof(u));
goto Chunked;
} else {
goto TransportError;

133
tool/viz/fontspace.c Normal file
View file

@ -0,0 +1,133 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2021 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "dsp/scale/cdecimate2xuint8x8.h"
#include "libc/calls/ioctl.h"
#include "libc/calls/struct/winsize.h"
#include "libc/fmt/conv.h"
#include "libc/log/libfatal.internal.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/bsr.h"
#include "libc/runtime/gc.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/termios.h"
#include "libc/x/x.h"
#include "third_party/getopt/getopt.h"
#include "third_party/stb/stb_truetype.h"
#define MAXCODE
int start;
int end = 0x03134A /* 0x10FFFD */;
int verbose;
struct winsize ws = {24, 80};
signed char kThePerfectKernel[8] = {-1, -3, 3, 17, 17, 3, -3, -1};
void PrintBar(unsigned char *p, size_t n) {
size_t i, j;
for (j = n; j > ws.ws_col - 32; j = (j + 1) >> 1) {
cDecimate2xUint8x8(j, p, kThePerfectKernel);
}
for (i = 0; i < j; ++i) {
if (p[i]) {
fputwc(u"░░▒▒▓▓██"[bsr(p[i])], stdout);
} else {
fputc(' ', stdout);
}
}
}
int main(int argc, char *argv[]) {
size_t n, m;
float scale;
void *bitmap;
size_t ttfsize;
const char *dir;
unsigned char *ttf;
stbtt_fontinfo font;
unsigned char *present;
unsigned char *intotal;
int w, h, i, j, c, arg, opt, errs, line, count, maxcode, s = 40 * 4, rc = 0;
ShowCrashReports();
ioctl(0, TIOCGWINSZ, &ws);
while ((opt = getopt(argc, argv, "vs:e:")) != -1) {
switch (opt) {
case 'v':
++verbose;
break;
case 's':
start = strtol(optarg, 0, 16);
break;
case 'e':
end = strtol(optarg, 0, 16);
break;
default:
return 1;
}
}
n = end + 1 - start;
m = ROUNDUP(n, 16);
present = gc(malloc(m));
intotal = gc(calloc(1, m));
if (optind < argc) {
for (arg = optind; arg < argc; ++arg) {
ttf = xslurp(argv[arg], &ttfsize);
if (!(line = setjmp(stbtt_jmpbuf))) {
stbtt_InitFont(&font, ttf, stbtt_GetFontOffsetForIndex(ttf, 0));
} else {
rc = 1;
fprintf(stderr, "%s: error loading font (assert @ stb_truetype.c:%d\n",
argv[arg], line);
free(ttf);
continue;
}
bzero(present, m);
for (maxcode = errs = 0, c = start; c <= end; ++c) {
if (!(line = setjmp(stbtt_jmpbuf))) {
if ((i = stbtt_FindGlyphIndex(&font, c)) > 0) {
w = h = 0;
scale = stbtt_ScaleForPixelHeight(&font, s);
bitmap = stbtt_GetGlyphBitmap(&font, 0, scale, i, &w, &h, 0, 0);
if (w && h) {
intotal[c - start] = present[c - start] = 255;
maxcode = c;
}
free(bitmap);
}
} else {
++errs;
}
}
PrintBar(present, m);
if (errs) {
printf(" %s (%d errors)\n", basename(argv[arg]), errs);
} else {
printf(" %s (%,d kb)\n", basename(argv[arg]), ttfsize / 1024);
}
free(ttf);
}
PrintBar(intotal, m);
fputc('\n', stdout);
}
return rc;
}

206
tool/viz/getglyph.c Normal file
View file

@ -0,0 +1,206 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2021 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/conv.h"
#include "libc/limits.h"
#include "libc/log/log.h"
#include "libc/macros.internal.h"
#include "libc/runtime/gc.internal.h"
#include "libc/stdio/append.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/tpenc.h"
#include "libc/sysv/consts/sig.h"
#include "libc/x/x.h"
#include "third_party/getopt/getopt.h"
#include "third_party/stb/stb_truetype.h"
#define SQR(x) ((x) * (x))
int end;
int start;
int verbose;
int difference;
struct Block {
char16_t c;
unsigned char b[4][2];
} kBlocks[] = {
{u' ', {{0000, 0000}, {0000, 0000}, {0000, 0000}, {0000, 0000}}}, //
{u'', {{0060, 0060}, {0060, 0060}, {0060, 0060}, {0060, 0060}}}, //
{u'', {{0140, 0140}, {0140, 0140}, {0140, 0140}, {0140, 0140}}}, //
{u'', {{0300, 0300}, {0300, 0300}, {0300, 0300}, {0300, 0300}}}, //
{u'', {{0377, 0377}, {0377, 0377}, {0377, 0377}, {0377, 0377}}}, //
{u'', {{0000, 0000}, {0000, 0000}, {0377, 0377}, {0377, 0377}}}, //
{u'', {{0377, 0000}, {0377, 0000}, {0377, 0000}, {0377, 0000}}}, //
{u'', {{0000, 0377}, {0000, 0377}, {0000, 0377}, {0000, 0377}}}, //
{u'', {{0377, 0377}, {0377, 0377}, {0000, 0000}, {0000, 0000}}}, //
};
static char *Raster(int yn, int xn, unsigned char Y[yn][xn], int *dw) {
char *r = 0;
unsigned char B[4][4];
int y, x, i, j, k, s, w, bi, bs;
*dw = 0;
for (y = 0; y < yn; y += 4) {
if (y) appendw(&r, '\n');
for (w = x = 0; x < xn; x += 4) {
for (i = 0; i < 4; ++i) {
for (j = 0; j < 4; ++j) {
if (y + i < yn && x + j < xn) {
B[i][j] = Y[y + i][x + j];
} else {
B[i][j] = 0;
}
}
}
bi = 0;
bs = INT_MAX;
for (k = 0; k < ARRAYLEN(kBlocks); ++k) {
s = 0;
for (i = 0; i < 4; ++i) {
for (j = 0; j < 4; ++j) {
s += SQR(B[i][j] - kBlocks[k].b[i][j / 2]);
}
}
if (s < bs) {
bi = k;
bs = s;
}
}
appendw(&r, tpenc(kBlocks[bi].c));
++w;
}
if (w > *dw) *dw = w;
}
return r;
}
void OnSig(int sig) {
exit(128 + sig);
}
int main(int argc, char *argv[]) {
char *p;
void *bmap;
float scale;
bool gotsome;
char **rasters;
char **fasters;
size_t ttfsize;
const char *dir;
bool isdifferent;
unsigned char **ttf;
stbtt_fontinfo *font;
int c, i, j, m, o, dw, maxw, *w, *h, s = 40 * 4;
struct sigaction sa = {.sa_handler = OnSig};
ShowCrashReports();
sigaction(SIGPIPE, &sa, 0);
start = 0;
end = 0x10FFFD;
while ((o = getopt(argc, argv, "vdc:s:e:S:")) != -1) {
switch (o) {
case 'v':
++verbose;
break;
case 'd':
difference = 1;
break;
case 'c':
start = end = strtol(optarg, 0, 16);
break;
case 's':
start = strtol(optarg, 0, 16);
break;
case 'e':
end = strtol(optarg, 0, 16);
break;
case 'S':
s = strtol(optarg, 0, 0);
break;
default:
return 1;
}
}
m = argc - optind;
w = gc(calloc(m, sizeof(*w)));
h = gc(calloc(m, sizeof(*h)));
ttf = gc(calloc(m, sizeof(*ttf)));
font = gc(calloc(m, sizeof(*font)));
rasters = gc(calloc(m, sizeof(*rasters)));
fasters = gc(calloc(m, sizeof(*fasters)));
for (j = 0; j < m; ++j) {
ttf[j] = gc(xslurp(argv[optind + j], &ttfsize));
if (!ttf[j]) {
fprintf(stderr, "%s: not found\n", argv[optind + j]);
exit(1);
}
stbtt_InitFont(font + j, ttf[j], stbtt_GetFontOffsetForIndex(ttf[j], 0));
printf("%s\n", argv[optind + j]);
}
for (c = start; c <= end; ++c) {
maxw = 0;
gotsome = false;
isdifferent = false;
for (j = 0; j < m; ++j) {
rasters[j] = 0;
if ((i = stbtt_FindGlyphIndex(font + j, c)) > 0) {
w[j] = 0;
h[j] = 0;
scale = stbtt_ScaleForPixelHeight(font + j, s);
bmap = stbtt_GetGlyphBitmap(font + j, 0, scale, i, w + j, h + j, 0, 0);
if (w[j] && h[j]) {
gotsome = true;
if (verbose) {
rasters[j] = Raster(h[j], w[j], bmap, &dw);
if (!isdifferent && j && rasters[j - 1] &&
strcmp(rasters[j], rasters[j - 1])) {
isdifferent = true;
}
if (dw > maxw) maxw = dw;
}
}
free(bmap);
}
}
if (gotsome) {
memcpy(fasters, rasters, m * sizeof(*rasters));
printf("%04X\n", c);
if (verbose && (!difference || isdifferent)) {
do {
gotsome = false;
for (j = 0; j < m; ++j) {
if (!rasters[j]) {
printf("%-*s ", maxw, "");
continue;
}
p = strchrnul(rasters[j], '\n');
if (p - rasters[j]) gotsome = true;
printf("%-*.*s ", maxw, p - rasters[j], rasters[j]);
rasters[j] = *p ? p + 1 : p;
}
printf("\n");
} while (gotsome);
printf("\n");
}
for (j = 0; j < m; ++j) {
free(fasters[j]);
}
}
}
return 0;
}

34
tool/viz/rsastrength.c Normal file
View file

@ -0,0 +1,34 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2021 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/fmt/conv.h"
#include "libc/math.h"
#include "libc/stdio/stdio.h"
int main(int argc, char *argv[]) {
int i, x, y;
for (i = 1; i < argc; ++i) {
x = atoi(argv[i]);
y = round(
(1.923 * cbrt(x * log(2)) * cbrt(log(x * log(2)) * log(x * log(2))) -
4.69) /
log(2));
printf("%4d %4d\n", x, y);
}
return 0;
}

View file

@ -50,6 +50,7 @@ TOOL_VIZ_DIRECTDEPS = \
THIRD_PARTY_GDTOA \
THIRD_PARTY_GETOPT \
THIRD_PARTY_STB \
THIRD_PARTY_MUSL \
THIRD_PARTY_XED \
THIRD_PARTY_ZLIB \
TOOL_DECODE_LIB \