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