Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Documentation is sparse, but you can use doxygen to build it from the in-code co

- It boots up on most modern-day 64-bit systems that support x86_64 (so no ARM)
- It can print stuff on your screen
- It can do some basic memory management with paging
- More to come

## Setup
Expand Down
85 changes: 85 additions & 0 deletions include/liballoc/liballoc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#ifndef _LIBALLOC_H
#define _LIBALLOC_H

#include <stddef.h>
#include <stdint.h>

/** \defgroup ALLOCHOOKS liballoc hooks
*
* These are the OS specific functions which need to
* be implemented on any platform that the library
* is expected to work on.
*/

/** @{ */



// If we are told to not define our own size_t, then we skip the define.
//#define _HAVE_UINTPTR_T
//typedef unsigned long uintptr_t;

//This lets you prefix malloc and friends
#define PREFIX(func) k ## func

#ifdef __cplusplus
extern "C" {
#endif



/** 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.
*
* \return 0 if the lock was acquired successfully. Anything else is
* failure.
*/
extern int liballoc_lock();

/** 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.
*
* \return 0 if the lock was successfully released.
*/
extern int liballoc_unlock();

/** 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.
*
* \return NULL if the pages were not allocated.
* \return A pointer to the allocated memory.
*/
extern void* liballoc_alloc(size_t);

/** 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.
*
* \return 0 if the memory was successfully freed.
*/
extern int liballoc_free(void*,size_t);




extern void *PREFIX(malloc)(size_t); ///< The standard function.
extern void *PREFIX(realloc)(void *, size_t); ///< The standard function.
extern void *PREFIX(calloc)(size_t, size_t); ///< The standard function.
extern void PREFIX(free)(void *); ///< The standard function.


#ifdef __cplusplus
}
#endif


/** @} */

#endif


9 changes: 9 additions & 0 deletions include/memmgt.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,13 @@ void* get_paddr(void* vaddr);

uint64_t allocate_physical_pageframes(size_t);


// LIBALLOC FUNCTION IMPLEMENTATIONS

void* try_assign_pt(pt_entry_t*, size_t);
int liballoc_lock();
int liballoc_unlock();
void* liballoc_alloc(size_t);
int liballoc_free(void*, size_t);

#endif
2 changes: 2 additions & 0 deletions src/entry.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <memmgt.h>
#include <stdio.h>

#include <liballoc/liballoc.h>

#define FONT_SIZE 2

// volatile so that compiler does not mess with the structure
Expand Down
Loading