Started separating important structs from kernel.c

This commit is contained in:
2023-11-08 14:13:03 -06:00
parent 108e04a8f0
commit c5ef8c53a7
6 changed files with 160 additions and 0 deletions

37
src/sharedobject.c Normal file
View File

@@ -0,0 +1,37 @@
#include "sharedobject.h"
#include "avltree.h"
#include "mmgr.h"
#include "heap.h"
struct shared_object *create_shared_object(size_t size, unsigned long flags)
{
physaddr_t phys_addr = reserve_pages(size);
if(phys_addr == NULL)
{
return NULL;
}
struct shared_object_t *obj = kmalloc(sizeof(struct shared_object_t));
if(obj == NULL)
{
free_pages(phys_addr);
return NULL;
}
obj->phys_addr = phys_addr;
obj->size = size;
obj->access_flags = flags;
obj->refcount = 0;
obj->users = NULL;
return obj;
}
void destroy_shared_object(struct shared_object_t *obj)
{
if(obj != NULL)
{
free_pages(obj->phys_addr);
avl_clear(obj->users);
kfree(obj);
}
}