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:
@@ -100,6 +100,7 @@ static void DisLoadElfSyms(struct Dis *d, struct Elf *elf) {
|
||||
d->syms.p[j].unique = i;
|
||||
d->syms.p[j].size = st[i].st_size;
|
||||
d->syms.p[j].name = st[i].st_name;
|
||||
CHECK_GE(st[i].st_value, 0);
|
||||
d->syms.p[j].addr = st[i].st_value;
|
||||
d->syms.p[j].rank =
|
||||
-islocal + -isweak + -isabs + isprotected + isobject + isfunc;
|
||||
@@ -112,7 +113,14 @@ static void DisLoadElfSyms(struct Dis *d, struct Elf *elf) {
|
||||
}
|
||||
|
||||
static void DisSortSyms(struct Dis *d) {
|
||||
size_t i, j;
|
||||
qsort(d->syms.p, d->syms.i, sizeof(struct DisSym), (void *)DisSymCompare);
|
||||
for (i = 0; i < d->syms.i; ++i) {
|
||||
if (!strcmp("_end", d->syms.stab + d->syms.p[i].name)) {
|
||||
d->syms.i = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void DisCanonizeSyms(struct Dis *d) {
|
||||
@@ -178,6 +186,10 @@ long DisFindSym(struct Dis *d, int64_t addr) {
|
||||
l = m + 1;
|
||||
}
|
||||
}
|
||||
if (r && d->syms.p[r - 1].addr < 256) {
|
||||
/* XXX: prevent skewed binbase from doing weirdness */
|
||||
return -1;
|
||||
}
|
||||
if (r && (addr == d->syms.p[r - 1].addr ||
|
||||
(addr > d->syms.p[r - 1].addr &&
|
||||
(addr <= d->syms.p[r - 1].addr + d->syms.p[r - 1].size ||
|
||||
|
||||
@@ -16,9 +16,8 @@
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/config.h"
|
||||
#include "ape/lib/pc.h"
|
||||
#include "libc/math.h"
|
||||
#include "libc/runtime/pc.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "tool/build/lib/case.h"
|
||||
@@ -988,7 +987,7 @@ static void OpFnop(struct Machine *m) {
|
||||
}
|
||||
|
||||
void OpFinit(struct Machine *m) {
|
||||
m->fpu.cw = X87_NORMAL;
|
||||
m->fpu.cw = 0x037f;
|
||||
m->fpu.sw = 0;
|
||||
m->fpu.tw = -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user