Browse Source
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.htmlmain
775 changed files with 6821 additions and 3920 deletions
@ -1,22 +1,3 @@
@@ -1,22 +1,3 @@
|
||||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 tw=8 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 │ |
||||
╚─────────────────────────────────────────────────────────────────────────────*/ |
||||
#ifndef APE_IDATA_H_ |
||||
#define APE_IDATA_H_ |
||||
#ifdef __ASSEMBLER__ |
@ -1,41 +0,0 @@
@@ -1,41 +0,0 @@
|
||||
#ifndef COSMOPOLITAN_APE_MTIME_H_ |
||||
#define COSMOPOLITAN_APE_MTIME_H_ |
||||
#include "libc/dos.h" |
||||
|
||||
/**
|
||||
* @fileoverview Deterministic last modified timestamp embedding. |
||||
*/ |
||||
|
||||
#ifndef MTIME_YEAR |
||||
#define MTIME_YEAR 2019 |
||||
#endif |
||||
|
||||
#ifndef MTIME_MONTH |
||||
#define MTIME_MONTH 1 |
||||
#endif |
||||
|
||||
#ifndef MTIME_DAY |
||||
#define MTIME_DAY 1 |
||||
#endif |
||||
|
||||
#ifndef MTIME_HOUR |
||||
#define MTIME_HOUR 0 |
||||
#endif |
||||
|
||||
#ifndef MTIME_MINUTES |
||||
#define MTIME_MINUTES 0 |
||||
#endif |
||||
|
||||
#ifndef MTIME_SECONDS |
||||
#define MTIME_SECONDS 0 |
||||
#endif |
||||
|
||||
#ifndef ZIP_MTIME_DATE |
||||
#define ZIP_MTIME_DATE DOS_DATE(MTIME_YEAR, MTIME_MONTH, MTIME_DAY) |
||||
#endif |
||||
|
||||
#ifndef ZIP_MTIME_TIME |
||||
#define ZIP_MTIME_TIME DOS_TIME(MTIME_HOUR, MTIME_MINUTES, MTIME_SECONDS) |
||||
#endif |
||||
|
||||
#endif /* COSMOPOLITAN_APE_MTIME_H_ */ |
@ -1,63 +0,0 @@
@@ -1,63 +0,0 @@
|
||||
#if 0 |
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │ |
||||
│ all copyright and related or neighboring rights to this file, │ |
||||
│ as it is written in the following disclaimers: │ |
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/ |
||||
#endif |
||||
#include "libc/calls/calls.h" |
||||
#include "libc/log/backtrace.h" |
||||
#include "libc/log/log.h" |
||||
#include "libc/mem/mem.h" |
||||
#include "libc/runtime/gc.h" |
||||
#include "libc/runtime/runtime.h" |
||||
#include "libc/runtime/symbols.h" |
||||
#include "libc/stdio/stdio.h" |
||||
#include "libc/sysv/consts/fileno.h" |
||||
|
||||
/*
|
||||
|
||||
Your executables will try to find the addr2line tool, which is needed |
||||
to decrypt gcc debug information, enabling backtraces like this: |
||||
|
||||
0x0000000000403a7a: Hello at examples/backtrace.c:31 |
||||
0x0000000000403ac3: World at examples/backtrace.c:38 |
||||
0x0000000000401608: main at examples/backtrace.c:42 |
||||
0x0000000000401379: _start at libc/crt/crt.S:61 |
||||
|
||||
If that doesn't work, then your αcτµαlly pδrταblε εxεcµταblε will use |
||||
its own builtin fallback solution: |
||||
|
||||
0000ac2fa7e0 000000403a9b Hello+0x49 |
||||
0000ac2fa7f0 000000403ac4 World+0x22 |
||||
0000ac2fa800 000000401609 main+0x7 |
||||
0000ac2fa810 00000040137a _start+0x63 |
||||
|
||||
This is guaranteed to work if the .com.dbg file can be found. |
||||
Otherwise it'll print numbers: |
||||
|
||||
0000268a8390 000000403a90 (null)+0x403a8f |
||||
0000268a83a0 000000403aef (null)+0x403aee |
||||
0000268a83b0 0000004015fe (null)+0x4015fd |
||||
0000268a83c0 00000040137a (null)+0x401379 |
||||
|
||||
*/ |
||||
|
||||
void hello(void) { |
||||
gc(malloc(1)); |
||||
ShowBacktrace(STDOUT_FILENO, NULL); |
||||
setenv("ADDR2LINE", "", true); |
||||
ShowBacktrace(STDOUT_FILENO, NULL); |
||||
} |
||||
|
||||
void world(void) { |
||||
gc(malloc(1)); |
||||
hello(); |
||||
} |
||||
|
||||
int main(int argc, char *argv[]) { |
||||
world(); |
||||
return 0; |
||||
} |
@ -1,36 +0,0 @@
@@ -1,36 +0,0 @@
|
||||
#if 0 |
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │ |
||||
│ all copyright and related or neighboring rights to this file, │ |
||||
│ as it is written in the following disclaimers: │ |
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/ |
||||
#endif |
||||
#include "libc/calls/calls.h" |
||||
#include "libc/elf/elf.h" |
||||
#include "libc/log/backtrace.h" |
||||
#include "libc/log/log.h" |
||||
#include "libc/runtime/symbols.h" |
||||
#include "libc/stdio/stdio.h" |
||||
#include "libc/sysv/consts/fileno.h" |
||||
|
||||
int main(int argc, char *argv[]) { |
||||
int rc = 0; |
||||
char *filename; |
||||
struct SymbolTable *tab = NULL; |
||||
if ((filename = FindDebugBinary()) != NULL && |
||||
(tab = OpenSymbolTable(filename))) { |
||||
for (unsigned i = 0; i < tab->count; ++i) { |
||||
printf("%p %s\n", tab->addr_base + tab->symbols[i].addr_rva, |
||||
GetElfString(tab->elf, tab->elfsize, tab->name_base, |
||||
tab->symbols[i].name_rva)); |
||||
} |
||||
} else { |
||||
perror("printmysymbols"); |
||||
ShowBacktrace(STDERR_FILENO, NULL); |
||||
rc = 1; |
||||
} |
||||
CloseSymbolTable(&tab); |
||||
return rc; |
||||
} |
@ -1,27 +0,0 @@
@@ -1,27 +0,0 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_ALG_BISECTLEFT_H_ |
||||
#define COSMOPOLITAN_LIBC_ALG_BISECTLEFT_H_ |
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0) |
||||
COSMOPOLITAN_C_START_ |
||||
|
||||
forceinline size_t bisectleft(const void *key, const void *base, size_t count, |
||||
size_t sz, int cmp(const void *, const void *)) { |
||||
size_t m, l, r; |
||||
l = 0; |
||||
r = count; |
||||
while (l < r) { |
||||
m = (l + r) >> 1; |
||||
if (cmp((char *)base + m * sz, key) < 0) { |
||||
l = m + 1; |
||||
} else { |
||||
r = m; |
||||
} |
||||
} |
||||
if (l && (l == count || cmp((char *)base + l * sz, key) > 0)) { |
||||
l--; |
||||
} |
||||
return l; |
||||
} |
||||
|
||||
COSMOPOLITAN_C_END_ |
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ |
||||
#endif /* COSMOPOLITAN_LIBC_ALG_BISECTLEFT_H_ */ |
@ -1,26 +0,0 @@
@@ -1,26 +0,0 @@
|
||||
#ifndef COSMOPOLITAN_LIBC_ALG_BISECTRIGHT_H_ |
||||
#define COSMOPOLITAN_LIBC_ALG_BISECTRIGHT_H_ |
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0) |
||||
COSMOPOLITAN_C_START_ |
||||
|
||||
forceinline size_t bisectright(const void *key, const void *base, size_t count, |
||||
size_t sz, int cmp(const void *, const void *)) { |
||||
size_t left = 0; |
||||
size_t right = count; |
||||
while (left < right) { |
||||
size_t m = (right + right) >> 1; |
||||
if (cmp((char *)base + m * sz, key) > 0) { |
||||
right = m + 1; |
||||
} else { |
||||
right = m; |
||||
} |
||||
} |
||||
if (right && (right == count || cmp((char *)base + right * sz, key) > 0)) { |
||||
right--; |
||||
} |
||||
return right; |
||||
} |
||||
|
||||
COSMOPOLITAN_C_END_ |
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ |
||||
#endif /* COSMOPOLITAN_LIBC_ALG_BISECTRIGHT_H_ */ |