mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 23:08:31 +00:00
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:
parent
6843150e0c
commit
7e0a09feec
510 changed files with 1783 additions and 1483 deletions
|
@ -53,7 +53,7 @@ ssize_t appendd(char **b, const void *s, size_t l) {
|
|||
z.n = ROUNDUP(z.n, W);
|
||||
if ((p = realloc(p, z.n))) {
|
||||
z.n = malloc_usable_size(p);
|
||||
_unassert(!(z.n & (W - 1)));
|
||||
unassert(!(z.n & (W - 1)));
|
||||
*b = p;
|
||||
} else {
|
||||
return -1;
|
||||
|
|
|
@ -51,14 +51,14 @@ ssize_t appendr(char **b, size_t i) {
|
|||
char *p;
|
||||
size_t n;
|
||||
struct appendz z;
|
||||
_unassert(b);
|
||||
unassert(b);
|
||||
z = appendz((p = *b));
|
||||
if (i != z.i || !p) {
|
||||
n = ROUNDUP(i + 1, 8) + W;
|
||||
if (n > z.n || _bsrl(n) < _bsrl(z.n)) {
|
||||
if ((p = realloc(p, n))) {
|
||||
z.n = malloc_usable_size(p);
|
||||
_unassert(!(z.n & (W - 1)));
|
||||
unassert(!(z.n & (W - 1)));
|
||||
*b = p;
|
||||
} else {
|
||||
return -1;
|
||||
|
|
|
@ -67,7 +67,7 @@ ssize_t appendw(char **b, uint64_t w) {
|
|||
z.n = ROUNDUP(z.n, W);
|
||||
if ((p = realloc(p, z.n))) {
|
||||
z.n = malloc_usable_size(p);
|
||||
_unassert(!(z.n & (W - 1)));
|
||||
unassert(!(z.n & (W - 1)));
|
||||
*b = p;
|
||||
} else {
|
||||
return -1;
|
||||
|
|
|
@ -34,7 +34,7 @@ struct appendz appendz(char *p) {
|
|||
struct appendz z;
|
||||
if (p) {
|
||||
z.n = malloc_usable_size(p);
|
||||
_unassert(z.n >= W * 2 && !(z.n & (W - 1)));
|
||||
unassert(z.n >= W * 2 && !(z.n & (W - 1)));
|
||||
z.i = *(size_t *)(p + z.n - W);
|
||||
if (!IsTiny() && W == 8) {
|
||||
/*
|
||||
|
@ -43,10 +43,10 @@ struct appendz appendz(char *p) {
|
|||
* can be free()'d safely, but they need to be allocated by the
|
||||
* append library, because we write a special value to the end.
|
||||
*/
|
||||
_unassert((z.i >> 48) == APPEND_COOKIE);
|
||||
unassert((z.i >> 48) == APPEND_COOKIE);
|
||||
z.i &= 0x0000ffffffffffff;
|
||||
}
|
||||
_unassert(z.n >= z.i);
|
||||
unassert(z.n >= z.i);
|
||||
} else {
|
||||
z.i = 0;
|
||||
z.n = 0;
|
||||
|
|
|
@ -347,8 +347,8 @@ static struct dirent *readdir_impl(DIR *dir) {
|
|||
ent = 0;
|
||||
zip = _weaken(__zipos_get)();
|
||||
while (!ent && dir->tell < dir->zip.records) {
|
||||
_npassert(ZIP_CFILE_MAGIC(zip->map + dir->zip.offset) ==
|
||||
kZipCfileHdrMagic);
|
||||
npassert(ZIP_CFILE_MAGIC(zip->map + dir->zip.offset) ==
|
||||
kZipCfileHdrMagic);
|
||||
s = ZIP_CFILE_NAME(zip->map + dir->zip.offset);
|
||||
n = ZIP_CFILE_NAMESIZE(zip->map + dir->zip.offset);
|
||||
if (dir->zip.prefixlen < n &&
|
||||
|
|
|
@ -270,7 +270,7 @@ static int __fmt_ntoa2(int out(const char *, void *, size_t), void *arg,
|
|||
}
|
||||
buf[len++] = alphabet[digit];
|
||||
} while (value);
|
||||
_npassert(count <= BUFFER_SIZE);
|
||||
npassert(count <= BUFFER_SIZE);
|
||||
}
|
||||
return __fmt_ntoa_format(out, arg, buf, len, neg, log2base, prec, width,
|
||||
flags, alphabet);
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
#include "libc/sysv/errfuns.h"
|
||||
#include "libc/thread/thread.h"
|
||||
|
||||
STATIC_YOINK("rdrand_init");
|
||||
__static_yoink("rdrand_init");
|
||||
|
||||
int sys_getentropy(void *, size_t) asm("sys_getrandom");
|
||||
|
||||
|
@ -128,7 +128,7 @@ static ssize_t GetRandomMetal(char *p, size_t n, int f) {
|
|||
}
|
||||
|
||||
static void GetRandomEntropy(char *p, size_t n) {
|
||||
_unassert(n <= 256);
|
||||
unassert(n <= 256);
|
||||
if (sys_getentropy(p, n)) notpossible;
|
||||
}
|
||||
|
||||
|
@ -137,7 +137,7 @@ static void GetRandomArnd(char *p, size_t n) {
|
|||
int cmd[2];
|
||||
cmd[0] = 1; // CTL_KERN
|
||||
cmd[1] = IsFreebsd() ? 37 : 81; // KERN_ARND
|
||||
_unassert((m = n) <= 256);
|
||||
unassert((m = n) <= 256);
|
||||
if (sys_sysctl(cmd, 2, p, &n, 0, 0) == -1) notpossible;
|
||||
if (m != n) notpossible;
|
||||
}
|
||||
|
|
|
@ -51,9 +51,9 @@ ssize_t kvappendf(char **b, const char *f, va_list v) {
|
|||
z.n = ROUNDUP(z.n, W);
|
||||
if ((p = realloc(p, z.n))) {
|
||||
z.n = malloc_usable_size(p);
|
||||
_unassert(!(z.n & (W - 1)));
|
||||
unassert(!(z.n & (W - 1)));
|
||||
s = kvsnprintf(p + z.i, z.n - W - z.i, f, w);
|
||||
_unassert(s == r);
|
||||
unassert(s == r);
|
||||
*b = p;
|
||||
} else {
|
||||
va_end(w);
|
||||
|
|
|
@ -38,7 +38,7 @@ int mkostempsmi(char *tpl, int slen, unsigned flags, uint64_t *rando, int mode,
|
|||
size_t wildlen = strlen(WILDCARD);
|
||||
if (len < wildlen || slen > len - wildlen) return einval();
|
||||
char *ss = tpl + len - wildlen - slen;
|
||||
_npassert(memcmp(ss, WILDCARD, wildlen) == 0);
|
||||
npassert(memcmp(ss, WILDCARD, wildlen) == 0);
|
||||
flags = (flags & ~(flags & O_ACCMODE)) | O_RDWR | O_CREAT | O_EXCL;
|
||||
unsigned attempts = ATTEMPTS;
|
||||
do {
|
||||
|
|
|
@ -73,26 +73,26 @@ FILE *popen(const char *cmdline, const char *mode) {
|
|||
if ((f = fdopen(pipefds[dir], mode))) {
|
||||
switch ((pid = fork())) {
|
||||
case 0:
|
||||
_unassert(dup2(pipefds[!dir], !dir) == !dir);
|
||||
unassert(dup2(pipefds[!dir], !dir) == !dir);
|
||||
// we can't rely on cloexec because cocmd builtins don't execve
|
||||
if (pipefds[0] != !dir) _unassert(!close(pipefds[0]));
|
||||
if (pipefds[1] != !dir) _unassert(!close(pipefds[1]));
|
||||
if (pipefds[0] != !dir) unassert(!close(pipefds[0]));
|
||||
if (pipefds[1] != !dir) unassert(!close(pipefds[1]));
|
||||
_Exit(_cocmd(3, (char *[]){"popen", "-c", cmdline, 0}, environ));
|
||||
default:
|
||||
f->pid = pid;
|
||||
_unassert(!close(pipefds[!dir]));
|
||||
unassert(!close(pipefds[!dir]));
|
||||
return f;
|
||||
case -1:
|
||||
e = errno;
|
||||
_unassert(!fclose(f));
|
||||
_unassert(!close(pipefds[!dir]));
|
||||
unassert(!fclose(f));
|
||||
unassert(!close(pipefds[!dir]));
|
||||
errno = e;
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
e = errno;
|
||||
_unassert(!close(pipefds[0]));
|
||||
_unassert(!close(pipefds[1]));
|
||||
unassert(!close(pipefds[0]));
|
||||
unassert(!close(pipefds[1]));
|
||||
errno = e;
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -217,7 +217,7 @@ int posix_spawnattr_getsigmask(const posix_spawnattr_t *attr,
|
|||
sigset_t *sigmask) {
|
||||
struct _posix_spawna *a = *(/*unconst*/ posix_spawnattr_t *)attr;
|
||||
if (!a->sigmask_isset) {
|
||||
_npassert(!sigprocmask(SIG_SETMASK, 0, &a->sigmask));
|
||||
npassert(!sigprocmask(SIG_SETMASK, 0, &a->sigmask));
|
||||
a->sigmask_isset = true;
|
||||
}
|
||||
*sigmask = a->sigmask;
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
#include "libc/stdio/rand.h"
|
||||
#include "libc/sysv/consts/grnd.h"
|
||||
|
||||
STATIC_YOINK("rdrand_init");
|
||||
__static_yoink("rdrand_init");
|
||||
|
||||
static dontinline uint64_t rdrand_failover(void) {
|
||||
int f;
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
*
|
||||
* @return original buf
|
||||
*/
|
||||
noasan void *rngset(void *b, size_t n, uint64_t seed(void), size_t reseed) {
|
||||
dontasan void *rngset(void *b, size_t n, uint64_t seed(void), size_t reseed) {
|
||||
size_t m;
|
||||
uint64_t i, x, t = 0;
|
||||
unsigned char *p = b;
|
||||
|
|
|
@ -44,9 +44,9 @@ ssize_t(vappendf)(char **b, const char *f, va_list v) {
|
|||
z.n = ROUNDUP(z.n, W);
|
||||
if ((p = realloc(p, z.n))) {
|
||||
z.n = malloc_usable_size(p);
|
||||
_unassert(!(z.n & (W - 1)));
|
||||
unassert(!(z.n & (W - 1)));
|
||||
s = (vsnprintf)(p + z.i, z.n - W - z.i, f, w);
|
||||
_unassert(s == r);
|
||||
unassert(s == r);
|
||||
*b = p;
|
||||
} else {
|
||||
va_end(w);
|
||||
|
|
|
@ -43,7 +43,7 @@ int vasprintf(char **strp, const char *fmt, va_list va) {
|
|||
if ((p2 = realloc(p, size))) {
|
||||
p = p2;
|
||||
wrote = vsnprintf(p, size, fmt, vb);
|
||||
_unassert(wrote == size - 1);
|
||||
unassert(wrote == size - 1);
|
||||
rc = wrote;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue