Mint APE Loader v1.7

This change reduces the memory requirements of your APE Loader by 10x,
in terms of virtual memory size, thanks to the help of alloca(). We're
also now creating argument blocks with the same layout across systems.
This commit is contained in:
Justine Tunney 2023-08-17 07:21:13 -07:00
parent d967a94c9a
commit 1d8937d528
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
31 changed files with 367 additions and 656 deletions

View file

@ -180,6 +180,7 @@ textwindows bool __sig_handle(int sigops, int sig, int si_code,
case (intptr_t)SIG_DFL:
if (__sig_is_fatal(sig)) {
STRACE("terminating on %G", sig);
_restorewintty();
ExitProcess(sig);
}
// fallthrough

View file

@ -85,8 +85,8 @@ int sys_execve(const char *prog, char *const argv[], char *const envp[]) {
(CanExecute((ape = "/usr/bin/ape")) ||
CanExecute((ape = Join(firstnonnull(getenv("TMPDIR"),
firstnonnull(getenv("HOME"), ".")),
".ape-1.6", buf))) ||
CanExecute((ape = Join(firstnonnull(getenv("HOME"), "."), ".ape-1.6",
".ape-1.7", buf))) ||
CanExecute((ape = Join(firstnonnull(getenv("HOME"), "."), ".ape-1.7",
buf))))) {
shargs[0] = ape;
shargs[1] = "-";

View file

@ -43,8 +43,8 @@ int getrlimit(int resource, struct rlimit *rlim) {
} else if (!IsWindows()) {
rc = sys_getrlimit(resource, rlim);
} else if (resource == RLIMIT_STACK) {
rlim->rlim_cur = (uintptr_t)ape_stack_memsz;
rlim->rlim_max = (uintptr_t)ape_stack_memsz;
rlim->rlim_cur = GetStaticStackSize();
rlim->rlim_max = GetStaticStackSize();
rc = 0;
} else if (resource == RLIMIT_AS) {
rlim->rlim_cur = __virtualmax;

View file

@ -26,10 +26,10 @@
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/intrin/weaken.h"
#include "libc/runtime/zipos.internal.h"
#include "libc/sock/internal.h"
#include "libc/sock/sock.h"
#include "libc/sysv/errfuns.h"
#include "libc/runtime/zipos.internal.h"
/**
* Reads data from file descriptor.

View file

@ -23,6 +23,7 @@
#include "libc/intrin/asan.internal.h"
#include "libc/intrin/describeflags.internal.h"
#include "libc/intrin/strace.internal.h"
#include "libc/macros.internal.h"
#include "libc/sysv/consts/rlimit.h"
#include "libc/sysv/errfuns.h"
@ -31,6 +32,12 @@
*
* The following resources are recommended:
*
* - `RLIMIT_STACK` controls how much stack memory is available to the
* main thread. This setting is inherited across fork() and execve()
* Please note it's only safe for Cosmopolitan programs, to set this
* value to at least `PTHREAD_STACK_MIN * 2`. On Windows this cannot
* be used to extend the stack, which is currently hard-coded.
*
* - `RLIMIT_AS` limits the size of the virtual address space. This will
* work on all platforms except WSL. It is emulated on XNU and Windows
* which means it won't propagate across execve() currently.

View file

@ -278,7 +278,7 @@ void statfs2cosmo(struct statfs *f, const union statfs_meta *m) {
f_files = m->netbsd.f_files;
f_ffree = m->netbsd.f_ffree;
f_fsid = m->netbsd.f_fsid;
f_namelen = f->f_namelen;
f_namelen = 511;
f_frsize = m->netbsd.f_bsize;
f_flags = m->netbsd.f_flags;
f_owner = m->netbsd.f_owner;