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