From 995a7142a0cc95affba7a6f46d0092ccb36fcd1f Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 17 Jul 2018 15:49:15 -0400 Subject: [PATCH] added a default main function to runtime to store off the stack bottom --- source/rt/gc.c | 14 ++++++-------- source/rt/main.c | 9 +++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 source/rt/main.c diff --git a/source/rt/gc.c b/source/rt/gc.c index abf50fe..c4f0b9a 100644 --- a/source/rt/gc.c +++ b/source/rt/gc.c @@ -18,12 +18,8 @@ typedef struct { void* val; /* pointer to the original cell value */ } entry_t; -size_t EntryCount; -entry_t EntryLog[NENTRIES]; - -void gc_init(void* stkbtm) { - EntryCount = 0; -} +size_t EntryCount = 0; +entry_t EntryLog[NENTRIES] = {0}; void gc_collect(void) { @@ -34,6 +30,10 @@ void* gc_alloc(size_t sz, void (*dtor)(void*)) { if (obj) { obj->dtor = dtor; obj->refs = 0u; + EntryLog[EntryCount].ref = NULL; + EntryLog[EntryCount].val = obj->data; + if (++EntryCount == NENTRIES) + gc_collect(); } else { perror("refcreate() failed :"); abort(); @@ -58,5 +58,3 @@ void gc_setref(void** ref, void* val) { void* gc_getref(void** ref) { return (void*)((uintptr_t)*ref & ~DIRTY_BIT); } - - diff --git a/source/rt/main.c b/source/rt/main.c new file mode 100644 index 0000000..fbb53ce --- /dev/null +++ b/source/rt/main.c @@ -0,0 +1,9 @@ +#include + +uintptr_t* StackBot; + +int main(int argc, char** argv) { + { StackBot = (uintptr_t*)&(int){0}; } + extern int usermain(int argc, char** argv); + return usermain(argc, argv); +} -- 2.52.0