Xyris  0.5
heap.hpp
Go to the documentation of this file.
1 /**
2  * @file heap.hpp
3  * @author Keeton Feavel ([email protected])
4  * @brief Liballoc heap implementation
5  * @version 0.3
6  * @date 2019-11-22
7  *
8  * @copyright Copyright the Xyris Contributors (c) 2019
9  * Code shamelessly taken from the OSDev Wiki. The article
10  * can be found at the link below.
11  *
12  * https://wiki.osdev.org/User:Mrvn/LinkedListBucketHeapImplementation
13  */
14 #pragma once
15 
16 #include <stddef.h>
17 
18 extern "C" {
19 
20 /**
21  * @brief This function is supposed to lock the memory data structures. It
22  * could be as simple as disabling interrupts or acquiring a spinlock.
23  * It's up to you to decide.
24  *
25  * @return 0 if the lock was acquired successfully. Anything else is
26  * failure.
27  */
28 int liballoc_lock();
29 
30 /**
31  * @brief This function unlocks what was previously locked by the liballoc_lock
32  * function. If it disabled interrupts, it enables interrupts. If it
33  * had acquiried a spinlock, it releases the spinlock. etc.
34  *
35  * @return 0 if the lock was successfully released.
36  */
37 int liballoc_unlock();
38 
39 /**
40  * @brief This is the hook into the local system which allocates pages. It
41  * accepts an integer parameter which is the number of pages
42  * required. The page size was set up in the liballoc_init function.
43  *
44  * @return NULL if the pages were not allocated.
45  * @return A pointer to the allocated memory.
46  */
47 void* liballoc_alloc(unsigned int);
48 
49 /**
50  * @brief This frees previously allocated memory. The void* parameter passed
51  * to the function is the exact same value returned from a previous
52  * liballoc_alloc call.
53  *
54  * The integer value is the number of pages to free.
55  *
56  * @return 0 if the memory was successfully freed.
57  */
58 int liballoc_free(void*, unsigned int);
59 
60 extern void* malloc(size_t);
61 extern void* realloc(void*, size_t);
62 extern void* calloc(size_t, size_t);
63 extern void free(void*);
64 
65 }
liballoc_unlock
int liballoc_unlock()
This function unlocks what was previously locked by the liballoc_lock function. If it disabled interr...
Definition: heap.cpp:26
liballoc_free
int liballoc_free(void *, unsigned int)
This frees previously allocated memory. The void* parameter passed to the function is the exact same ...
Definition: heap.cpp:36
free
void free(void *)
realloc
void * realloc(void *, size_t)
liballoc_alloc
void * liballoc_alloc(unsigned int)
This is the hook into the local system which allocates pages. It accepts an integer parameter which i...
Definition: heap.cpp:31
malloc
void * malloc(size_t)
liballoc_lock
int liballoc_lock()
This function is supposed to lock the memory data structures. It could be as simple as disabling inte...
Definition: heap.cpp:21
calloc
void * calloc(size_t, size_t)