[zion/glacier] Move RefPtr to glacier.
This commit is contained in:
parent
8bcb574677
commit
e1af79b975
26 changed files with 130 additions and 106 deletions
|
|
@ -8,10 +8,10 @@
|
|||
|
||||
extern KernelStackManager* gKernelStackManager;
|
||||
|
||||
RefPtr<AddressSpace> AddressSpace::ForRoot() {
|
||||
glcr::RefPtr<AddressSpace> AddressSpace::ForRoot() {
|
||||
uint64_t cr3 = 0;
|
||||
asm volatile("mov %%cr3, %0;" : "=r"(cr3));
|
||||
return MakeRefCounted<AddressSpace>(cr3);
|
||||
return glcr::MakeRefCounted<AddressSpace>(cr3);
|
||||
}
|
||||
|
||||
AddressSpace::AddressSpace() {
|
||||
|
|
@ -36,12 +36,13 @@ uint64_t AddressSpace::GetNextMemMapAddr(uint64_t size) {
|
|||
return addr;
|
||||
}
|
||||
|
||||
void AddressSpace::MapInMemoryObject(uint64_t vaddr,
|
||||
const RefPtr<MemoryObject>& mem_obj) {
|
||||
void AddressSpace::MapInMemoryObject(
|
||||
uint64_t vaddr, const glcr::RefPtr<MemoryObject>& mem_obj) {
|
||||
memory_mappings_.PushBack({.vaddr = vaddr, .mem_obj = mem_obj});
|
||||
}
|
||||
|
||||
uint64_t AddressSpace::MapInMemoryObject(const RefPtr<MemoryObject>& mem_obj) {
|
||||
uint64_t AddressSpace::MapInMemoryObject(
|
||||
const glcr::RefPtr<MemoryObject>& mem_obj) {
|
||||
uint64_t vaddr = GetNextMemMapAddr(mem_obj->size());
|
||||
memory_mappings_.PushBack({.vaddr = vaddr, .mem_obj = mem_obj});
|
||||
return vaddr;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/memory/ref_ptr.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "lib/ref_ptr.h"
|
||||
#include "memory/user_stack_manager.h"
|
||||
#include "object/memory_object.h"
|
||||
|
||||
|
|
@ -49,7 +49,7 @@ class AddressSpace : public KernelObject {
|
|||
KERNEL_STACK,
|
||||
};
|
||||
|
||||
static RefPtr<AddressSpace> ForRoot();
|
||||
static glcr::RefPtr<AddressSpace> ForRoot();
|
||||
|
||||
AddressSpace();
|
||||
AddressSpace(const AddressSpace&) = delete;
|
||||
|
|
@ -63,9 +63,10 @@ class AddressSpace : public KernelObject {
|
|||
|
||||
// Maps in a memory object at a specific address.
|
||||
// Note this is unsafe for now as it may clobber other mappings.
|
||||
void MapInMemoryObject(uint64_t vaddr, const RefPtr<MemoryObject>& mem_obj);
|
||||
void MapInMemoryObject(uint64_t vaddr,
|
||||
const glcr::RefPtr<MemoryObject>& mem_obj);
|
||||
|
||||
uint64_t MapInMemoryObject(const RefPtr<MemoryObject>& mem_obj);
|
||||
uint64_t MapInMemoryObject(const glcr::RefPtr<MemoryObject>& mem_obj);
|
||||
|
||||
// Kernel Mappings.
|
||||
uint64_t* AllocateKernelStack();
|
||||
|
|
@ -74,7 +75,7 @@ class AddressSpace : public KernelObject {
|
|||
bool HandlePageFault(uint64_t vaddr);
|
||||
|
||||
private:
|
||||
friend class MakeRefCountedFriend<AddressSpace>;
|
||||
friend class glcr::MakeRefCountedFriend<AddressSpace>;
|
||||
AddressSpace(uint64_t cr3) : cr3_(cr3) {}
|
||||
uint64_t cr3_ = 0;
|
||||
|
||||
|
|
@ -83,7 +84,7 @@ class AddressSpace : public KernelObject {
|
|||
|
||||
struct MemoryMapping {
|
||||
uint64_t vaddr;
|
||||
RefPtr<MemoryObject> mem_obj;
|
||||
glcr::RefPtr<MemoryObject> mem_obj;
|
||||
};
|
||||
LinkedList<MemoryMapping> memory_mappings_;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,9 +3,10 @@
|
|||
#include "include/ztypes.h"
|
||||
#include "scheduler/scheduler.h"
|
||||
|
||||
Pair<RefPtr<Channel>, RefPtr<Channel>> Channel::CreateChannelPair() {
|
||||
auto c1 = MakeRefCounted<Channel>();
|
||||
auto c2 = MakeRefCounted<Channel>();
|
||||
Pair<glcr::RefPtr<Channel>, glcr::RefPtr<Channel>>
|
||||
Channel::CreateChannelPair() {
|
||||
auto c1 = glcr::MakeRefCounted<Channel>();
|
||||
auto c2 = glcr::MakeRefCounted<Channel>();
|
||||
c1->SetPeer(c2);
|
||||
c2->SetPeer(c1);
|
||||
return {c1, c2};
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/memory/ref_ptr.h>
|
||||
|
||||
#include "capability/capability.h"
|
||||
#include "include/ztypes.h"
|
||||
#include "lib/linked_list.h"
|
||||
#include "lib/message_queue.h"
|
||||
#include "lib/mutex.h"
|
||||
#include "lib/pair.h"
|
||||
#include "lib/ref_ptr.h"
|
||||
#include "object/kernel_object.h"
|
||||
#include "usr/zcall_internal.h"
|
||||
|
||||
|
|
@ -20,9 +21,9 @@ struct KernelObjectTag<Channel> {
|
|||
class Channel : public KernelObject {
|
||||
public:
|
||||
uint64_t TypeTag() override { return KernelObject::CHANNEL; }
|
||||
static Pair<RefPtr<Channel>, RefPtr<Channel>> CreateChannelPair();
|
||||
static Pair<glcr::RefPtr<Channel>, glcr::RefPtr<Channel>> CreateChannelPair();
|
||||
|
||||
RefPtr<Channel> peer() { return peer_; }
|
||||
glcr::RefPtr<Channel> peer() { return peer_; }
|
||||
|
||||
z_err_t Write(uint64_t num_bytes, const void* bytes, uint64_t num_caps,
|
||||
const z_cap_t* caps);
|
||||
|
|
@ -32,16 +33,16 @@ class Channel : public KernelObject {
|
|||
private:
|
||||
// FIXME: We will likely never close the channel based on this
|
||||
// circular dependency.
|
||||
RefPtr<Channel> peer_{nullptr};
|
||||
glcr::RefPtr<Channel> peer_{nullptr};
|
||||
|
||||
Mutex mutex_{"channel"};
|
||||
UnboundedMessageQueue message_queue_;
|
||||
|
||||
LinkedList<RefPtr<Thread>> blocked_threads_;
|
||||
LinkedList<glcr::RefPtr<Thread>> blocked_threads_;
|
||||
|
||||
friend class MakeRefCountedFriend<Channel>;
|
||||
friend class glcr::MakeRefCountedFriend<Channel>;
|
||||
Channel() {}
|
||||
void SetPeer(const RefPtr<Channel>& peer) { peer_ = peer; }
|
||||
void SetPeer(const glcr::RefPtr<Channel>& peer) { peer_ = peer; }
|
||||
|
||||
z_err_t WriteInternal(uint64_t num_bytes, const void* bytes,
|
||||
uint64_t num_caps, const z_cap_t* caps);
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ z_err_t Port::Read(uint64_t* num_bytes, void* bytes, uint64_t* num_caps,
|
|||
return message_queue_.PopFront(num_bytes, bytes, num_caps, caps);
|
||||
}
|
||||
|
||||
void Port::WriteKernel(uint64_t init, RefPtr<Capability> cap) {
|
||||
void Port::WriteKernel(uint64_t init, glcr::RefPtr<Capability> cap) {
|
||||
MutexHolder h(mutex_);
|
||||
message_queue_.WriteKernel(init, cap);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/memory/ref_ptr.h>
|
||||
|
||||
#include "capability/capability.h"
|
||||
#include "lib/linked_list.h"
|
||||
#include "lib/message_queue.h"
|
||||
|
|
@ -26,13 +28,13 @@ class Port : public KernelObject {
|
|||
z_err_t Read(uint64_t* num_bytes, void* bytes, uint64_t* num_caps,
|
||||
z_cap_t* caps);
|
||||
|
||||
void WriteKernel(uint64_t init, RefPtr<Capability> cap);
|
||||
void WriteKernel(uint64_t init, glcr::RefPtr<Capability> cap);
|
||||
|
||||
bool HasMessages();
|
||||
|
||||
private:
|
||||
UnboundedMessageQueue message_queue_;
|
||||
LinkedList<RefPtr<Thread>> blocked_threads_;
|
||||
LinkedList<glcr::RefPtr<Thread>> blocked_threads_;
|
||||
|
||||
Mutex mutex_{"Port"};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -13,26 +13,31 @@ static uint64_t gNextId = 1;
|
|||
|
||||
}
|
||||
|
||||
RefPtr<Process> Process::RootProcess() {
|
||||
RefPtr<Process> proc = MakeRefCounted<Process>(0);
|
||||
glcr::RefPtr<Process> Process::RootProcess() {
|
||||
glcr::RefPtr<Process> proc = glcr::MakeRefCounted<Process>(0);
|
||||
proc->threads_.PushBack(Thread::RootThread(*proc));
|
||||
proc->next_thread_id_ = 1;
|
||||
|
||||
return proc;
|
||||
}
|
||||
RefPtr<Process> Process::Create() { return MakeRefCounted<Process>(); }
|
||||
glcr::RefPtr<Process> Process::Create() {
|
||||
return glcr::MakeRefCounted<Process>();
|
||||
}
|
||||
|
||||
Process::Process()
|
||||
: id_(gNextId++), vmas_(MakeRefCounted<AddressSpace>()), state_(RUNNING) {}
|
||||
: id_(gNextId++),
|
||||
vmas_(glcr::MakeRefCounted<AddressSpace>()),
|
||||
state_(RUNNING) {}
|
||||
|
||||
RefPtr<Thread> Process::CreateThread() {
|
||||
glcr::RefPtr<Thread> Process::CreateThread() {
|
||||
MutexHolder lock(mutex_);
|
||||
RefPtr<Thread> thread = MakeRefCounted<Thread>(*this, next_thread_id_++);
|
||||
glcr::RefPtr<Thread> thread =
|
||||
glcr::MakeRefCounted<Thread>(*this, next_thread_id_++);
|
||||
threads_.PushBack(thread);
|
||||
return thread;
|
||||
}
|
||||
|
||||
RefPtr<Thread> Process::GetThread(uint64_t tid) {
|
||||
glcr::RefPtr<Thread> Process::GetThread(uint64_t tid) {
|
||||
MutexHolder lock(mutex_);
|
||||
auto iter = threads_.begin();
|
||||
while (iter != threads_.end()) {
|
||||
|
|
@ -57,14 +62,14 @@ void Process::CheckState() {
|
|||
state_ = FINISHED;
|
||||
}
|
||||
|
||||
RefPtr<Capability> Process::ReleaseCapability(uint64_t cid) {
|
||||
glcr::RefPtr<Capability> Process::ReleaseCapability(uint64_t cid) {
|
||||
return caps_.ReleaseCapability(cid);
|
||||
}
|
||||
|
||||
RefPtr<Capability> Process::GetCapability(uint64_t cid) {
|
||||
glcr::RefPtr<Capability> Process::GetCapability(uint64_t cid) {
|
||||
return caps_.GetCapability(cid);
|
||||
}
|
||||
|
||||
uint64_t Process::AddExistingCapability(const RefPtr<Capability>& cap) {
|
||||
uint64_t Process::AddExistingCapability(const glcr::RefPtr<Capability>& cap) {
|
||||
return caps_.AddExistingCapability(cap);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/memory/ref_ptr.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "capability/capability.h"
|
||||
#include "capability/capability_table.h"
|
||||
#include "lib/linked_list.h"
|
||||
#include "lib/mutex.h"
|
||||
#include "lib/ref_ptr.h"
|
||||
#include "object/address_space.h"
|
||||
#include "object/channel.h"
|
||||
#include "object/port.h"
|
||||
|
|
@ -28,23 +28,23 @@ class Process : public KernelObject {
|
|||
RUNNING,
|
||||
FINISHED,
|
||||
};
|
||||
static RefPtr<Process> RootProcess();
|
||||
static RefPtr<Process> Create();
|
||||
static glcr::RefPtr<Process> RootProcess();
|
||||
static glcr::RefPtr<Process> Create();
|
||||
|
||||
uint64_t id() const { return id_; }
|
||||
RefPtr<AddressSpace> vmas() { return vmas_; }
|
||||
glcr::RefPtr<AddressSpace> vmas() { return vmas_; }
|
||||
|
||||
RefPtr<Thread> CreateThread();
|
||||
RefPtr<Thread> GetThread(uint64_t tid);
|
||||
glcr::RefPtr<Thread> CreateThread();
|
||||
glcr::RefPtr<Thread> GetThread(uint64_t tid);
|
||||
|
||||
RefPtr<Capability> ReleaseCapability(uint64_t cid);
|
||||
RefPtr<Capability> GetCapability(uint64_t cid);
|
||||
glcr::RefPtr<Capability> ReleaseCapability(uint64_t cid);
|
||||
glcr::RefPtr<Capability> GetCapability(uint64_t cid);
|
||||
|
||||
template <typename T>
|
||||
uint64_t AddNewCapability(const RefPtr<T>& obj, uint64_t permissions) {
|
||||
uint64_t AddNewCapability(const glcr::RefPtr<T>& obj, uint64_t permissions) {
|
||||
return caps_.AddNewCapability(obj, permissions);
|
||||
}
|
||||
uint64_t AddExistingCapability(const RefPtr<Capability>& cap);
|
||||
uint64_t AddExistingCapability(const glcr::RefPtr<Capability>& cap);
|
||||
|
||||
// Checks the state of all child threads and transitions to
|
||||
// finished if all have finished.
|
||||
|
|
@ -53,19 +53,19 @@ class Process : public KernelObject {
|
|||
State GetState() { return state_; }
|
||||
|
||||
private:
|
||||
friend class MakeRefCountedFriend<Process>;
|
||||
friend class glcr::MakeRefCountedFriend<Process>;
|
||||
Process();
|
||||
Process(uint64_t id) : id_(id), vmas_(AddressSpace::ForRoot()) {}
|
||||
|
||||
Mutex mutex_{"Process"};
|
||||
|
||||
uint64_t id_;
|
||||
RefPtr<AddressSpace> vmas_;
|
||||
glcr::RefPtr<AddressSpace> vmas_;
|
||||
State state_;
|
||||
|
||||
uint64_t next_thread_id_ = 0;
|
||||
uint64_t next_cap_id_ = 0x100;
|
||||
|
||||
LinkedList<RefPtr<Thread>> threads_;
|
||||
LinkedList<glcr::RefPtr<Thread>> threads_;
|
||||
CapabilityTable caps_;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -21,12 +21,12 @@ extern "C" void thread_init() {
|
|||
|
||||
} // namespace
|
||||
|
||||
RefPtr<Thread> Thread::RootThread(Process& root_proc) {
|
||||
return MakeRefCounted<Thread>(root_proc);
|
||||
glcr::RefPtr<Thread> Thread::RootThread(Process& root_proc) {
|
||||
return glcr::MakeRefCounted<Thread>(root_proc);
|
||||
}
|
||||
|
||||
RefPtr<Thread> Thread::Create(Process& proc, uint64_t tid) {
|
||||
return MakeRefCounted<Thread>(proc, tid);
|
||||
glcr::RefPtr<Thread> Thread::Create(Process& proc, uint64_t tid) {
|
||||
return glcr::MakeRefCounted<Thread>(proc, tid);
|
||||
}
|
||||
|
||||
Thread::Thread(Process& proc, uint64_t tid) : process_(proc), id_(tid) {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/memory/ref_ptr.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "lib/ref_ptr.h"
|
||||
#include "object/kernel_object.h"
|
||||
|
||||
// Forward decl due to cyclic dependency.
|
||||
|
|
@ -25,8 +25,8 @@ class Thread : public KernelObject {
|
|||
BLOCKED,
|
||||
FINISHED,
|
||||
};
|
||||
static RefPtr<Thread> RootThread(Process& root_proc);
|
||||
static RefPtr<Thread> Create(Process& proc, uint64_t tid);
|
||||
static glcr::RefPtr<Thread> RootThread(Process& root_proc);
|
||||
static glcr::RefPtr<Thread> Create(Process& proc, uint64_t tid);
|
||||
|
||||
uint64_t tid() const { return id_; };
|
||||
uint64_t pid() const;
|
||||
|
|
@ -48,7 +48,7 @@ class Thread : public KernelObject {
|
|||
void Exit();
|
||||
|
||||
private:
|
||||
friend class MakeRefCountedFriend<Thread>;
|
||||
friend class glcr::MakeRefCountedFriend<Thread>;
|
||||
Thread(Process& proc, uint64_t tid);
|
||||
// Special constructor for the root thread only.
|
||||
Thread(Process& proc) : process_(proc), id_(0) {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue