Xyris  0.5
heap.cpp File Reference
#include <Library/errno.hpp>
#include <Locking/Mutex.hpp>
#include <Memory/heap.hpp>
#include <Memory/paging.hpp>
#include <stddef.h>
+ Include dependency graph for heap.cpp:

Go to the source code of this file.

Functions

int liballoc_lock ()
 
int liballoc_unlock ()
 
void * liballoc_alloc (unsigned int count)
 
int liballoc_free (void *page, unsigned int count)
 

Detailed Description

Liballoc heap implementation.

Author
Keeton Feavel (keeto.nosp@m.nfea.nosp@m.vel@c.nosp@m.edar.nosp@m.ville.nosp@m..edu)
Version
0.1
Date
2021-08-24

Definition in file heap.cpp.

Function Documentation

◆ liballoc_alloc()

void* liballoc_alloc ( unsigned int  )

This is the hook into the local system which allocates pages. It accepts an integer parameter which is the number of pages required. The page size was set up in the liballoc_init function.

Returns
NULL if the pages were not allocated.
A pointer to the allocated memory.

Definition at line 31 of file heap.cpp.

32 {
33  return Memory::newPage(count * ARCH_PAGE_SIZE - 1);
34 }
+ Here is the call graph for this function:

◆ liballoc_free()

int liballoc_free ( void *  ,
unsigned int   
)

This frees previously allocated memory. The void* parameter passed to the function is the exact same value returned from a previous liballoc_alloc call.

The integer value is the number of pages to free.

Returns
0 if the memory was successfully freed.

Definition at line 36 of file heap.cpp.

37 {
38  Memory::freePage(page, count * ARCH_PAGE_SIZE - 1);
39  return 0;
40 }
+ Here is the call graph for this function:

◆ liballoc_lock()

int liballoc_lock ( )

This function is supposed to lock the memory data structures. It could be as simple as disabling interrupts or acquiring a spinlock. It's up to you to decide.

Returns
0 if the lock was acquired successfully. Anything else is failure.

Definition at line 21 of file heap.cpp.

22 {
23  return (lock.lock() ? 0 : 1);
24 }

◆ liballoc_unlock()

int liballoc_unlock ( )

This function unlocks what was previously locked by the liballoc_lock function. If it disabled interrupts, it enables interrupts. If it had acquiried a spinlock, it releases the spinlock. etc.

Returns
0 if the lock was successfully released.

Definition at line 26 of file heap.cpp.

27 {
28  return (lock.unlock() ? 0 : 1);
29 }
Mutex::unlock
bool unlock()
Release the mutex.
Definition: Mutex.cpp:38
Memory::freePage
void freePage(void *page, size_t size)
Frees pages starting at a given page address.
Definition: paging.cpp:246
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
ARCH_PAGE_SIZE
#define ARCH_PAGE_SIZE
Definition: Memory.i686.hpp:21