Redesign userspace memory management
All checks were successful
Build documentation / build-and-deploy (push) Successful in 44s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 44s
This commit is contained in:
@@ -6,8 +6,6 @@
|
||||
|
||||
#define LIBALLOC_MUTEX 500
|
||||
|
||||
static uintptr_t liballoc_map_base = PROC_MAP_BASE;
|
||||
static int mem_rid_base = 1000000;
|
||||
static int liballoc_mutex;
|
||||
|
||||
void liballoc_init (void) { liballoc_mutex = create_mutex (LIBALLOC_MUTEX); }
|
||||
@@ -18,30 +16,9 @@ int liballoc_lock (void) { return lock_mutex (liballoc_mutex); }
|
||||
|
||||
int liballoc_unlock (void) { return unlock_mutex (liballoc_mutex); }
|
||||
|
||||
void* liballoc_alloc (int pages, int* mem_rid) {
|
||||
uintptr_t current_base = liballoc_map_base;
|
||||
void* liballoc_alloc (int pages) { return map (0, pages, MAP_FLAGS | MAP_RW); }
|
||||
|
||||
*mem_rid = create_mem (mem_rid_base++, pages);
|
||||
if (*mem_rid < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (map (*mem_rid, current_base, MAP_FLAGS | MAP_RW) < 0) {
|
||||
unlink_mem (*mem_rid, pages);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uintptr_t old_base = current_base;
|
||||
current_base += pages * PAGE_SIZE;
|
||||
|
||||
return (void*)old_base;
|
||||
}
|
||||
|
||||
int liballoc_free (void* ptr, int pages, int mem_rid) {
|
||||
unmap ((uintptr_t)ptr, pages);
|
||||
unlink_mem (mem_rid, pages);
|
||||
return 0;
|
||||
}
|
||||
int liballoc_free (void* ptr, int pages) { return unmap ((uintptr_t)ptr, pages); }
|
||||
|
||||
/** Durand's Ridiculously Amazing Super Duper Memory functions. */
|
||||
|
||||
@@ -208,7 +185,6 @@ static struct boundary_tag* allocate_new_tag (unsigned int size) {
|
||||
unsigned int pages;
|
||||
unsigned int usage;
|
||||
struct boundary_tag* tag;
|
||||
int mem_rid;
|
||||
|
||||
// This is how much space is required.
|
||||
usage = size + sizeof (struct boundary_tag);
|
||||
@@ -222,7 +198,7 @@ static struct boundary_tag* allocate_new_tag (unsigned int size) {
|
||||
if (pages < (unsigned int)l_pageCount)
|
||||
pages = l_pageCount;
|
||||
|
||||
tag = (struct boundary_tag*)liballoc_alloc (pages, &mem_rid);
|
||||
tag = (struct boundary_tag*)liballoc_alloc (pages);
|
||||
|
||||
if (tag == NULL)
|
||||
return NULL; // uh oh, we ran out of memory.
|
||||
@@ -231,7 +207,6 @@ static struct boundary_tag* allocate_new_tag (unsigned int size) {
|
||||
tag->size = size;
|
||||
tag->real_size = pages * l_pageSize;
|
||||
tag->index = -1;
|
||||
tag->mem_rid = mem_rid;
|
||||
|
||||
tag->next = NULL;
|
||||
tag->prev = NULL;
|
||||
@@ -354,7 +329,7 @@ void free (void* ptr) {
|
||||
if (pages < (unsigned int)l_pageCount)
|
||||
pages = l_pageCount;
|
||||
|
||||
liballoc_free (tag, pages, tag->mem_rid);
|
||||
liballoc_free (tag, pages);
|
||||
|
||||
liballoc_unlock ();
|
||||
return;
|
||||
|
||||
@@ -41,8 +41,6 @@ struct boundary_tag {
|
||||
|
||||
struct boundary_tag* next; //< Linked list info.
|
||||
struct boundary_tag* prev; //< Linked list info.
|
||||
|
||||
int mem_rid;
|
||||
};
|
||||
|
||||
/** This function is supposed to lock the memory data structures. It
|
||||
@@ -69,7 +67,7 @@ extern int liballoc_unlock (void);
|
||||
* \return NULL if the pages were not allocated.
|
||||
* \return A pointer to the allocated memory.
|
||||
*/
|
||||
extern void* liballoc_alloc (int pages, int* mem_rid);
|
||||
extern void* liballoc_alloc (int pages);
|
||||
|
||||
/** This frees previously allocated memory. The void* parameter passed
|
||||
* to the function is the exact same value returned from a previous
|
||||
@@ -79,7 +77,7 @@ extern void* liballoc_alloc (int pages, int* mem_rid);
|
||||
*
|
||||
* \return 0 if the memory was successfully freed.
|
||||
*/
|
||||
extern int liballoc_free (void* ptr, int pages, int mem_rid);
|
||||
extern int liballoc_free (void* ptr, int pages);
|
||||
|
||||
void* malloc (size_t); //< The standard function.
|
||||
void* realloc (void*, size_t); //< The standard function.
|
||||
|
||||
Reference in New Issue
Block a user