Xyris  0.5
heap.cpp
Go to the documentation of this file.
1 /**
2  * @file heap.cpp
3  * @author Keeton Feavel ([email protected])
4  * @brief Liballoc heap implementation
5  * @version 0.1
6  * @date 2021-08-24
7  *
8  * @copyright Copyright the Xyris Contributors (c) 2021
9  *
10  */
11 #include <Library/errno.hpp>
12 #include <Locking/Mutex.hpp>
13 #include <Memory/heap.hpp>
14 #include <Memory/paging.hpp>
15 #include <stddef.h>
16 
17 static Mutex lock("alloc");
18 
19 extern "C" {
20 
22 {
23  return (lock.lock() ? 0 : 1);
24 }
25 
27 {
28  return (lock.unlock() ? 0 : 1);
29 }
30 
31 void* liballoc_alloc(unsigned int count)
32 {
33  return Memory::newPage(count * ARCH_PAGE_SIZE - 1);
34 }
35 
36 int liballoc_free(void* page, unsigned int count)
37 {
38  Memory::freePage(page, count * ARCH_PAGE_SIZE - 1);
39  return 0;
40 }
41 
42 }
Mutex::unlock
bool unlock()
Release the mutex.
Definition: Mutex.cpp:38
errno.hpp
Kernel error definitions.
Memory::freePage
void freePage(void *page, size_t size)
Frees pages starting at a given page address.
Definition: paging.cpp:246
liballoc_free
int liballoc_free(void *page, unsigned int count)
This frees previously allocated memory. The void* parameter passed to the function is the exact same ...
Definition: heap.cpp:36
Mutex
Definition: Mutex.hpp:16
Mutex::lock
bool lock()
Aquire the mutex.
Definition: Mutex.cpp:20
Memory::newPage
void * newPage(size_t size)
Returns a new page in memory for use. If less than one page is requested, exactly one page will be al...
Definition: paging.cpp:228
paging.hpp
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
heap.hpp
Liballoc heap implementation.
Mutex.hpp
ARCH_PAGE_SIZE
#define ARCH_PAGE_SIZE
Definition: Memory.i686.hpp:21
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_alloc
void * liballoc_alloc(unsigned int count)
This is the hook into the local system which allocates pages. It accepts an integer parameter which i...
Definition: heap.cpp:31