Support malloc() on bare metal

Your Actually Portable Executables now contains a simple virtual memory
that works similarly to the Linux Kernel in the sense that it maps your
physical memory to negative addresses. This is needed to support mmap()
and malloc(). This functionality has zero code size impact. For example
the MODE=tiny LIFE.COM executable is still only 12KB in size.

The APE bootloader code has also been simplified to improve readibility
and further elevate the elegance by which we're able to support so many
platforms thereby enhancing verifiability so that we may engender trust
in this bootloading process.
This commit is contained in:
Justine Tunney 2021-02-23 20:23:19 -08:00
parent ac3b1dfb21
commit edd9297eba
89 changed files with 900 additions and 1417 deletions

View file

@ -20,8 +20,8 @@
#include "libc/runtime/internal.h"
#include "libc/runtime/runtime.h"
extern const uintptr_t __fini_array_start[];
extern const uintptr_t __fini_array_end[];
extern const uintptr_t __fini_array_start[] __attribute__((__weak__));
extern const uintptr_t __fini_array_end[] __attribute__((__weak__));
/**
* Exits process with grace.
@ -39,7 +39,7 @@ wontreturn void exit(int exitcode) {
if (weaken(__cxa_finalize)) {
weaken(__cxa_finalize)(NULL);
}
for (p = *weaken(__fini_array_end); p > *weaken(__fini_array_start);) {
for (p = __fini_array_end; p > __fini_array_start;) {
((void (*)(void))(*--p))();
}
_Exit(exitcode);