summaryrefslogtreecommitdiff
path: root/buddy.h
blob: 0b4de098d963cfee70b712bcd9d91b27269520be (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#pragma once
#include <stdint.h>
#include <stddef.h>

#define MAGIC_COOKIE_BYTES 32
#define ADDRESS_BITS (8 * sizeof(void*))

struct buddy {
    uint8_t magic[MAGIC_COOKIE_BYTES];
    struct free_block *(avail[ADDRESS_BITS]);
    size_t root_logsize;
    void *base;
};

// NOTE: after init_buddy, *state should never move.
void init_buddy(uint8_t *base, size_t size, uint8_t magic[MAGIC_COOKIE_BYTES],
                struct buddy *state);

void *allocate(size_t size, struct buddy *state);
void  liberate(void *base, size_t size, struct buddy *state);

void debug_buddy(struct buddy *state);

void *reallocate(void *old, size_t old_size, size_t new_size,
                 struct buddy *state);
int reserve(void *start, size_t size, struct buddy *state);
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback