All checks were successful
Build documentation / build-and-deploy (push) Successful in 33s
38 lines
983 B
C
38 lines
983 B
C
#include <libk/std.h>
|
|
#include <mm/pmm.h>
|
|
#include <proc/mem.h>
|
|
#include <proc/proc.h>
|
|
#include <proc/resource.h>
|
|
#include <sync/spin_lock.h>
|
|
|
|
bool proc_create_resource_mem (struct proc_resource_mem* mem, struct proc_resource_mem_init* init) {
|
|
if (init->pages == 0)
|
|
return false;
|
|
|
|
uintptr_t paddr = pmm_alloc (init->pages);
|
|
if (paddr == PMM_ALLOC_ERR)
|
|
return false;
|
|
|
|
mem->paddr = paddr;
|
|
mem->pages = mem->alive_pages = init->pages;
|
|
|
|
return true;
|
|
}
|
|
|
|
void proc_cleanup_resource_mem (struct proc* proc, struct proc_resource* resource) {
|
|
(void)proc;
|
|
pmm_free (resource->u.mem.paddr, resource->u.mem.pages);
|
|
}
|
|
|
|
void proc_mem_unref (struct proc* proc, struct proc_resource_mem* mem, size_t pages) {
|
|
spin_lock_ctx_t ctxrs;
|
|
|
|
spin_lock (&mem->resource->lock, &ctxrs);
|
|
mem->alive_pages -= pages;
|
|
ptrdiff_t current_pages = mem->alive_pages;
|
|
spin_unlock (&mem->resource->lock, &ctxrs);
|
|
|
|
if (current_pages <= 0)
|
|
proc_drop_resource (proc, mem->resource);
|
|
}
|