Browse Source

Merge branch 'tree_alloc' of gitea:cameron/cs241-project into tree_alloc

tree_alloc
Cameron Weinfurt 1 year ago
parent
commit
898a1c4611
  1. 2
      Makefile
  2. 13
      alloc_api.h
  3. 2
      allocator_internal.h
  4. 24
      main.c
  5. 1
      tree_alloc.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);

2
allocator_internal.h

@ -3,8 +3,6 @@
#include <stdint.h>
#define alignof(x) offsetof(struct { char pad; x member; }, member)
// No enum because these need to be 1 byte
const char RT_FREESPACE = 0;
const char RT_TREE_NODE = 1;

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;
}

1
tree_alloc.c

@ -1,5 +1,6 @@
#include <stddef.h>
#include <stdalign.h>
#include "allocator_internal.h"

Loading…
Cancel
Save