Define heap in linker and place other sections correctly
This commit is contained in:
10
os/alloc.c
10
os/alloc.c
@@ -1,14 +1,16 @@
|
||||
#include "alloc.h"
|
||||
#include "stdint.h"
|
||||
|
||||
void* *first_mem_avail = (void*) 0x20000000;
|
||||
HeapArena heap_arena;
|
||||
|
||||
extern void * _heap_top;
|
||||
|
||||
void init_allocator() {
|
||||
*first_mem_avail = (void*) 0x20000000 +sizeof(void*);
|
||||
heap_arena.wilderness = &_heap_top;
|
||||
}
|
||||
|
||||
void* malloc(size_t size) {
|
||||
void* block = *first_mem_avail;
|
||||
*first_mem_avail += size;
|
||||
void* block = heap_arena.wilderness;
|
||||
heap_arena.wilderness += size;
|
||||
return block;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct {
|
||||
void * wilderness;
|
||||
} HeapArena;
|
||||
|
||||
void init_allocator();
|
||||
void* malloc (size_t size);
|
||||
|
||||
Reference in New Issue
Block a user