2023-06-20 14:26:06 -07:00
|
|
|
#include "syscall/memory_object.h"
|
|
|
|
|
|
|
|
#include "boot/acpi.h"
|
|
|
|
#include "memory/physical_memory.h"
|
|
|
|
#include "scheduler/scheduler.h"
|
|
|
|
|
|
|
|
z_err_t MemoryObjectCreate(ZMemoryObjectCreateReq* req) {
|
|
|
|
auto& curr_proc = gScheduler->CurrentProcess();
|
2023-08-01 18:22:41 -07:00
|
|
|
*req->vmmo_cap =
|
|
|
|
curr_proc.AddNewCapability(glcr::MakeRefCounted<MemoryObject>(req->size));
|
2023-06-21 18:28:54 -07:00
|
|
|
return glcr::OK;
|
2023-06-20 14:26:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
z_err_t MemoryObjectCreatePhysical(ZMemoryObjectCreatePhysicalReq* req) {
|
|
|
|
auto& curr_proc = gScheduler->CurrentProcess();
|
|
|
|
uint64_t paddr = req->paddr;
|
2023-06-21 15:07:40 -07:00
|
|
|
auto vmmo_ref = glcr::MakeRefCounted<FixedMemoryObject>(paddr, req->size);
|
2023-08-01 18:22:41 -07:00
|
|
|
*req->vmmo_cap =
|
|
|
|
curr_proc.AddNewCapability(StaticCastRefPtr<MemoryObject>(vmmo_ref));
|
2023-06-21 18:28:54 -07:00
|
|
|
return glcr::OK;
|
2023-06-20 14:26:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
z_err_t MemoryObjectCreateContiguous(ZMemoryObjectCreateContiguousReq* req) {
|
|
|
|
auto& curr_proc = gScheduler->CurrentProcess();
|
|
|
|
uint64_t paddr = phys_mem::AllocateContinuous(((req->size - 1) / 0x1000) + 1);
|
2023-06-21 15:07:40 -07:00
|
|
|
auto vmmo_ref = glcr::MakeRefCounted<FixedMemoryObject>(paddr, req->size);
|
2023-08-01 18:22:41 -07:00
|
|
|
*req->vmmo_cap =
|
|
|
|
curr_proc.AddNewCapability(StaticCastRefPtr<MemoryObject>(vmmo_ref));
|
2023-06-20 14:26:06 -07:00
|
|
|
*req->paddr = paddr;
|
2023-06-21 18:28:54 -07:00
|
|
|
return glcr::OK;
|
2023-06-20 14:26:06 -07:00
|
|
|
}
|
2023-08-01 17:46:26 -07:00
|
|
|
|
|
|
|
z_err_t MemoryObjectDuplicate(ZMemoryObjectDuplicateReq* req) {
|
|
|
|
auto& curr_proc = gScheduler->CurrentProcess();
|
|
|
|
auto vmmo_cap = curr_proc.GetCapability(req->vmmo_cap);
|
2023-08-01 18:30:24 -07:00
|
|
|
RET_ERR(ValidateCapability<MemoryObject>(vmmo_cap, kZionPerm_Duplicate));
|
2023-08-01 17:46:26 -07:00
|
|
|
|
|
|
|
ASSIGN_OR_RETURN(
|
|
|
|
glcr::RefPtr<MemoryObject> new_vmmo,
|
|
|
|
vmmo_cap->obj<MemoryObject>()->Duplicate(req->base_offset, req->length));
|
2023-08-01 18:37:17 -07:00
|
|
|
*req->new_vmmo_cap =
|
|
|
|
curr_proc.AddNewCapability(new_vmmo, vmmo_cap->permissions());
|
2023-08-01 17:46:26 -07:00
|
|
|
return glcr::OK;
|
|
|
|
}
|
2023-11-19 19:02:55 -08:00
|
|
|
|
|
|
|
z_err_t MemoryObjectInspect(ZMemoryObjectInspectReq* req) {
|
|
|
|
auto& curr_proc = gScheduler->CurrentProcess();
|
|
|
|
auto vmmo_cap = curr_proc.GetCapability(req->vmmo_cap);
|
|
|
|
RET_ERR(ValidateCapability<MemoryObject>(vmmo_cap, kZionPerm_Read));
|
|
|
|
|
|
|
|
auto vmmo = vmmo_cap->obj<MemoryObject>();
|
|
|
|
*req->size = vmmo->size();
|
|
|
|
|
|
|
|
return glcr::OK;
|
|
|
|
}
|