mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-28 13:30:29 +00:00
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:
parent
dba7552c1e
commit
ea0b5d9d1c
775 changed files with 6864 additions and 3963 deletions
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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(§, 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) {
|
||||
|
|
|
@ -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
149
tool/build/rollup.c
Normal 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;
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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_;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue