ROSS
buddy.h
Go to the documentation of this file.
1#ifndef BUDDY_H
2#define BUDDY_H
3
4#include <stdint.h>
5#include <sys/queue.h>
6
7/**
8 * @file buddy.h
9 * @brief Buddy-system memory allocator
10 */
11
12typedef enum purpose { FREE, USED } purpose_t;
13
14#define BUDDY_ALIGN_PREF (32 - 2 * sizeof(void*) - sizeof(uint32_t) - sizeof(purpose_t))
15
16/**
17 * Metadata about this particular block
18 * (and stored at the beginning of this block).
19 * One per allocated block of memory.
20 * Should be 32 bytes to not screw up alignment.
21 */
22typedef struct buddy_list
23{
24 // Should be two pointers
25 LIST_ENTRY(buddy_list) next_freelist;
26 uint32_t size;
30
31typedef enum valid { VALID, INVALID } valid_t;
32
33/**
34 * Bucket of 2^order sized free memory blocks.
35 */
36typedef struct buddy_list_bucket
37{
38 LIST_HEAD(buddy_list_head, buddy_list) ptr;
39 unsigned int count;
40 unsigned int order;
43
44buddy_list_bucket_t * create_buddy_table(unsigned int power_of_two);
45void *buddy_alloc(unsigned size);
46void buddy_free(void *ptr);
47
48#endif /* BUDDY_H */
struct buddy_list buddy_list_t
enum valid valid_t
void * buddy_alloc(unsigned size)
Definition buddy.c:234
void buddy_free(void *ptr)
Definition buddy.c:137
buddy_list_bucket_t * create_buddy_table(unsigned int power_of_two)
Definition buddy.c:288
valid
Definition buddy.h:31
@ VALID
Definition buddy.h:31
@ INVALID
Definition buddy.h:31
struct buddy_list_bucket buddy_list_bucket_t
enum purpose purpose_t
purpose
Definition buddy.h:12
@ USED
Definition buddy.h:12
@ FREE
Definition buddy.h:12
enum valid valid_t
enum purpose purpose_t
#define BUDDY_ALIGN_PREF
Definition buddy.h:14
unsigned int count
Definition buddy.h:39
valid_t is_valid
Definition buddy.h:41
unsigned int order
Definition buddy.h:40
LIST_HEAD(buddy_list_head, buddy_list) ptr
LIST_ENTRY(buddy_list) next_freelist
char padding[(32 - 2 *sizeof(void *) - sizeof(uint32_t) - sizeof(purpose_t))]
Definition buddy.h:28
purpose_t use
Definition buddy.h:27
uint32_t size
Definition buddy.h:26