Mass rename memory object variables.
Use shorthand: AddressSpace -> vmas MemoryObject -> vmmo The VM prefix makes these a little more distinguishable in code.
This commit is contained in:
parent
a8a4f8d9ab
commit
6c10c57bfa
|
@ -1,6 +1,7 @@
|
|||
#include "include/mammoth/process.h"
|
||||
|
||||
#include <zcall.h>
|
||||
#include <zerrors.h>
|
||||
|
||||
#include "include/mammoth/debug.h"
|
||||
|
||||
|
@ -68,7 +69,7 @@ uint64_t LoadElfProgram(uint64_t base, uint64_t as_cap) {
|
|||
|
||||
dbgln("Map Local");
|
||||
uint64_t vaddr;
|
||||
check(ZAddressSpaceMap(Z_INIT_AS_SELF, 0, mem_cap, &vaddr));
|
||||
check(ZAddressSpaceMap(Z_INIT_VMAS_SELF, 0, mem_cap, &vaddr));
|
||||
|
||||
dbgln("Copy");
|
||||
memcpy(base + program.offset, program.filesz, vaddr);
|
||||
|
@ -94,4 +95,6 @@ uint64_t SpawnProcessFromElfRegion(uint64_t program) {
|
|||
|
||||
dbgln("Thread start");
|
||||
check(ZThreadStart(thread_cap, entry_point, 0, 0));
|
||||
|
||||
return Z_OK;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
int main() {
|
||||
dbgln("Testing");
|
||||
uint64_t vaddr;
|
||||
check(ZAddressSpaceMap(Z_INIT_AS_SELF, 0, Z_INIT_BOOT_VMMO, &vaddr));
|
||||
check(ZAddressSpaceMap(Z_INIT_VMAS_SELF, 0, Z_INIT_BOOT_VMMO, &vaddr));
|
||||
check(SpawnProcessFromElfRegion(vaddr));
|
||||
dbgln("Return");
|
||||
return 0;
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#define Z_ADDRESS_SPACE_MAP 0x21
|
||||
#define Z_ADDRESS_SPACE_UNMAP 0x22
|
||||
|
||||
#define Z_INIT_AS_SELF 0x20
|
||||
#define Z_INIT_VMAS_SELF 0x20
|
||||
|
||||
#define Z_MEMORY_OBJECT_CREATE 0x30
|
||||
|
||||
|
@ -38,7 +38,7 @@
|
|||
void ZProcessExit(uint64_t code);
|
||||
|
||||
[[nodiscard]] uint64_t ZProcessSpawn(uint64_t proc_cap, uint64_t* new_proc_cap,
|
||||
uint64_t* new_as_cap);
|
||||
uint64_t* new_vmas_cap);
|
||||
|
||||
// UNUSED for now, I think we can get away with just starting a thread.
|
||||
[[nodiscard]] uint64_t ZProcessStart(uint64_t proc_cap, uint64_t thread_cap,
|
||||
|
@ -52,8 +52,8 @@ void ZProcessExit(uint64_t code);
|
|||
|
||||
void ZThreadExit();
|
||||
|
||||
[[nodiscard]] uint64_t ZAddressSpaceMap(uint64_t as_cap, uint64_t offset,
|
||||
uint64_t mem_cap, uint64_t* vaddr);
|
||||
[[nodiscard]] uint64_t ZMemoryObjectCreate(uint64_t size, uint64_t* mem_cap);
|
||||
[[nodiscard]] uint64_t ZAddressSpaceMap(uint64_t vmas_cap, uint64_t vmas_offset,
|
||||
uint64_t vmmo_cap, uint64_t* vaddr);
|
||||
[[nodiscard]] uint64_t ZMemoryObjectCreate(uint64_t size, uint64_t* vmmo_cap);
|
||||
|
||||
[[nodiscard]] uint64_t ZDebug(const char* message);
|
||||
|
|
|
@ -26,12 +26,12 @@ RefPtr<Process> Process::Create() {
|
|||
new Capability(proc, Capability::PROCESS, Z_INIT_PROC_SELF,
|
||||
ZC_PROC_SPAWN_PROC | ZC_PROC_SPAWN_THREAD));
|
||||
proc->caps_.PushBack(new Capability(proc->vmas(), Capability::ADDRESS_SPACE,
|
||||
Z_INIT_AS_SELF, ZC_WRITE));
|
||||
Z_INIT_VMAS_SELF, ZC_WRITE));
|
||||
return proc;
|
||||
}
|
||||
|
||||
Process::Process()
|
||||
: id_(gNextId++), vmm_(MakeRefCounted<AddressSpace>()), state_(RUNNING) {}
|
||||
: id_(gNextId++), vmas_(MakeRefCounted<AddressSpace>()), state_(RUNNING) {}
|
||||
|
||||
RefPtr<Thread> Process::CreateThread() {
|
||||
RefPtr<Thread> thread = MakeRefCounted<Thread>(*this, next_thread_id_++);
|
||||
|
@ -87,20 +87,20 @@ uint64_t Process::AddCapability(const RefPtr<Process>& p) {
|
|||
ZC_WRITE | ZC_PROC_SPAWN_THREAD));
|
||||
return cap_id;
|
||||
}
|
||||
uint64_t Process::AddCapability(const RefPtr<AddressSpace>& as) {
|
||||
uint64_t Process::AddCapability(const RefPtr<AddressSpace>& vmas) {
|
||||
uint64_t cap_id = next_cap_id_++;
|
||||
caps_.PushBack(
|
||||
new Capability(as, Capability::ADDRESS_SPACE, cap_id, ZC_WRITE));
|
||||
new Capability(vmas, Capability::ADDRESS_SPACE, cap_id, ZC_WRITE));
|
||||
return cap_id;
|
||||
}
|
||||
uint64_t Process::AddCapability(const RefPtr<MemoryObject>& mo) {
|
||||
uint64_t Process::AddCapability(const RefPtr<MemoryObject>& vmmo) {
|
||||
uint64_t cap_id = next_cap_id_++;
|
||||
caps_.PushBack(
|
||||
new Capability(mo, Capability::MEMORY_OBJECT, cap_id, ZC_WRITE));
|
||||
new Capability(vmmo, Capability::MEMORY_OBJECT, cap_id, ZC_WRITE));
|
||||
return cap_id;
|
||||
}
|
||||
|
||||
void Process::AddCapability(uint64_t cap_id, const RefPtr<MemoryObject>& mo) {
|
||||
void Process::AddCapability(uint64_t cap_id, const RefPtr<MemoryObject>& vmmo) {
|
||||
caps_.PushBack(
|
||||
new Capability(mo, Capability::MEMORY_OBJECT, cap_id, ZC_WRITE));
|
||||
new Capability(vmmo, Capability::MEMORY_OBJECT, cap_id, ZC_WRITE));
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ class Process : public KernelObject {
|
|||
static RefPtr<Process> Create();
|
||||
|
||||
uint64_t id() const { return id_; }
|
||||
RefPtr<AddressSpace> vmas() { return vmm_; }
|
||||
RefPtr<AddressSpace> vmas() { return vmas_; }
|
||||
|
||||
RefPtr<Thread> CreateThread();
|
||||
RefPtr<Thread> GetThread(uint64_t tid);
|
||||
|
@ -31,10 +31,10 @@ class Process : public KernelObject {
|
|||
SharedPtr<Capability> GetCapability(uint64_t cid);
|
||||
uint64_t AddCapability(const RefPtr<Thread>& t);
|
||||
uint64_t AddCapability(const RefPtr<Process>& p);
|
||||
uint64_t AddCapability(const RefPtr<AddressSpace>& as);
|
||||
uint64_t AddCapability(const RefPtr<MemoryObject>& mo);
|
||||
uint64_t AddCapability(const RefPtr<AddressSpace>& vmas);
|
||||
uint64_t AddCapability(const RefPtr<MemoryObject>& vmmo);
|
||||
|
||||
void AddCapability(uint64_t cap_id, const RefPtr<MemoryObject>& mo);
|
||||
void AddCapability(uint64_t cap_id, const RefPtr<MemoryObject>& vmmo);
|
||||
// Checks the state of all child threads and transitions to
|
||||
// finished if all have finished.
|
||||
void CheckState();
|
||||
|
@ -44,9 +44,9 @@ class Process : public KernelObject {
|
|||
private:
|
||||
friend class MakeRefCountedFriend<Process>;
|
||||
Process();
|
||||
Process(uint64_t id) : id_(id), vmm_(AddressSpace::ForRoot()) {}
|
||||
Process(uint64_t id) : id_(id), vmas_(AddressSpace::ForRoot()) {}
|
||||
uint64_t id_;
|
||||
RefPtr<AddressSpace> vmm_;
|
||||
RefPtr<AddressSpace> vmas_;
|
||||
State state_;
|
||||
|
||||
uint64_t next_thread_id_ = 0;
|
||||
|
|
|
@ -72,7 +72,7 @@ uint64_t ProcessSpawn(ZProcessSpawnReq* req, ZProcessSpawnResp* resp) {
|
|||
gProcMan->InsertProcess(proc);
|
||||
|
||||
resp->proc_cap = curr_proc.AddCapability(proc);
|
||||
resp->as_cap = curr_proc.AddCapability(proc->vmas());
|
||||
resp->vmas_cap = curr_proc.AddCapability(proc->vmas());
|
||||
|
||||
return Z_OK;
|
||||
}
|
||||
|
@ -120,33 +120,34 @@ uint64_t ThreadStart(ZThreadStartReq* req) {
|
|||
|
||||
uint64_t AddressSpaceMap(ZAddressSpaceMapReq* req, ZAddressSpaceMapResp* resp) {
|
||||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
auto as_cap = curr_proc.GetCapability(req->as_cap);
|
||||
auto mem_cap = curr_proc.GetCapability(req->mem_cap);
|
||||
if (as_cap.empty() || mem_cap.empty()) {
|
||||
auto vmas_cap = curr_proc.GetCapability(req->vmas_cap);
|
||||
auto vmmo_cap = curr_proc.GetCapability(req->vmmo_cap);
|
||||
if (vmas_cap.empty() || vmmo_cap.empty()) {
|
||||
return ZE_NOT_FOUND;
|
||||
}
|
||||
if (!as_cap->CheckType(Capability::ADDRESS_SPACE) ||
|
||||
!mem_cap->CheckType(Capability::MEMORY_OBJECT)) {
|
||||
if (!vmas_cap->CheckType(Capability::ADDRESS_SPACE) ||
|
||||
!vmmo_cap->CheckType(Capability::MEMORY_OBJECT)) {
|
||||
return ZE_INVALID;
|
||||
}
|
||||
if (!as_cap->HasPermissions(ZC_WRITE) || !mem_cap->HasPermissions(ZC_WRITE)) {
|
||||
if (!vmas_cap->HasPermissions(ZC_WRITE) ||
|
||||
!vmmo_cap->HasPermissions(ZC_WRITE)) {
|
||||
return ZE_DENIED;
|
||||
}
|
||||
auto as = as_cap->obj<AddressSpace>();
|
||||
auto mo = mem_cap->obj<MemoryObject>();
|
||||
auto vmas = vmas_cap->obj<AddressSpace>();
|
||||
auto vmmo = vmmo_cap->obj<MemoryObject>();
|
||||
// FIXME: Validation necessary.
|
||||
if (req->offset != 0) {
|
||||
as->MapInMemoryObject(req->offset, mo);
|
||||
resp->vaddr = req->offset;
|
||||
if (req->vmas_offset != 0) {
|
||||
vmas->MapInMemoryObject(req->vmas_offset, vmmo);
|
||||
resp->vaddr = req->vmas_offset;
|
||||
} else {
|
||||
resp->vaddr = as->MapInMemoryObject(mo);
|
||||
resp->vaddr = vmas->MapInMemoryObject(vmmo);
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t MemoryObjectCreate(ZMemoryObjectCreateReq* req,
|
||||
ZMemoryObjectCreateResp* resp) {
|
||||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
resp->mem_cap =
|
||||
resp->vmmo_cap =
|
||||
curr_proc.AddCapability(MakeRefCounted<MemoryObject>(req->size));
|
||||
return Z_OK;
|
||||
}
|
||||
|
|
|
@ -30,14 +30,14 @@ void ZProcessExit(uint64_t code) {
|
|||
}
|
||||
|
||||
uint64_t ZProcessSpawn(uint64_t proc_cap, uint64_t* new_proc_cap,
|
||||
uint64_t* new_as_cap) {
|
||||
uint64_t* new_vmas_cap) {
|
||||
ZProcessSpawnReq req{
|
||||
.proc_cap = proc_cap,
|
||||
};
|
||||
ZProcessSpawnResp resp;
|
||||
uint64_t ret = SysCall2(Z_PROCESS_SPAWN, &req, &resp);
|
||||
*new_proc_cap = resp.proc_cap;
|
||||
*new_as_cap = resp.as_cap;
|
||||
*new_vmas_cap = resp.vmas_cap;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -64,25 +64,25 @@ uint64_t ZThreadStart(uint64_t thread_cap, uint64_t entry, uint64_t arg1,
|
|||
|
||||
void ZThreadExit() { SysCall0(Z_THREAD_EXIT); }
|
||||
|
||||
uint64_t ZAddressSpaceMap(uint64_t as_cap, uint64_t offset, uint64_t mem_cap,
|
||||
uint64_t* vaddr) {
|
||||
uint64_t ZAddressSpaceMap(uint64_t vmas_cap, uint64_t vmas_offset,
|
||||
uint64_t vmmo_cap, uint64_t* vaddr) {
|
||||
ZAddressSpaceMapReq req{
|
||||
.as_cap = as_cap,
|
||||
.offset = offset,
|
||||
.mem_cap = mem_cap,
|
||||
.vmas_cap = vmas_cap,
|
||||
.vmas_offset = vmas_offset,
|
||||
.vmmo_cap = vmmo_cap,
|
||||
};
|
||||
ZAddressSpaceMapResp resp;
|
||||
uint64_t ret = SysCall2(Z_ADDRESS_SPACE_MAP, &req, &resp);
|
||||
*vaddr = resp.vaddr;
|
||||
return ret;
|
||||
}
|
||||
uint64_t ZMemoryObjectCreate(uint64_t size, uint64_t* mem_cap) {
|
||||
uint64_t ZMemoryObjectCreate(uint64_t size, uint64_t* vmmo_cap) {
|
||||
ZMemoryObjectCreateReq req{
|
||||
.size = size,
|
||||
};
|
||||
ZMemoryObjectCreateResp resp;
|
||||
uint64_t ret = SysCall2(Z_MEMORY_OBJECT_CREATE, &req, &resp);
|
||||
*mem_cap = resp.mem_cap;
|
||||
*vmmo_cap = resp.vmmo_cap;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ struct ZProcessSpawnReq {
|
|||
|
||||
struct ZProcessSpawnResp {
|
||||
uint64_t proc_cap;
|
||||
uint64_t as_cap;
|
||||
uint64_t vmas_cap;
|
||||
};
|
||||
|
||||
struct ZThreadCreateReq {
|
||||
|
@ -27,9 +27,9 @@ struct ZThreadStartReq {
|
|||
};
|
||||
|
||||
struct ZAddressSpaceMapReq {
|
||||
uint64_t as_cap;
|
||||
uint64_t offset;
|
||||
uint64_t mem_cap;
|
||||
uint64_t vmas_cap;
|
||||
uint64_t vmas_offset;
|
||||
uint64_t vmmo_cap;
|
||||
};
|
||||
|
||||
struct ZAddressSpaceMapResp {
|
||||
|
@ -41,5 +41,5 @@ struct ZMemoryObjectCreateReq {
|
|||
};
|
||||
|
||||
struct ZMemoryObjectCreateResp {
|
||||
uint64_t mem_cap;
|
||||
uint64_t vmmo_cap;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue