Mint APE Loader v1.5

This change ports APE Loader to Linux AARCH64, so that Raspberry Pi
users can run programs like redbean, without the executable needing
to modify itself. Progress has also slipped into this change on the
issue of making progress better conforming to user expectations and
industry standards regarding which symbols we're allowed to declare
This commit is contained in:
Justine Tunney 2023-07-26 13:54:49 -07:00
parent 6843150e0c
commit 7e0a09feec
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
510 changed files with 1783 additions and 1483 deletions

View file

@ -277,17 +277,17 @@ int _curl(int argc, char *argv[]) {
mbedtls_ssl_init(&ssl);
mbedtls_ctr_drbg_init(&drbg);
mbedtls_ssl_config_init(&conf);
_unassert(!mbedtls_ctr_drbg_seed(&drbg, GetSslEntropy, 0, "justine", 7));
_unassert(!mbedtls_ssl_config_defaults(&conf, MBEDTLS_SSL_IS_CLIENT,
MBEDTLS_SSL_TRANSPORT_STREAM,
MBEDTLS_SSL_PRESET_DEFAULT));
unassert(!mbedtls_ctr_drbg_seed(&drbg, GetSslEntropy, 0, "justine", 7));
unassert(!mbedtls_ssl_config_defaults(&conf, MBEDTLS_SSL_IS_CLIENT,
MBEDTLS_SSL_TRANSPORT_STREAM,
MBEDTLS_SSL_PRESET_DEFAULT));
mbedtls_ssl_conf_ca_chain(&conf, GetSslRoots(), 0);
mbedtls_ssl_conf_rng(&conf, mbedtls_ctr_drbg_random, &drbg);
#ifndef NDEBUG
mbedtls_ssl_conf_dbg(&conf, OnSslDebug, 0);
#endif
_unassert(!mbedtls_ssl_setup(&ssl, &conf));
_unassert(!mbedtls_ssl_set_hostname(&ssl, host));
unassert(!mbedtls_ssl_setup(&ssl, &conf));
unassert(!mbedtls_ssl_set_hostname(&ssl, host));
mbedtls_ssl_set_bio(&ssl, &sock, TlsSend, 0, TlsRecv);
if ((ret = mbedtls_ssl_handshake(&ssl))) {
tinyprint(2, prog, ": ssl negotiation with ", host,
@ -340,7 +340,7 @@ int _curl(int argc, char *argv[]) {
i += g;
switch (t) {
case kHttpClientStateHeaders:
_unassert(g);
unassert(g);
if ((rc = ParseHttpMessage(&msg, p, i)) == -1) {
tinyprint(2, prog, ": ", host, " sent bad http message\n", NULL);
exit(1);
@ -376,7 +376,7 @@ int _curl(int argc, char *argv[]) {
}
break;
case kHttpClientStateBodyLengthed:
_unassert(g);
unassert(g);
if (i - hdrlen > paylen) {
g = hdrlen + paylen - (i - g);
}

View file

@ -27,7 +27,7 @@
#include "libc/sysv/consts/o.h"
#include "libc/x/x.h"
STATIC_YOINK("zipos");
__static_yoink("zipos");
static struct ZipArgs {
bool initialized;

View file

@ -35,7 +35,7 @@
#include "third_party/getopt/getopt.internal.h"
#include "third_party/regex/regex.h"
STATIC_YOINK("strerror_wr");
__static_yoink("strerror_wr");
// options used: fhem
// letters not used: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdgijklnopqrstuvwxyz

View file

@ -18,7 +18,7 @@
*/
#include "libc/runtime/runtime.h"
STATIC_YOINK("glob");
__static_yoink("glob");
int main(int argc, char **argv, char **envp) {
return _cocmd(argc, argv, envp);

View file

@ -43,7 +43,7 @@
#include "third_party/xed/x86.h"
#include "tool/build/lib/getargs.h"
STATIC_YOINK("realloc");
__static_yoink("realloc");
/**
* @fileoverview Build Package Script.

View file

@ -69,8 +69,8 @@
// test/tool/build/pledge_test.sh
//
STATIC_YOINK("strerror_wr");
STATIC_YOINK("zipos");
__static_yoink("strerror_wr");
__static_yoink("zipos");
#define USAGE \
"\

View file

@ -119,15 +119,15 @@ static bool GetDigest(const char *path, FILE *f, unsigned char digest[32]) {
unsigned char buf[512];
mbedtls_sha256_context ctx;
mbedtls_sha256_init(&ctx);
_unassert(!mbedtls_sha256_starts_ret(&ctx, false));
unassert(!mbedtls_sha256_starts_ret(&ctx, false));
while ((got = fread(buf, 1, sizeof(buf), f))) {
_unassert(!mbedtls_sha256_update_ret(&ctx, buf, got));
unassert(!mbedtls_sha256_update_ret(&ctx, buf, got));
}
if (ferror(f)) {
tinyprint(2, prog, ": ", path, ": ", strerror(errno), "\n", NULL);
return false;
}
_unassert(!mbedtls_sha256_finish_ret(&ctx, digest));
unassert(!mbedtls_sha256_finish_ret(&ctx, digest));
mbedtls_sha256_free(&ctx);
return true;
}

View file

@ -364,18 +364,18 @@ int _curl(int argc, char *argv[]) {
mbedtls_ssl_init(&ssl);
mbedtls_ctr_drbg_init(&drbg);
mbedtls_ssl_config_init(&conf);
_unassert(!mbedtls_ctr_drbg_seed(&drbg, GetSslEntropy, 0, "justine", 7));
_unassert(!mbedtls_ssl_config_defaults(&conf, MBEDTLS_SSL_IS_CLIENT,
MBEDTLS_SSL_TRANSPORT_STREAM,
ciphersuite));
unassert(!mbedtls_ctr_drbg_seed(&drbg, GetSslEntropy, 0, "justine", 7));
unassert(!mbedtls_ssl_config_defaults(&conf, MBEDTLS_SSL_IS_CLIENT,
MBEDTLS_SSL_TRANSPORT_STREAM,
ciphersuite));
mbedtls_ssl_conf_authmode(&conf, authmode);
mbedtls_ssl_conf_ca_chain(&conf, GetSslRoots(), 0);
mbedtls_ssl_conf_rng(&conf, mbedtls_ctr_drbg_random, &drbg);
#ifndef NDEBUG
mbedtls_ssl_conf_dbg(&conf, OnSslDebug, 0);
#endif
_unassert(!mbedtls_ssl_setup(&ssl, &conf));
_unassert(!mbedtls_ssl_set_hostname(&ssl, host));
unassert(!mbedtls_ssl_setup(&ssl, &conf));
unassert(!mbedtls_ssl_set_hostname(&ssl, host));
mbedtls_ssl_set_bio(&ssl, &sock, TlsSend, 0, TlsRecv);
if ((ret = mbedtls_ssl_handshake(&ssl))) {
tinyprint(2, prog, ": ssl negotiation with ", host,
@ -444,7 +444,7 @@ int _curl(int argc, char *argv[]) {
i += g;
switch (t) {
case kHttpClientStateHeaders:
_unassert(g);
unassert(g);
if ((rc = ParseHttpMessage(&msg, p, i)) == -1) {
tinyprint(2, prog, ": ", host, " sent bad http message\n", NULL);
exit(1);
@ -501,7 +501,7 @@ int _curl(int argc, char *argv[]) {
if (!g) goto Finished;
break;
case kHttpClientStateBodyLengthed:
_unassert(g);
unassert(g);
if (i - hdrlen > paylen) {
g = hdrlen + paylen - (i - g);
}

View file

@ -1663,12 +1663,12 @@ Keywords={
"MACHINE_CODE_ANALYSIS_BEGIN_",
"MACHINE_CODE_ANALYSIS_END_",
"DebugBreak",
"VEIL",
"CONCEAL",
"EXPROPRIATE",
"YOINK",
"STATIC_YOINK",
"STATIC_YOINK_SOURCE",
"__veil",
"__conceal",
"__expropriate",
"__yoink",
"__static_yoink",
"__static_yoink_source",
"STRINGIFY",
"likely",
"unlikely",

View file

@ -202,11 +202,11 @@
(cosmopolitan-builtin-functions
'("DebugBreak"
"VEIL"
"CONCEAL"
"EXPROPRIATE"
"YOINK"
"STATIC_YOINK"
"__veil"
"__conceal"
"__expropriate"
"__yoink"
"__static_yoink"
"PYTHON_YOINK"
"PYTHON_PROVIDE"
"STATIC_STACK_ADDR"

View file

@ -71,9 +71,9 @@
"nodebuginfo"
"frownedupon"
"wontreturn"
"noasan"
"dontasan"
"nomsan"
"noubsan"
"dontubsan"
"nostackprotector"
"initarray"
"mayalias"

View file

@ -178,7 +178,6 @@
'("__SAUCE__"
"PAGESIZE"
"APE_STACKSIZE"
"APE_GUARDSIZE"
"FRAMESIZE"
"ARG_MAX"
"PATH_MAX"

View file

@ -21,11 +21,13 @@
#include "libc/intrin/likely.h"
#include "libc/log/check.h"
#include "libc/log/log.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/stack.h"
#include "libc/stdckdint.h"
#include "libc/str/str.h"
#include "libc/str/tab.internal.h"
#include "libc/str/utf16.h"
#include "libc/sysv/consts/auxv.h"
#include "third_party/double-conversion/wrapper.h"
#include "third_party/lua/cosmo.h"
#include "third_party/lua/lauxlib.h"
@ -99,7 +101,7 @@ static struct DecodeJson Parse(struct lua_State *L, const char *p,
if (UNLIKELY(!depth)) {
return (struct DecodeJson){-1, "maximum depth exceeded"};
}
if (UNLIKELY(!HaveStackMemory(APE_GUARDSIZE))) {
if (UNLIKELY(!HaveStackMemory(getauxval(AT_PAGESZ)))) {
return (struct DecodeJson){-1, "out of stack"};
}
for (a = p, d = +1; p < e;) {

View file

@ -141,16 +141,16 @@
STATIC_STACK_SIZE(0x80000);
STATIC_YOINK("zipos");
__static_yoink("zipos");
#ifdef USE_BLINK
STATIC_YOINK("blink_linux_aarch64"); // for raspberry pi
STATIC_YOINK("blink_xnu_aarch64"); // is apple silicon
__static_yoink("blink_linux_aarch64"); // for raspberry pi
__static_yoink("blink_xnu_aarch64"); // is apple silicon
#endif
#if !IsTiny()
#ifdef __x86_64__
STATIC_YOINK("ShowCrashReportsEarly");
__static_yoink("ShowCrashReportsEarly");
#endif
#endif
@ -4948,7 +4948,7 @@ static int LuaProgramTokenBucket(lua_State *L) {
tokenbucket.ban = ban;
tokenbucket.replenish = timespec_fromnanos(1 / replenish * 1e9);
int pid = fork();
_npassert(pid != -1);
npassert(pid != -1);
if (!pid) Replenisher();
return 0;
}

View file

@ -19,7 +19,7 @@
#include "tool/plinko/lib/plinko.h"
#include "libc/thread/tls.h"
STATIC_YOINK("__zipos_get");
__static_yoink("__zipos_get");
int main(int argc, char *argv[]) {
__tls_enabled = false;

View file

@ -55,11 +55,13 @@
#include "libc/nt/struct/openfilename.h"
#include "libc/nt/windows.h"
#include "libc/runtime/runtime.h"
#include "libc/runtime/sysconf.h"
#include "libc/sock/struct/pollfd.h"
#include "libc/stdio/rand.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/str/strwidth.h"
#include "libc/sysv/consts/auxv.h"
#include "libc/sysv/consts/ex.h"
#include "libc/sysv/consts/exit.h"
#include "libc/sysv/consts/poll.h"
@ -481,17 +483,17 @@ static void *NewBoard(size_t *out_size) {
char *p;
size_t s, n, k;
s = (byn * bxn) >> 3;
k = APE_GUARDSIZE + ROUNDUP(s, APE_GUARDSIZE);
n = ROUNDUP(k + APE_GUARDSIZE, FRAMESIZE);
k = getauxval(AT_PAGESZ) + ROUNDUP(s, getauxval(AT_PAGESZ));
n = ROUNDUP(k + getauxval(AT_PAGESZ), sysconf(_SC_PAGESIZE));
p = _mapanon(n);
mprotect(p, APE_GUARDSIZE, 0);
mprotect(p, getauxval(AT_PAGESZ), 0);
mprotect(p + k, n - k, 0);
if (out_size) *out_size = n;
return p + APE_GUARDSIZE;
return p + getauxval(AT_PAGESZ);
}
static void FreeBoard(void *p, size_t n) {
munmap((char *)p - APE_GUARDSIZE, n);
munmap((char *)p - getauxval(AT_PAGESZ), n);
}
static void AllocateBoardsWithHardwareAcceleratedMemorySafety(void) {

View file

@ -45,7 +45,7 @@
#include "third_party/stb/stb_image.h"
#include "tool/viz/lib/graphic.h"
STATIC_YOINK("__zipos_get");
__static_yoink("__zipos_get");
static struct Flags {
const char *out;

View file

@ -82,7 +82,7 @@ const struct IdName kNtStartfFlagNames[] = {
{0, 0},
};
noasan void PrintStartupInfo(void) {
dontasan void PrintStartupInfo(void) {
#if 0
printf("\n\
\n\
@ -161,7 +161,7 @@ void PrintStdioInfo(void) {
ft2str(GetFileType(g_fds.p[2].handle)));
}
noasan void PrintTeb(void) {
dontasan void PrintTeb(void) {
GetCurrentProcessId();
SetLastError(0x1234);
printf("\n\