From 54c09d54c0c170f1369751f8bf5a8a0b771a167c Mon Sep 17 00:00:00 2001 From: Matthew Sotoudeh Date: Thu, 16 May 2024 14:03:57 -0700 Subject: reorganize --- examples/main.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 examples/main.c (limited to 'examples/main.c') diff --git a/examples/main.c b/examples/main.c new file mode 100644 index 0000000..a288f1c --- /dev/null +++ b/examples/main.c @@ -0,0 +1,32 @@ +#include "buddy.h" +#include +#include +#include +#include +#include +#include + +void get_random(uint8_t *dst, size_t count) { + int fd = open("/dev/urandom", O_RDONLY); + assert(count == read(fd, dst, count)); + close(fd); +} + +void main() { + struct buddy buddy; + + size_t region_size = 1024 * 1024; + + uint8_t magic[MAGIC_COOKIE_BYTES]; + get_random(magic, MAGIC_COOKIE_BYTES); + init_buddy(malloc(region_size), region_size, magic, &buddy); + memset(magic, 0, sizeof(magic)); + + void *x = allocate(1024, &buddy); + printf("Just allocated %p...\n", x); + debug_buddy(&buddy); + + printf("Now liberating %p...\n", x); + liberate(x, 1024, &buddy); + debug_buddy(&buddy); +} -- cgit v1.2.3