Browse Source

Added broken code

tree_alloc
Thomas Johnson 1 year ago
parent
commit
4338b8ca5e
  1. 2
      Makefile
  2. 13
      alloc_api.h
  3. 24
      main.c

2
Makefile

@ -18,7 +18,7 @@ $(OUT_NAME): $(objs)
clean:
rm -f *.o $(OUT_NAME)
main.o: main.c
main.o: main.c alloc_api.h
$(CC) $(CFLAGS) -c main.c -o main.o
tree_alloc.o: tree_alloc.c allocator_internal.h

13
alloc_api.h

@ -0,0 +1,13 @@
#include <stdint.h>
struct Arena {
void *root_freespace;
void *root_treealloc;
void *(*get_new_region)(uintptr_t);
void (*error)(char*);
};
void unalloc(struct Arena *arena, void *addr);
void *alloc(struct Arena *arena, uintptr_t size, uintptr_t align);

24
main.c

@ -1,6 +1,30 @@
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <unistd.h>
#include <sys/mman.h>
#include "alloc_api.h"
void *get_new_region(uintptr_t size) {
void *m = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
if (m == MAP_FAILED) {
return 0;
}
return m;
}
void error(char *msg) {
printf("=== ALLOCATOR ERROR ===\n%s\n====== END ERROR ======\n", msg);
}
int main() {
printf("Hello, World!\n");
struct Arena arena = {
NULL,
NULL,
get_new_region,
error,
};
return 0;
}
Loading…
Cancel
Save