Get garbage collector working on aarch64

Garbage collection will now happen on arm64 when a function returns,
rather than kicking the can down the road to when the process exits.
This change also does some code cleanup and incorporates suggestions
This commit is contained in:
Justine Tunney 2023-06-07 03:34:45 -07:00
parent 9793d3524f
commit 01fd655097
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
16 changed files with 144 additions and 323 deletions

View file

@ -18,10 +18,7 @@
*/
#include "ape/sections.internal.h"
#include "libc/calls/calls.h"
#include "libc/elf/def.h"
#include "libc/elf/elf.h"
#include "libc/elf/struct/ehdr.h"
#include "libc/elf/struct/sym.h"
#include "libc/elf/tinyelf.internal.h"
#include "libc/errno.h"
#include "libc/intrin/bits.h"
#include "libc/macros.internal.h"
@ -32,23 +29,6 @@
#include "libc/sysv/consts/o.h"
#include "libc/sysv/consts/prot.h"
static bool GetElfSymbolValue(const Elf64_Ehdr *ehdr, size_t esize,
const char *name, uint64_t *res) {
Elf64_Xword i, n;
const char *stab;
const Elf64_Sym *st;
if ((stab = GetElfStringTable(ehdr, esize)) &&
(st = GetElfSymbolTable(ehdr, esize, &n))) {
for (i = 0; i < n; ++i) {
if (!strcmp(stab + st[i].st_name, name)) {
*res = st[i].st_value;
return true;
}
}
}
return false;
}
static bool IsMyDebugBinaryImpl(const char *path) {
int fd;
void *map;
@ -61,8 +41,8 @@ static bool IsMyDebugBinaryImpl(const char *path) {
// which is currently running in memory.
if ((size = lseek(fd, 0, SEEK_END)) != -1 &&
(map = mmap(0, size, PROT_READ, MAP_SHARED, fd, 0)) != MAP_FAILED) {
if (IsElf64Binary(map, size) &&
GetElfSymbolValue(map, size, "_etext", &value)) {
if (READ32LE(map) == READ32LE("\177ELF") &&
GetElfSymbolValue(map, "_etext", &value)) {
res = !_etext || value == (uintptr_t)_etext;
}
munmap(map, size);