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;
|
||||
|
||||
Reference in New Issue
Block a user