Get Cosmopolitan into releasable state

A new rollup tool now exists for flattening out the headers in a way
that works better for our purposes than cpp. A lot of the API clutter
has been removed. APIs that aren't a sure thing in terms of general
recommendation are now marked internal.

There's now a smoke test for the amalgamation archive and gigantic
header file. So we can now guarantee you can use this project on the
easiest difficulty setting without the gigantic repository.

A website is being created, which is currently a work in progress:
https://justine.storage.googleapis.com/cosmopolitan/index.html
This commit is contained in:
Justine Tunney 2020-11-25 08:19:00 -08:00
parent dba7552c1e
commit ea0b5d9d1c
775 changed files with 6864 additions and 3963 deletions

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/alg/arraylist2.h"
#include "libc/alg/arraylist2.internal.h"
#include "libc/bits/bits.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/iovec.h"
@ -29,6 +29,7 @@
#include "libc/errno.h"
#include "libc/log/check.h"
#include "libc/macros.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/sock.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"

View file

@ -19,10 +19,10 @@
*/
#include "dsp/scale/cdecimate2xuint8x8.h"
#include "dsp/tty/tty.h"
#include "libc/alg/arraylist2.h"
#include "libc/alg/arraylist2.internal.h"
#include "libc/assert.h"
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/ioctl.h"
#include "libc/calls/struct/iovec.h"
@ -34,12 +34,12 @@
#include "libc/conv/conv.h"
#include "libc/conv/itoa.h"
#include "libc/errno.h"
#include "libc/fmt/bing.h"
#include "libc/fmt/bing.internal.h"
#include "libc/fmt/fmt.h"
#include "libc/intrin/pcmpeqb.h"
#include "libc/intrin/pmovmskb.h"
#include "libc/log/check.h"
#include "libc/log/color.h"
#include "libc/log/color.internal.h"
#include "libc/log/log.h"
#include "libc/macros.h"
#include "libc/math.h"
@ -50,8 +50,8 @@
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/str/thompike.h"
#include "libc/str/tpdecode.h"
#include "libc/str/tpencode.h"
#include "libc/str/tpdecode.internal.h"
#include "libc/str/tpencode.internal.h"
#include "libc/sysv/consts/auxv.h"
#include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/exit.h"

View file

@ -8,7 +8,7 @@
*/
#endif
#include "dsp/tty/tty.h"
#include "libc/alg/arraylist2.h"
#include "libc/alg/arraylist2.internal.h"
#include "libc/assert.h"
#include "libc/bits/bits.h"
#include "libc/bits/morton.h"
@ -19,7 +19,7 @@
#include "libc/dce.h"
#include "libc/fmt/fmt.h"
#include "libc/limits.h"
#include "libc/log/color.h"
#include "libc/log/color.internal.h"
#include "libc/log/log.h"
#include "libc/macros.h"
#include "libc/math.h"

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/xmmintrin.h"
#include "libc/bits/xmmintrin.internal.h"
#include "libc/intrin/repstosb.h"
#include "tool/build/emubin/metalsha256.h"

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/conv/conv.h"
#include "libc/macros.h"
#include "libc/runtime/runtime.h"

View file

@ -21,7 +21,7 @@
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/conv/conv.h"
#include "libc/fmt/bing.h"
#include "libc/fmt/bing.internal.h"
#include "libc/limits.h"
#include "libc/log/check.h"
#include "libc/log/log.h"

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/alg/arraylist2.h"
#include "libc/alg/arraylist2.internal.h"
#include "libc/assert.h"
#include "libc/log/log.h"
#include "tool/build/lib/breakpoint.h"

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/alg/arraylist2.h"
#include "libc/alg/arraylist2.internal.h"
#include "libc/calls/calls.h"
#include "libc/errno.h"
#include "libc/fmt/fmt.h"

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/assert.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/hefty/spawn.h"
#include "libc/calls/struct/iovec.h"

View file

@ -18,10 +18,10 @@
02110-1301 USA
*/
#include "libc/alg/alg.h"
#include "libc/alg/arraylist2.h"
#include "libc/bits/safemacros.h"
#include "libc/alg/arraylist2.internal.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/conv/itoa.h"
#include "libc/fmt/bing.h"
#include "libc/fmt/bing.internal.h"
#include "libc/fmt/fmt.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
@ -29,7 +29,7 @@
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/str/tpencode.h"
#include "libc/str/tpencode.internal.h"
#include "third_party/xed/x86.h"
#include "tool/build/lib/case.h"
#include "tool/build/lib/demangle.h"

View file

@ -58,7 +58,7 @@ static void DisLoadElfLoads(struct Dis *d, struct Elf *elf) {
CHECK_NOTNULL(d->loads.p);
}
for (i = 0; i < n; ++i) {
phdr = getelfsegmentheaderaddress(elf->ehdr, elf->size, i);
phdr = GetElfSegmentHeaderAddress(elf->ehdr, elf->size, i);
if (phdr->p_type != PT_LOAD) continue;
d->loads.p[j].addr = phdr->p_vaddr;
d->loads.p[j].size = phdr->p_memsz;

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/log/check.h"
#include "libc/nexgen32e/tinystrcmp.h"
#include "libc/nexgen32e/tinystrcmp.internal.h"
#include "libc/str/str.h"
#include "third_party/zlib/zlib.h"
#include "tool/build/lib/dis.h"

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/alg/arraylist2.h"
#include "libc/alg/arraylist2.internal.h"
#include "libc/assert.h"
#include "libc/calls/calls.h"
#include "libc/log/check.h"

View file

@ -33,7 +33,7 @@ int MachineFdAdd(struct MachineFds *mf) {
} else {
DCHECK_LE(mf->i, mf->n);
if (mf->i == mf->n) {
if (!grow(&mf->p, &mf->n, sizeof(struct MachineFd), 0)) {
if (!__grow(&mf->p, &mf->n, sizeof(struct MachineFd), 0)) {
return -1;
}
}

View file

@ -17,9 +17,9 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/alg/arraylist.h"
#include "libc/alg/arraylist2.h"
#include "libc/bits/safemacros.h"
#include "libc/alg/arraylist.internal.h"
#include "libc/alg/arraylist2.internal.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/mem/mem.h"
#include "libc/str/knuthmultiplicativehash.h"
#include "libc/str/str.h"

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/calls/struct/iovec.h"
#include "libc/nexgen32e/uart.h"
#include "libc/nexgen32e/uart.internal.h"
#include "libc/sysv/consts/fileno.h"
#include "tool/build/lib/ioports.h"

View file

@ -25,7 +25,7 @@
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/macros.h"
#include "libc/nexgen32e/vendor.h"
#include "libc/nexgen32e/vendor.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/fileno.h"
@ -81,7 +81,7 @@ static void LoadElf(struct Machine *m, struct Elf *elf) {
m->ip = elf->base = elf->ehdr->e_entry;
VERBOSEF("LOADELF ENTRY %p", m->ip);
for (i = 0; i < elf->ehdr->e_phnum; ++i) {
phdr = getelfsegmentheaderaddress(elf->ehdr, elf->size, i);
phdr = GetElfSegmentHeaderAddress(elf->ehdr, elf->size, i);
switch (phdr->p_type) {
case PT_LOAD:
elf->base = MIN(elf->base, phdr->p_vaddr);

View file

@ -17,11 +17,11 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/conv/conv.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "libc/str/tpdecode.h"
#include "libc/str/tpdecode.internal.h"
#include "libc/unicode/unicode.h"
#include "tool/build/lib/buffer.h"
#include "tool/build/lib/panel.h"

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/alg/arraylist2.h"
#include "libc/alg/arraylist2.internal.h"
#include "tool/build/lib/endian.h"
#include "tool/build/lib/machine.h"
#include "tool/build/lib/pml4t.h"

View file

@ -17,10 +17,10 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/alg/arraylist2.h"
#include "libc/alg/arraylist2.internal.h"
#include "libc/assert.h"
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/conv/conv.h"
#include "libc/conv/itoa.h"
#include "libc/log/check.h"

View file

@ -22,7 +22,7 @@
#include "libc/calls/ioctl.h"
#include "libc/calls/struct/iovec.h"
#include "libc/calls/struct/rusage.h"
#include "libc/calls/struct/sigaction-linux.h"
#include "libc/calls/struct/sigaction-linux.internal.h"
#include "libc/calls/struct/sigaction.h"
#include "libc/calls/struct/stat.h"
#include "libc/calls/struct/termios.h"
@ -35,9 +35,10 @@
#include "libc/log/log.h"
#include "libc/macros.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/vendor.h"
#include "libc/nexgen32e/vendor.internal.h"
#include "libc/runtime/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/select.h"
#include "libc/sock/sock.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/af.h"

View file

@ -19,7 +19,7 @@
*/
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/nexgen32e/vendor.h"
#include "libc/nexgen32e/vendor.internal.h"
#include "libc/runtime/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"

View file

@ -18,12 +18,12 @@
02110-1301 USA
*/
#include "libc/alg/alg.h"
#include "libc/alg/arraylist.h"
#include "libc/alg/arraylist2.h"
#include "libc/alg/bisectcarleft.h"
#include "libc/alg/arraylist.internal.h"
#include "libc/alg/arraylist2.internal.h"
#include "libc/alg/bisectcarleft.internal.h"
#include "libc/assert.h"
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/errno.h"

View file

@ -18,12 +18,12 @@
02110-1301 USA
*/
#include "libc/alg/alg.h"
#include "libc/alg/arraylist.h"
#include "libc/alg/bisect.h"
#include "libc/alg/bisectcarleft.h"
#include "libc/alg/arraylist.internal.h"
#include "libc/alg/bisect.internal.h"
#include "libc/alg/bisectcarleft.internal.h"
#include "libc/assert.h"
#include "libc/bits/bswap.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/conv/conv.h"
@ -263,7 +263,7 @@ void IndexSections(struct Object *obj) {
struct XedDecodedInst xedd;
for (i = 0; i < obj->elf->e_shnum; ++i) {
memset(&sect, 0, sizeof(sect));
CHECK_NOTNULL((shdr = getelfsectionheaderaddress(obj->elf, obj->size, i)));
CHECK_NOTNULL((shdr = GetElfSectionHeaderAddress(obj->elf, obj->size, i)));
if (shdr->sh_type != SHT_NULL) {
CHECK_NOTNULL((name = GetElfSectionName(obj->elf, obj->size, shdr)));
if (startswith(name, ".sort.")) name += 5;
@ -289,7 +289,7 @@ void IndexSections(struct Object *obj) {
sect.kind = kUndef; /* should always and only be section #0 */
}
if (shdr->sh_flags & SHF_EXECINSTR) {
CHECK_NOTNULL((code = getelfsectionaddress(obj->elf, obj->size, shdr)));
CHECK_NOTNULL((code = GetElfSectionAddress(obj->elf, obj->size, shdr)));
for (op.offset = 0; op.offset < shdr->sh_size; op.offset += op.length) {
if (xed_instruction_length_decode(
xed_decoded_inst_zero_set_mode(&xedd, XED_MACHINE_MODE_LONG_64),
@ -453,15 +453,15 @@ void OptimizeRelocations(struct Package *pkg, struct Packages *deps,
unsigned char *code, *p;
Elf64_Shdr *shdr, *shdrcode;
for (i = 0; i < obj->elf->e_shnum; ++i) {
shdr = getelfsectionheaderaddress(obj->elf, obj->size, i);
shdr = GetElfSectionHeaderAddress(obj->elf, obj->size, i);
if (shdr->sh_type == SHT_RELA) {
CHECK_EQ(sizeof(struct Elf64_Rela), shdr->sh_entsize);
CHECK_NOTNULL((shdrcode = getelfsectionheaderaddress(obj->elf, obj->size,
CHECK_NOTNULL((shdrcode = GetElfSectionHeaderAddress(obj->elf, obj->size,
shdr->sh_info)));
if (!(shdrcode->sh_flags & SHF_EXECINSTR)) continue;
CHECK_NOTNULL(
(code = getelfsectionaddress(obj->elf, obj->size, shdrcode)));
for (rela = getelfsectionaddress(obj->elf, obj->size, shdr);
(code = GetElfSectionAddress(obj->elf, obj->size, shdrcode)));
for (rela = GetElfSectionAddress(obj->elf, obj->size, shdr);
((uintptr_t)rela + shdr->sh_entsize <=
min((uintptr_t)obj->elf + obj->size,
(uintptr_t)obj->elf + shdr->sh_offset + shdr->sh_size));
@ -594,12 +594,12 @@ void CompressLowEntropyReadOnlyDataSections(struct Package *pkg,
memset(&rle, 0, sizeof(rle));
haverldecode = IsSymbolDirectlyReachable(pkg, deps, "rldecode");
for (i = 0; i < obj->elf->e_shnum; ++i) {
if ((shdr = getelfsectionheaderaddress(obj->elf, obj->size, i)) &&
if ((shdr = GetElfSectionHeaderAddress(obj->elf, obj->size, i)) &&
shdr->sh_size >= 256 &&
(shdr->sh_type == SHT_PROGBITS &&
!(shdr->sh_flags &
(SHF_WRITE | SHF_MERGE | SHF_STRINGS | SHF_COMPRESSED))) &&
(p = getelfsectionaddress(obj->elf, obj->size, shdr)) &&
(p = GetElfSectionAddress(obj->elf, obj->size, shdr)) &&
startswith((name = GetElfSectionName(obj->elf, obj->size, shdr)),
".rodata") &&
rlencode(&rle, p, shdr->sh_size) != -1) {

View file

@ -19,7 +19,7 @@
*/
#include "libc/alg/alg.h"
#include "libc/assert.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/dirent.h"
#include "libc/calls/struct/stat.h"

149
tool/build/rollup.c Normal file
View file

@ -0,0 +1,149 @@
/*-*- 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 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/alg/arraylist2.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/conv/itoa.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/mem/mem.h"
#include "libc/runtime/runtime.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
#define LOOKINGAT(p, pe, s) LookingAt(p, pe, s, strlen(s))
#define APPENDSTR(s) AppendData(s, strlen(s))
struct Output {
size_t i, n;
const char *p;
};
struct Visited {
size_t i, n;
const char **p;
};
static struct stat st;
static struct Output output;
static struct Visited visited;
static void Visit(const char *);
static bool HasVisited(const char *path) {
int i;
for (i = 0; i < visited.i; ++i) {
if (strcmp(path, visited.p[i]) == 0) {
return true;
}
}
return false;
}
static void AppendData(const char *s, size_t n) {
CONCAT(&output.p, &output.i, &output.n, s, n);
}
static void AppendInt(long x) {
char ibuf[21];
AppendData(ibuf, int64toarray_radix10(x, ibuf));
}
static bool LookingAt(const char *p, const char *pe, const char *s, size_t n) {
return pe - p >= n && memcmp(p, s, n) == 0;
}
static void Process(const char *p, const char *pe, const char *path,
bool isheader) {
int level;
bool noformat;
const char *p2, *dq, *name;
for (noformat = level = 0; p < pe; p = p2) {
p2 = memchr(p, '\n', pe - p);
p2 = p2 ? p2 + 1 : pe;
if (LOOKINGAT(p, pe, "#if")) {
if (isheader && !level++) continue;
}
if (LOOKINGAT(p, pe, "#endif")) {
if (isheader && !--level) continue;
}
if (LOOKINGAT(p, pe, "/* clang-format off */")) {
noformat = true;
} else if (LOOKINGAT(p, pe, "/* clang-format on */")) {
noformat = false;
}
if (LOOKINGAT(p, pe, "#include \"")) {
name = p + strlen("#include \"");
dq = memchr(name, '"', pe - name);
if (dq) {
Visit(strndup(name, dq - name));
continue;
}
}
AppendData(p, p2 - p);
}
if (noformat) {
APPENDSTR("/* clang-format on */\n");
}
}
static void Visit(const char *path) {
int fd;
char *map;
bool isheader;
if (!endswith(path, ".h") && !endswith(path, ".inc")) return;
if (endswith(path, ".internal.h")) return;
if (endswith(path, "/internal.h")) return;
if (endswith(path, ".internal.inc")) return;
if (endswith(path, "/internal.inc")) return;
isheader = endswith(path, ".h");
if (isheader && HasVisited(path)) return;
APPENDSTR("\n\f\n/*!BEGIN ");
APPENDSTR(path);
APPENDSTR(" */\n\n");
APPEND(&visited.p, &visited.i, &visited.n, &path);
CHECK_NE(-1, (fd = open(path, O_RDONLY)));
CHECK_NE(-1, fstat(fd, &st));
if (st.st_size) {
CHECK_NE(MAP_FAILED,
(map = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0)));
Process(map, map + st.st_size, path, isheader);
LOGIFNEG1(munmap(map, st.st_size));
}
LOGIFNEG1(close(fd));
}
int main(int argc, char *argv[]) {
int i;
APPENDSTR("#ifndef COSMOPOLITAN_H_\n");
APPENDSTR("#define COSMOPOLITAN_H_\n");
APPENDSTR("#define IMAGE_BASE_VIRTUAL ");
AppendInt(IMAGE_BASE_VIRTUAL);
APPENDSTR("\n");
for (i = 1; i < argc; ++i) {
Visit(argv[i]);
}
APPENDSTR("\n");
APPENDSTR("#endif /* COSMOPOLITAN_H_ */\n");
CHECK_EQ(output.i, write(1, output.p, output.i));
return 0;
}

View file

@ -19,7 +19,7 @@
*/
#include "libc/alg/alg.h"
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/hefty/spawn.h"
#include "libc/calls/struct/itimerval.h"
@ -36,7 +36,7 @@
#include "libc/mem/mem.h"
#include "libc/runtime/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/ipclassify.h"
#include "libc/sock/ipclassify.internal.h"
#include "libc/sock/sock.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
@ -303,7 +303,7 @@ int ReadResponse(void) {
}
break;
default:
die();
__die();
}
} while (n);
}

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/hefty/spawn.h"
#include "libc/calls/struct/sigaction.h"

View file

@ -1,89 +0,0 @@
/*-*- 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 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/nt/dll.h"
#include "libc/nt/enum/color.h"
#include "libc/nt/enum/cw.h"
#include "libc/nt/enum/idc.h"
#include "libc/nt/enum/sw.h"
#include "libc/nt/enum/wm.h"
#include "libc/nt/enum/ws.h"
#include "libc/nt/events.h"
#include "libc/nt/paint.h"
#include "libc/nt/struct/msg.h"
#include "libc/nt/struct/paintstruct.h"
#include "libc/nt/struct/wndclass.h"
#include "libc/nt/windows.h"
#include "libc/runtime/missioncritical.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/winmain.h"
#include "libc/str/str.h"
/**
* @fileoverview Incomplete Windows App.
*/
static const char16_t kClassName[] = u"Sample Window Class";
int64_t WindowProcSysv(int64_t hwnd, uint32_t uMsg, uint64_t wParam,
int64_t lParam) {
int64_t hdc;
struct NtPaintStruct ps;
switch (uMsg) {
case kNtWmDestroy:
PostQuitMessage(0);
return 0;
case kNtWmPaint:
hdc = BeginPaint(hwnd, &ps);
FillRect(hdc, &ps.rcPaint, kNtColorWindow + 1);
EndPaint(hwnd, &ps);
return 0;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
}
int64_t WindowProcNt(int64_t, uint32_t, uint64_t, int64_t);
asm("WindowProcNt:\n\t"
"lea\tWindowProcSysv(%rip),%rax\n\t"
"jmp\t__nt2sysv");
int main(int argc, char *argv[]) {
int64_t hwnd;
struct NtMsg msg;
struct NtWndClass wc;
memset(&wc, 0, sizeof(wc));
wc.lpfnWndProc = WindowProcNt;
wc.hInstance = g_winmain.hInstance;
wc.hCursor = LoadCursor(0, kNtIdcIbeam);
wc.lpszClassName = kClassName;
CHECK(RegisterClass(&wc));
CHECK((hwnd = CreateWindowEx(0, kClassName, u"Learn to Program Windows",
kNtWsOverlappedwindow, kNtCwUsedefault,
kNtCwUsedefault, kNtCwUsedefault,
kNtCwUsedefault, 0, 0, g_winmain.hInstance, 0)));
ShowWindow(hwnd, kNtSwNormal);
while (GetMessage(&msg, 0, 0, 0)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return 0;
}

View file

@ -17,13 +17,12 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/alg/arraylist.h"
#include "libc/alg/arraylist.internal.h"
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/calls/struct/timespec.h"
#include "libc/dos.h"
#include "libc/elf/def.h"
#include "libc/limits.h"
#include "libc/log/check.h"
@ -32,10 +31,10 @@
#include "libc/mem/alloca.h"
#include "libc/nexgen32e/crc32.h"
#include "libc/nt/enum/fileflagandattributes.h"
#include "libc/nt/struct/imageauxsymbolex.h"
#include "libc/nt/struct/imageauxsymbolex.internal.h"
#include "libc/runtime/gc.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/symbols.h"
#include "libc/runtime/symbols.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/ex.h"
@ -62,6 +61,11 @@
P[0] = V & 0xff, P[1] = V >> 010 & 0xff, P[2] = V >> 020 & 0xff, \
P[3] = V >> 030 & 0xff, P += 4
#define DOS_DATE(YEAR, MONTH_IDX1, DAY_IDX1) \
(((YEAR)-1980) << 9 | (MONTH_IDX1) << 5 | (DAY_IDX1))
#define DOS_TIME(HOUR, MINUTE, SECOND) \
((HOUR) << 11 | (MINUTE) << 5 | (SECOND) >> 1)
char *symbol_;
char *outpath_;
char *yoink_;

View file

@ -18,15 +18,19 @@
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/conv/conv.h"
#include "libc/errno.h"
#include "libc/log/log.h"
#include "libc/macros.h"
#include "libc/math.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/bsf.h"
#include "libc/nexgen32e/bsr.h"
#include "libc/nexgen32e/ffs.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/rand/rand.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/o.h"
#include "libc/time/time.h"
@ -98,6 +102,34 @@ static long double ParseNumber(struct Token t) {
}
}
static long double FnRand(struct Numbers *a) {
return rand();
}
static long double FnRand32(struct Numbers *a) {
return rand32();
}
static long double FnRand64(struct Numbers *a) {
return rand64();
}
static long double FnRdrand(struct Numbers *a) {
if (X86_HAVE(RDRND)) {
return rdrand();
} else {
return NAN;
}
}
static long double FnRdseed(struct Numbers *a) {
if (X86_HAVE(RDSEED)) {
return rdseed();
} else {
return NAN;
}
}
static long double FnAtan2(struct Numbers *a) {
if (!a || !a->n) MissingArgumentError();
return atan2l(a->n->x, a->x);
@ -662,6 +694,11 @@ static const struct Fn {
{"pow", FnPow},
{"powi", FnPowi},
{"print", FnPrint},
{"rand", FnRand},
{"rand32", FnRand32},
{"rand64", FnRand64},
{"rdrand", FnRdrand},
{"rdseed", FnRdseed},
{"remainder", FnRemainder},
{"rint", FnRint},
{"rol", FnRol},

View file

@ -32,6 +32,7 @@ TOOL_CALC_DIRECTDEPS = \
LIBC_FMT \
LIBC_MEM \
LIBC_NEXGEN32E \
LIBC_RAND \
LIBC_RUNTIME \
LIBC_STDIO \
LIBC_STUBS \

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/conv/conv.h"
@ -99,8 +99,8 @@ static void printelfehdr(void) {
}
static void printelfsegmentheader(int i) {
Elf64_Phdr *phdr = getelfsegmentheaderaddress(elf, st->st_size, i);
printf("/\tElf64_Phdr *phdr = getelfsegmentheaderaddress(elf, st->st_size, "
Elf64_Phdr *phdr = GetElfSegmentHeaderAddress(elf, st->st_size, i);
printf("/\tElf64_Phdr *phdr = GetElfSegmentHeaderAddress(elf, st->st_size, "
"%d)\n",
i);
printf(".Lph%d:", i);
@ -127,8 +127,8 @@ static void printelfsegmentheaders(void) {
static void printelfsectionheader(int i, char *shstrtab) {
Elf64_Shdr *shdr;
shdr = getelfsectionheaderaddress(elf, st->st_size, i);
printf("/\tElf64_Shdr *shdr = getelfsectionheaderaddress(elf, st->st_size, "
shdr = GetElfSectionHeaderAddress(elf, st->st_size, i);
printf("/\tElf64_Shdr *shdr = GetElfSectionHeaderAddress(elf, st->st_size, "
"%d)\n",
i);
printf(".Lsh%d:", i);
@ -154,7 +154,7 @@ static void printelfsectionheader(int i, char *shstrtab) {
static void printelfsectionheaders(void) {
Elf64_Half i;
char *shstrtab = getelfsectionnamestringtable(elf, st->st_size);
char *shstrtab = GetElfSectionNameStringTable(elf, st->st_size);
if (shstrtab) {
printf("\n");
printf("\t.org\t%#x\n", elf->e_shoff);
@ -163,10 +163,10 @@ static void printelfsectionheaders(void) {
}
printf("\n/\t%s\n", "elf->e_shstrndx");
printf("\t.org\t%#x\n",
getelfsectionheaderaddress(elf, st->st_size, elf->e_shstrndx)
GetElfSectionHeaderAddress(elf, st->st_size, elf->e_shstrndx)
->sh_offset);
for (i = 0; i < elf->e_shnum; ++i) {
Elf64_Shdr *shdr = getelfsectionheaderaddress(elf, st->st_size, i);
Elf64_Shdr *shdr = GetElfSectionHeaderAddress(elf, st->st_size, i);
const char *str = GetElfString(elf, st->st_size, shstrtab, shdr->sh_name);
show(".asciz", format(b1, "%`'s", str), NULL);
}
@ -207,7 +207,7 @@ static void printelfsymbol(Elf64_Sym *sym, char *strtab, char *shstrtab) {
sym->st_shndx < 0xff00
? format(b1, "%`'s",
GetElfString(elf, st->st_size, shstrtab,
getelfsectionheaderaddress(
GetElfSectionHeaderAddress(
elf, st->st_size, sym->st_shndx)
->sh_name))
: findnamebyid(kElfSpecialSectionNames, sym->st_shndx)));
@ -219,7 +219,7 @@ static void printelfsymboltable(void) {
size_t i, symcount = 0;
Elf64_Sym *symtab = GetElfSymbolTable(elf, st->st_size, &symcount);
char *strtab = GetElfStringTable(elf, st->st_size);
char *shstrtab = getelfsectionnamestringtable(elf, st->st_size);
char *shstrtab = GetElfSectionNameStringTable(elf, st->st_size);
if (symtab && strtab) {
printf("\n\n");
printf("\t.org\t%#x\n", (intptr_t)symtab - (intptr_t)elf);
@ -238,7 +238,7 @@ static char *getelfsymbolname(const Elf64_Ehdr *elf, size_t mapsize,
if (elf && sym &&
((shstrtab && !sym->st_name &&
ELF64_ST_TYPE(sym->st_info) == STT_SECTION &&
(shdr = getelfsectionheaderaddress(elf, mapsize, sym->st_shndx)) &&
(shdr = GetElfSectionHeaderAddress(elf, mapsize, sym->st_shndx)) &&
(res = GetElfString(elf, mapsize, shstrtab, shdr->sh_name))) ||
(strtab && (res = GetElfString(elf, mapsize, strtab, sym->st_name))))) {
return res;
@ -255,26 +255,26 @@ static void printelfrelocations(void) {
const Elf64_Shdr *shdr, *boop;
char *strtab, *shstrtab, *symbolname;
strtab = GetElfStringTable(elf, st->st_size);
shstrtab = getelfsectionnamestringtable(elf, st->st_size);
shstrtab = GetElfSectionNameStringTable(elf, st->st_size);
for (i = 0; i < elf->e_shnum; ++i) {
if ((shdr = getelfsectionheaderaddress(elf, st->st_size, i)) &&
if ((shdr = GetElfSectionHeaderAddress(elf, st->st_size, i)) &&
shdr->sh_type == SHT_RELA &&
(rela = getelfsectionaddress(elf, st->st_size, shdr))) {
(rela = GetElfSectionAddress(elf, st->st_size, shdr))) {
printf("\n/\t%s\n", GetElfSectionName(elf, st->st_size, shdr));
printf("\t.org\t%#x\n", (intptr_t)rela - (intptr_t)elf);
for (j = 0; ((uintptr_t)rela + sizeof(Elf64_Rela) <=
min((uintptr_t)elf + st->st_size,
(uintptr_t)elf + shdr->sh_offset + shdr->sh_size));
++rela, ++j) {
boop = getelfsectionheaderaddress(elf, st->st_size, shdr->sh_link);
syms = getelfsectionaddress(elf, st->st_size, boop);
boop = GetElfSectionHeaderAddress(elf, st->st_size, shdr->sh_link);
syms = GetElfSectionAddress(elf, st->st_size, boop);
sym = ELF64_R_SYM(rela->r_info);
symbolname =
getelfsymbolname(elf, st->st_size, strtab, shstrtab, &syms[sym]);
printf("/\t%s+%#lx → %s%c%#lx\n",
GetElfString(
elf, st->st_size, shstrtab,
getelfsectionheaderaddress(elf, st->st_size, shdr->sh_info)
GetElfSectionHeaderAddress(elf, st->st_size, shdr->sh_info)
->sh_name),
rela->r_offset, symbolname, rela->r_addend >= 0 ? '+' : '-',
abs(rela->r_addend));

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/fmt/fmt.h"
#include "libc/mem/mem.h"
#include "libc/runtime/gc.h"

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/alg/arraylist2.h"
#include "libc/alg/arraylist2.internal.h"
#include "libc/fmt/fmt.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/macho.h"
#include "libc/macho.internal.h"
#include "tool/decode/lib/machoidnames.h"
const struct IdName kMachoFileTypeNames[] = {

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/pe.h"
#include "libc/nt/pedef.internal.h"
#include "tool/decode/lib/peidnames.h"
const struct IdName kNtImageFileMachineNames[] = {

View file

@ -18,11 +18,11 @@
02110-1301 USA
*/
#include "libc/assert.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/conv/conv.h"
#include "libc/macho.h"
#include "libc/macho.internal.h"
#include "libc/runtime/runtime.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/map.h"
@ -44,7 +44,7 @@ static size_t machosize;
static void startfile(void) {
showtitle("αcτµαlly pδrταblε εxεcµταblε", "tool/decode/macho", NULL, NULL,
&kModelineAsm);
printf("#include \"libc/macho.h\"\n\n", path);
printf("#include \"libc/macho.internal.h\"\n\n", path);
}
static void showmachoheader(void) {

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/conv/conv.h"
#include "libc/log/check.h"

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/fmt/fmt.h"
#include "libc/log/check.h"
#include "libc/mem/mem.h"

View file

@ -17,13 +17,13 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/conv/conv.h"
#include "libc/nt/struct/imagentheaders.h"
#include "libc/nt/struct/imageoptionalheader.h"
#include "libc/pe.h"
#include "libc/nt/struct/imagedosheader.internal.h"
#include "libc/nt/struct/imagentheaders.internal.h"
#include "libc/nt/struct/imageoptionalheader.internal.h"
#include "libc/stdio/stdio.h"
#include "libc/sysv/consts/map.h"
#include "libc/sysv/consts/o.h"
@ -57,7 +57,23 @@ static struct XedDecodedInst *ildreal(void *addr) {
static void startfile(void) {
showtitle("αcτµαlly pδrταblε εxεcµταblε", "tool/decode/pe", NULL, NULL,
&kModelineAsm);
printf("#include \"libc/pe.h\"\n\n", path);
printf("#include \"libc/nt/pedef.internal.h\"\n\n", path);
}
static void *pecheckaddress(struct NtImageDosHeader *mz, size_t mzsize,
void *addr, uint32_t addrsize) {
#if !(TRUSTWORTHY + PE_TRUSTWORTHY + 0)
if ((intptr_t)addr < (intptr_t)mz ||
(intptr_t)addr + addrsize > (intptr_t)mz + mzsize) {
abort();
}
#endif
return addr;
}
static void *pecomputerva(struct NtImageDosHeader *mz, size_t mzsize,
uint32_t reladdr, uint32_t addrsize) {
return pecheckaddress(mz, mzsize, (void *)((intptr_t)mz + reladdr), addrsize);
}
static void showmzheader(void) {

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/conv/conv.h"

1991
tool/emacs/c.lang Normal file

File diff suppressed because it is too large Load diff

View file

@ -1289,8 +1289,7 @@
"isconstant"
"chooseexpr"
"likely"
"unlikely"
"assume"))
"unlikely"))
)
(concat "\\_<"

View file

@ -124,8 +124,7 @@
;; "delete"))
(cosmo
'("__rbx"
"__msabi"
'("__msabi"
"offsetof"
"microarchitecture"
"targetclones"

View file

@ -17,8 +17,8 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/alg/arraylist.h"
#include "libc/bits/safemacros.h"
#include "libc/alg/arraylist.internal.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/iovec.h"
#include "libc/errno.h"

View file

@ -17,10 +17,10 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/alg/arraylist2.h"
#include "libc/alg/arraylist2.internal.h"
#include "libc/bits/bits.h"
#include "libc/bits/bswap.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/iovec.h"
#include "libc/calls/struct/itimerval.h"
@ -38,7 +38,6 @@
#include "libc/nexgen32e/crc32.h"
#include "libc/rand/rand.h"
#include "libc/runtime/gc.h"
#include "libc/runtime/missioncritical.h"
#include "libc/runtime/runtime.h"
#include "libc/sock/sock.h"
#include "libc/stdio/stdio.h"

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/conv/conv.h"
#include "libc/errno.h"

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "dsp/core/core.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/hefty/spawn.h"
#include "libc/calls/ioctl.h"

View file

@ -17,9 +17,9 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/log/color.h"
#include "libc/log/color.internal.h"
#include "libc/log/log.h"
#include "libc/nexgen32e/cpuid4.h"
#include "libc/nexgen32e/cpuid4.internal.h"
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/nexgen32e/rdtscp.h"
#include "libc/nexgen32e/x86feature.h"

View file

@ -1,9 +1,9 @@
#include "dsp/tty/tty.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/termios.h"
#include "libc/log/check.h"
#include "libc/log/color.h"
#include "libc/log/color.internal.h"
#include "libc/log/log.h"
#include "libc/macros.h"
#include "libc/math.h"

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/conv/conv.h"
#include "libc/errno.h"
#include "libc/runtime/runtime.h"

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/conv/conv.h"
#include "libc/fmt/fmt.h"
#include "libc/limits.h"

View file

@ -1,6 +1,6 @@
#ifndef COSMOPOLITAN_TOOL_VIZ_LIB_CONVOLVE_H_
#define COSMOPOLITAN_TOOL_VIZ_LIB_CONVOLVE_H_
#include "libc/bits/xmmintrin.h"
#include "libc/bits/xmmintrin.internal.h"
#include "libc/str/str.h"
#include "tool/viz/lib/graphic.h"
#if !(__ASSEMBLER__ + __LINKER__ + 0)

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/conv/itoa.h"
#include "libc/runtime/gc.h"
#include "libc/str/str.h"

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/conv/itoa.h"
#include "tool/viz/lib/formatstringtable.h"

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/unicode/unicode.h"
#include "tool/viz/lib/formatstringtable.h"

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/xmmintrin.h"
#include "libc/bits/xmmintrin.internal.h"
#include "libc/macros.h"
#include "libc/mem/mem.h"
#include "libc/str/str.h"

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "dsp/tty/quant.h"
#include "libc/bits/xmmintrin.h"
#include "libc/bits/xmmintrin.internal.h"
#include "libc/macros.h"
#include "tool/viz/lib/graphic.h"

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/bits/bits.h"
#include "libc/bits/initializer.h"
#include "libc/bits/initializer.internal.h"
#include "libc/macros.h"
#include "libc/math.h"
#include "tool/viz/lib/graphic.h"

View file

@ -18,7 +18,7 @@
02110-1301 USA
*/
#include "libc/assert.h"
#include "libc/bits/xmmintrin.h"
#include "libc/bits/xmmintrin.internal.h"
#include "libc/runtime/buffer.h"
#include "tool/viz/lib/graphic.h"

View file

@ -26,7 +26,7 @@
#include "dsp/core/illumination.h"
#include "dsp/core/q.h"
#include "dsp/scale/scale.h"
#include "libc/bits/xmmintrin.h"
#include "libc/bits/xmmintrin.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/sigbits.h"
#include "libc/calls/struct/sigset.h"
@ -36,7 +36,7 @@
#include "libc/macros.h"
#include "libc/math.h"
#include "libc/mem/mem.h"
#include "libc/nexgen32e/gc.h"
#include "libc/nexgen32e/gc.internal.h"
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/nexgen32e/x86feature.h"
#include "libc/runtime/gc.h"

File diff suppressed because it is too large Load diff

View file

@ -21,7 +21,7 @@
#include "libc/bits/bits.h"
#include "libc/bits/hilbert.h"
#include "libc/bits/morton.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/ioctl.h"
#include "libc/calls/struct/sigaction.h"
@ -55,7 +55,7 @@
#include "third_party/getopt/getopt.h"
#define USAGE \
" [-hznmH] [-p PID] [PATH]\n\
" [-hznmHNW] [-p PID] [PATH]\n\
\n\
DESCRIPTION\n\
\n\
@ -65,10 +65,10 @@ FLAGS\n\
\n\
-h help\n\
-z zoom\n\
-w white bg color\n\
-m morton ordering\n\
-H hilbert ordering\n\
-n natural scrolling\n\
-N natural scrolling\n\
-W white terminal background\n\
-p PID shows process virtual memory\n\
-f INT frames per second [default 10]\n\
\n\
@ -276,7 +276,7 @@ static void SetupCanvas(void) {
munmap(canvas, canvassize);
munmap(buffer, buffersize);
}
displaysize = ROUNDUP(ROUNDUP(tyn * txn * (1ul << zoom), 16), 1ul << zoom);
displaysize = ROUNDUP(ROUNDUP((tyn * txn) << zoom, 16), 1ul << zoom);
canvassize = ROUNDUP(displaysize, FRAMESIZE);
buffersize = ROUNDUP(tyn * txn * 16 + PAGESIZE, FRAMESIZE);
canvas = Allocate(canvassize);
@ -341,7 +341,8 @@ static int GetCurrentRange(void) {
}
static void Move(long d) {
offset = MIN(highest, MAX(lowest, ROUNDDOWN(offset + d, 1L << zoom)));
d <<= zoom;
offset = MIN(highest, MAX(lowest, (offset + d) >> zoom << zoom));
}
static void SetZoom(long y, long x, int d) {
@ -351,7 +352,7 @@ static void SetZoom(long y, long x, int d) {
a = zoom;
b = MIN(MAXZOOM, MAX(0, a + d));
zoom = b;
Move(i * (1L << a) - i * (1L << b));
Move((i << a) - (i << b));
SetupCanvas();
}
}
@ -365,19 +366,19 @@ static void OnUnzoom(long y, long x) {
}
static void OnUp(void) {
Move(-(txn * (1l << zoom)));
Move(-(txn));
}
static void OnDown(void) {
Move(txn * (1l << zoom));
Move(txn);
}
static void OnPageUp(void) {
Move(-(txn * (tyn - 2) * (1l << zoom)));
Move(-(txn * (tyn - 2)));
}
static void OnPageDown(void) {
Move(txn * (tyn - 2) * (1l << zoom));
Move(txn * (tyn - 2));
}
static void OnHome(void) {
@ -385,7 +386,7 @@ static void OnHome(void) {
}
static void OnEnd(void) {
offset = MAX(lowest, highest - txn * tyn * (1l << zoom));
offset = MAX(lowest, highest - txn * tyn);
}
static void OnLinear(void) {
@ -425,7 +426,7 @@ static void OnPrev(void) {
static void OnNextEnd(void) {
long i, n;
if ((i = GetCurrentRange()) != -1) {
n = tyn * txn * (1L << zoom);
n = (tyn * txn) << zoom;
if (offset < ranges.p[i].b - n) {
offset = ranges.p[i].b - n;
} else if (i + 1 < ranges.i) {
@ -437,7 +438,7 @@ static void OnNextEnd(void) {
static void OnPrevEnd(void) {
long i, n;
if ((i = GetCurrentRange()) != -1) {
n = tyn * txn * (1L << zoom);
n = (tyn * txn) << zoom;
if (i) {
offset = MAX(ranges.p[i - 1].a, ranges.p[i - 1].b - n);
}
@ -753,7 +754,7 @@ static void Render(void) {
} while (w);
}
p = stpcpy(p, "\e[0m ");
p += uint64toarray_radix16(offset + y * txn * (1ul << zoom), p);
p += uint64toarray_radix16(offset + ((y * txn) << zoom), p);
p = stpcpy(p, "\e[K\r\n");
}
p = stpcpy(p, "\e[7m\e[K");
@ -772,7 +773,7 @@ static void Render(void) {
p += uint64toarray_radix10(MIN(offset / (long double)size * 100, 100), p);
p = stpcpy(p, "%-");
p += uint64toarray_radix10(
MIN((offset + tyn * txn * (1l << zoom)) / (long double)size * 100, 100),
MIN((offset + ((tyn * txn) << zoom)) / (long double)size * 100, 100),
p);
p = stpcpy(p, "% ");
}
@ -800,7 +801,7 @@ static void Zoom(long have) {
memset(canvas + n, 0, canvassize - n);
}
if (have != -1) {
n = have / (1L << zoom);
n = have >> zoom;
i = n / txn;
r = n % txn;
if (r) ++i;
@ -827,7 +828,7 @@ static void RangesZoom(void) {
LoadRanges();
memset(canvas, 1, canvassize);
a = offset;
b = MIN(highest, offset + tyn * txn * (1ul << zoom));
b = MIN(highest, offset + ((tyn * txn) << zoom));
for (i = 0; i < ranges.i; ++i) {
if ((a >= ranges.p[i].a && a < ranges.p[i].b) ||
(b >= ranges.p[i].a && b < ranges.p[i].b) ||
@ -871,23 +872,23 @@ static void GetOpts(int argc, char *argv[]) {
int opt;
char *p;
fps = 10;
while ((opt = getopt(argc, argv, "hzHnwf:p:")) != -1) {
while ((opt = getopt(argc, argv, "hzHNWf:p:")) != -1) {
switch (opt) {
case 'z':
++zoom;
break;
case 'n':
natural = true;
break;
case 'm':
order = MORTON;
break;
case 'H':
order = HILBERT;
break;
case 'w':
case 'W':
white = true;
break;
case 'N':
natural = true;
break;
case 'f':
fps = strtol(optarg, NULL, 0);
fps = MAX(1, fps);

View file

@ -24,7 +24,7 @@
#include "dsp/tty/tty.h"
#include "libc/assert.h"
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/ioctl.h"
#include "libc/calls/struct/stat.h"

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/dce.h"
@ -133,7 +133,7 @@ void PrintSystemInfo(void) {
#undef X
}
const char *ft2str(enum NtFileType ft) {
const char *ft2str(int ft) {
if (ft == kNtFileTypeUnknown) return "kNtFileTypeUnknown";
if (ft == kNtFileTypeDisk) return "kNtFileTypeDisk";
if (ft == kNtFileTypeChar) return "kNtFileTypeChar";

View file

@ -25,10 +25,10 @@
#include "dsp/tty/quant.h"
#include "dsp/tty/tty.h"
#include "libc/alg/alg.h"
#include "libc/alg/arraylist.h"
#include "libc/alg/arraylist.internal.h"
#include "libc/assert.h"
#include "libc/bits/bits.h"
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/bits/xchg.h"
#include "libc/calls/calls.h"
#include "libc/calls/hefty/spawn.h"

View file

@ -17,8 +17,8 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/alg/arraylist.h"
#include "libc/bits/safemacros.h"
#include "libc/alg/arraylist.internal.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/conv/conv.h"
#include "libc/limits.h"
#include "libc/log/check.h"

View file

@ -17,7 +17,7 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/safemacros.h"
#include "libc/bits/safemacros.internal.h"
#include "libc/calls/calls.h"
#include "libc/calls/struct/stat.h"
#include "libc/macros.h"

View file

@ -32,6 +32,9 @@ TOOL_VIZ_DIRECTDEPS = \
LIBC_NEXGEN32E \
LIBC_NT_KERNEL32 \
LIBC_NT_KERNELBASE \
LIBC_NT_USER32 \
LIBC_NT_GDI32 \
LIBC_NT_COMDLG32 \
LIBC_RUNTIME \
LIBC_TESTLIB \
LIBC_STDIO \