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

@ -47,12 +47,12 @@
#define MAP_FIXED_linux 0x00000010
#define MAP_SHARED_linux 0x00000001
STATIC_YOINK("_init_metalfile");
__static_yoink("_init_metalfile");
void *__ape_com_base;
size_t __ape_com_size = 0;
textstartup noasan void InitializeMetalFile(void) {
textstartup dontasan void InitializeMetalFile(void) {
if (IsMetal()) {
/*
* Copy out a pristine image of the program before the program might
@ -61,7 +61,7 @@ textstartup noasan void InitializeMetalFile(void) {
* This code is included if a symbol "file:/proc/self/exe" is defined
* (see libc/calls/metalfile.internal.h & libc/calls/metalfile_init.S).
* The zipos code will automatically arrange to do this. Alternatively,
* user code can STATIC_YOINK this symbol.
* user code can __static_yoink this symbol.
*/
size_t size = ROUNDUP(_ezip - __executable_start, 4096);
// TODO(jart): Restore support for ZIPOS on metal.
@ -70,7 +70,7 @@ textstartup noasan void InitializeMetalFile(void) {
dm = sys_mmap_metal(NULL, size, PROT_READ | PROT_WRITE,
MAP_SHARED_linux | MAP_ANONYMOUS_linux, -1, 0);
copied_base = dm.addr;
_npassert(copied_base != (void *)-1);
npassert(copied_base != (void *)-1);
memcpy(copied_base, (void *)(BANE + IMAGE_BASE_PHYSICAL), size);
__ape_com_base = copied_base;
__ape_com_size = size;