diff --git a/zion/lib/ref_ptr.h b/lib/glacier/memory/ref_ptr.h similarity index 97% rename from zion/lib/ref_ptr.h rename to lib/glacier/memory/ref_ptr.h index 41e5e87..6cdba6f 100644 --- a/zion/lib/ref_ptr.h +++ b/lib/glacier/memory/ref_ptr.h @@ -1,6 +1,6 @@ #pragma once -#include "debug/debug.h" +namespace glcr { template class RefPtr; @@ -28,7 +28,6 @@ class RefPtr { ptr_->Acquire(); } if (old && old->Release()) { - dbgln("Deleting obj %m", old); delete old; } @@ -90,3 +89,5 @@ template RefPtr StaticCastRefPtr(const RefPtr& ref) { return RefPtr(static_cast(ref.get()), RefPtr::DontAdopt); } + +} // namespace glcr diff --git a/zion/capability/capability.h b/zion/capability/capability.h index 44b5f84..6a4abd7 100644 --- a/zion/capability/capability.h +++ b/zion/capability/capability.h @@ -1,9 +1,10 @@ #pragma once #include +#include #include -#include "lib/ref_ptr.h" +#include "include/ztypes.h" #include "object/kernel_object.h" class Process; @@ -11,17 +12,17 @@ class Thread; class Capability : public glcr::RefCounted { public: - Capability(const RefPtr& obj, uint64_t permissions) + Capability(const glcr::RefPtr& obj, uint64_t permissions) : obj_(obj), permissions_(permissions) {} template - Capability(const RefPtr& obj, uint64_t permissions) + Capability(const glcr::RefPtr& obj, uint64_t permissions) : Capability(StaticCastRefPtr(obj), permissions) {} template - RefPtr obj(); + glcr::RefPtr obj(); - RefPtr raw_obj() { return obj_; } + glcr::RefPtr raw_obj() { return obj_; } uint64_t permissions() { return permissions_; } bool HasPermissions(uint64_t requested) { @@ -29,12 +30,12 @@ class Capability : public glcr::RefCounted { } private: - RefPtr obj_; + glcr::RefPtr obj_; uint64_t permissions_; }; template -RefPtr Capability::obj() { +glcr::RefPtr Capability::obj() { if (obj_->TypeTag() != KernelObjectTag::type) { return nullptr; } @@ -42,7 +43,7 @@ RefPtr Capability::obj() { } template -z_err_t ValidateCapability(const RefPtr& cap, +z_err_t ValidateCapability(const glcr::RefPtr& cap, uint64_t permissions) { if (!cap) { return Z_ERR_CAP_NOT_FOUND; diff --git a/zion/capability/capability_table.cpp b/zion/capability/capability_table.cpp index 48b5910..e673357 100644 --- a/zion/capability/capability_table.cpp +++ b/zion/capability/capability_table.cpp @@ -2,14 +2,15 @@ CapabilityTable::CapabilityTable() {} -uint64_t CapabilityTable::AddExistingCapability(const RefPtr& cap) { +uint64_t CapabilityTable::AddExistingCapability( + const glcr::RefPtr& cap) { MutexHolder h(lock_); uint64_t id = next_cap_id_++; capabilities_.PushBack({.id = id, .cap = cap}); return id; } -RefPtr CapabilityTable::GetCapability(uint64_t id) { +glcr::RefPtr CapabilityTable::GetCapability(uint64_t id) { MutexHolder h(lock_); auto iter = capabilities_.begin(); while (iter != capabilities_.end()) { @@ -23,7 +24,7 @@ RefPtr CapabilityTable::GetCapability(uint64_t id) { return {}; } -RefPtr CapabilityTable::ReleaseCapability(uint64_t id) { +glcr::RefPtr CapabilityTable::ReleaseCapability(uint64_t id) { MutexHolder h(lock_); auto iter = capabilities_.begin(); while (iter != capabilities_.end()) { diff --git a/zion/capability/capability_table.h b/zion/capability/capability_table.h index 8ca1219..21a9ee2 100644 --- a/zion/capability/capability_table.h +++ b/zion/capability/capability_table.h @@ -1,9 +1,10 @@ #pragma once +#include + #include "capability/capability.h" #include "lib/linked_list.h" #include "lib/mutex.h" -#include "lib/ref_ptr.h" class CapabilityTable { public: @@ -13,11 +14,12 @@ class CapabilityTable { CapabilityTable& operator=(CapabilityTable&) = delete; template - uint64_t AddNewCapability(const RefPtr& object, uint64_t permissions); - uint64_t AddExistingCapability(const RefPtr& cap); + uint64_t AddNewCapability(const glcr::RefPtr& object, + uint64_t permissions); + uint64_t AddExistingCapability(const glcr::RefPtr& cap); - RefPtr GetCapability(uint64_t id); - RefPtr ReleaseCapability(uint64_t id); + glcr::RefPtr GetCapability(uint64_t id); + glcr::RefPtr ReleaseCapability(uint64_t id); private: Mutex lock_{"cap table"}; @@ -26,13 +28,13 @@ class CapabilityTable { // FIXME: use a map data structure. struct CapEntry { uint64_t id; - RefPtr cap; + glcr::RefPtr cap; }; LinkedList capabilities_; }; template -uint64_t CapabilityTable::AddNewCapability(const RefPtr& object, +uint64_t CapabilityTable::AddNewCapability(const glcr::RefPtr& object, uint64_t permissions) { MutexHolder h(lock_); uint64_t id = next_cap_id_++; diff --git a/zion/interrupt/interrupt.cpp b/zion/interrupt/interrupt.cpp index d8243a7..ccaab0b 100644 --- a/zion/interrupt/interrupt.cpp +++ b/zion/interrupt/interrupt.cpp @@ -138,7 +138,7 @@ extern "C" void interrupt_timer(InterruptFrame*) { gScheduler->Preempt(); } -RefPtr pci1_port; +glcr::RefPtr pci1_port; extern "C" void isr_pci1(); extern "C" void interrupt_pci1(InterruptFrame*) { dbgln("Interrupt PCI line 1"); @@ -185,4 +185,4 @@ void InitIdt() { EnableApic(); } -void RegisterPciPort(const RefPtr& port) { pci1_port = port; } +void RegisterPciPort(const glcr::RefPtr& port) { pci1_port = port; } diff --git a/zion/interrupt/interrupt.h b/zion/interrupt/interrupt.h index 85bde5d..30219b5 100644 --- a/zion/interrupt/interrupt.h +++ b/zion/interrupt/interrupt.h @@ -1,8 +1,9 @@ #pragma once -#include "lib/ref_ptr.h" +#include + #include "object/port.h" void InitIdt(); -void RegisterPciPort(const RefPtr& port); +void RegisterPciPort(const glcr::RefPtr& port); diff --git a/zion/lib/message_queue.cpp b/zion/lib/message_queue.cpp index 1530679..5622526 100644 --- a/zion/lib/message_queue.cpp +++ b/zion/lib/message_queue.cpp @@ -56,7 +56,8 @@ z_err_t UnboundedMessageQueue::PopFront(uint64_t* num_bytes, void* bytes, return Z_OK; } -void UnboundedMessageQueue::WriteKernel(uint64_t init, RefPtr cap) { +void UnboundedMessageQueue::WriteKernel(uint64_t init, + glcr::RefPtr cap) { auto msg = glcr::MakeShared(); msg->bytes = new uint8_t[8]; msg->num_bytes = sizeof(init); diff --git a/zion/lib/message_queue.h b/zion/lib/message_queue.h index e89fa7d..c76b9ab 100644 --- a/zion/lib/message_queue.h +++ b/zion/lib/message_queue.h @@ -1,7 +1,9 @@ #pragma once +#include +#include + #include "capability/capability.h" -#include "glacier/memory/shared_ptr.h" #include "include/ztypes.h" #include "lib/linked_list.h" @@ -27,7 +29,7 @@ class UnboundedMessageQueue : public MessageQueue { z_err_t PopFront(uint64_t* num_bytes, void* bytes, uint64_t* num_caps, z_cap_t* caps) override; - void WriteKernel(uint64_t init, RefPtr cap); + void WriteKernel(uint64_t init, glcr::RefPtr cap); uint64_t size() { return pending_messages_.size(); } bool empty() { return size() == 0; } @@ -37,7 +39,7 @@ class UnboundedMessageQueue : public MessageQueue { uint64_t num_bytes; uint8_t* bytes; - LinkedList> caps; + LinkedList> caps; }; LinkedList> pending_messages_; diff --git a/zion/loader/init_loader.cpp b/zion/loader/init_loader.cpp index 3158d94..22d5766 100644 --- a/zion/loader/init_loader.cpp +++ b/zion/loader/init_loader.cpp @@ -1,11 +1,11 @@ #include "loader/init_loader.h" +#include #include #include "boot/boot_info.h" #include "debug/debug.h" #include "include/zcall.h" -#include "lib/ref_ptr.h" #include "memory/paging_util.h" #include "object/process.h" #include "object/thread.h" @@ -73,7 +73,7 @@ uint64_t LoadElfProgram(Process& dest_proc, uint64_t base, uint64_t offset) { program.type, program.flags, program.offset, program.vaddr, program.paddr, program.filesz, program.memsz, program.align); #endif - auto mem_obj = MakeRefCounted(program.memsz); + auto mem_obj = glcr::MakeRefCounted(program.memsz); mem_obj->CopyBytesToObject(base + program.offset, program.filesz); dest_proc.vmas()->MapInMemoryObject(program.vaddr, mem_obj); } @@ -122,18 +122,19 @@ void LoadInitProgram() { DumpModules(); const limine_file& init_prog = GetInitProgram("/sys/yellowstone"); - RefPtr proc = Process::Create(); + glcr::RefPtr proc = Process::Create(); gProcMan->InsertProcess(proc); uint64_t entry = LoadElfProgram( *proc, reinterpret_cast(init_prog.address), init_prog.size); const limine_file& prog2 = GetInitProgram("/sys/denali"); - RefPtr prog2_vmmo = MakeRefCounted(prog2.size); + glcr::RefPtr prog2_vmmo = + glcr::MakeRefCounted(prog2.size); prog2_vmmo->CopyBytesToObject(reinterpret_cast(prog2.address), prog2.size); - auto port = MakeRefCounted(); + auto port = glcr::MakeRefCounted(); uint64_t port_cap = proc->AddNewCapability(port, ZC_READ | ZC_WRITE); port->WriteKernel(Z_INIT_SELF_PROC, diff --git a/zion/object/address_space.cpp b/zion/object/address_space.cpp index 0faa89f..e0e6f40 100644 --- a/zion/object/address_space.cpp +++ b/zion/object/address_space.cpp @@ -8,10 +8,10 @@ extern KernelStackManager* gKernelStackManager; -RefPtr AddressSpace::ForRoot() { +glcr::RefPtr AddressSpace::ForRoot() { uint64_t cr3 = 0; asm volatile("mov %%cr3, %0;" : "=r"(cr3)); - return MakeRefCounted(cr3); + return glcr::MakeRefCounted(cr3); } AddressSpace::AddressSpace() { @@ -36,12 +36,13 @@ uint64_t AddressSpace::GetNextMemMapAddr(uint64_t size) { return addr; } -void AddressSpace::MapInMemoryObject(uint64_t vaddr, - const RefPtr& mem_obj) { +void AddressSpace::MapInMemoryObject( + uint64_t vaddr, const glcr::RefPtr& mem_obj) { memory_mappings_.PushBack({.vaddr = vaddr, .mem_obj = mem_obj}); } -uint64_t AddressSpace::MapInMemoryObject(const RefPtr& mem_obj) { +uint64_t AddressSpace::MapInMemoryObject( + const glcr::RefPtr& mem_obj) { uint64_t vaddr = GetNextMemMapAddr(mem_obj->size()); memory_mappings_.PushBack({.vaddr = vaddr, .mem_obj = mem_obj}); return vaddr; diff --git a/zion/object/address_space.h b/zion/object/address_space.h index 5513377..0a6e9c6 100644 --- a/zion/object/address_space.h +++ b/zion/object/address_space.h @@ -1,8 +1,8 @@ #pragma once +#include #include -#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 ForRoot(); + static glcr::RefPtr 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& mem_obj); + void MapInMemoryObject(uint64_t vaddr, + const glcr::RefPtr& mem_obj); - uint64_t MapInMemoryObject(const RefPtr& mem_obj); + uint64_t MapInMemoryObject(const glcr::RefPtr& mem_obj); // Kernel Mappings. uint64_t* AllocateKernelStack(); @@ -74,7 +75,7 @@ class AddressSpace : public KernelObject { bool HandlePageFault(uint64_t vaddr); private: - friend class MakeRefCountedFriend; + friend class glcr::MakeRefCountedFriend; AddressSpace(uint64_t cr3) : cr3_(cr3) {} uint64_t cr3_ = 0; @@ -83,7 +84,7 @@ class AddressSpace : public KernelObject { struct MemoryMapping { uint64_t vaddr; - RefPtr mem_obj; + glcr::RefPtr mem_obj; }; LinkedList memory_mappings_; diff --git a/zion/object/channel.cpp b/zion/object/channel.cpp index 5ec1670..ece6662 100644 --- a/zion/object/channel.cpp +++ b/zion/object/channel.cpp @@ -3,9 +3,10 @@ #include "include/ztypes.h" #include "scheduler/scheduler.h" -Pair, RefPtr> Channel::CreateChannelPair() { - auto c1 = MakeRefCounted(); - auto c2 = MakeRefCounted(); +Pair, glcr::RefPtr> +Channel::CreateChannelPair() { + auto c1 = glcr::MakeRefCounted(); + auto c2 = glcr::MakeRefCounted(); c1->SetPeer(c2); c2->SetPeer(c1); return {c1, c2}; diff --git a/zion/object/channel.h b/zion/object/channel.h index c2c573c..404b773 100644 --- a/zion/object/channel.h +++ b/zion/object/channel.h @@ -1,12 +1,13 @@ #pragma once +#include + #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 { class Channel : public KernelObject { public: uint64_t TypeTag() override { return KernelObject::CHANNEL; } - static Pair, RefPtr> CreateChannelPair(); + static Pair, glcr::RefPtr> CreateChannelPair(); - RefPtr peer() { return peer_; } + glcr::RefPtr 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 peer_{nullptr}; + glcr::RefPtr peer_{nullptr}; Mutex mutex_{"channel"}; UnboundedMessageQueue message_queue_; - LinkedList> blocked_threads_; + LinkedList> blocked_threads_; - friend class MakeRefCountedFriend; + friend class glcr::MakeRefCountedFriend; Channel() {} - void SetPeer(const RefPtr& peer) { peer_ = peer; } + void SetPeer(const glcr::RefPtr& peer) { peer_ = peer; } z_err_t WriteInternal(uint64_t num_bytes, const void* bytes, uint64_t num_caps, const z_cap_t* caps); diff --git a/zion/object/port.cpp b/zion/object/port.cpp index 22e8b8f..b054b62 100644 --- a/zion/object/port.cpp +++ b/zion/object/port.cpp @@ -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 cap) { +void Port::WriteKernel(uint64_t init, glcr::RefPtr cap) { MutexHolder h(mutex_); message_queue_.WriteKernel(init, cap); } diff --git a/zion/object/port.h b/zion/object/port.h index 15222b3..39d8b16 100644 --- a/zion/object/port.h +++ b/zion/object/port.h @@ -1,5 +1,7 @@ #pragma once +#include + #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 cap); + void WriteKernel(uint64_t init, glcr::RefPtr cap); bool HasMessages(); private: UnboundedMessageQueue message_queue_; - LinkedList> blocked_threads_; + LinkedList> blocked_threads_; Mutex mutex_{"Port"}; }; diff --git a/zion/object/process.cpp b/zion/object/process.cpp index b96997b..456f3a6 100644 --- a/zion/object/process.cpp +++ b/zion/object/process.cpp @@ -13,26 +13,31 @@ static uint64_t gNextId = 1; } -RefPtr Process::RootProcess() { - RefPtr proc = MakeRefCounted(0); +glcr::RefPtr Process::RootProcess() { + glcr::RefPtr proc = glcr::MakeRefCounted(0); proc->threads_.PushBack(Thread::RootThread(*proc)); proc->next_thread_id_ = 1; return proc; } -RefPtr Process::Create() { return MakeRefCounted(); } +glcr::RefPtr Process::Create() { + return glcr::MakeRefCounted(); +} Process::Process() - : id_(gNextId++), vmas_(MakeRefCounted()), state_(RUNNING) {} + : id_(gNextId++), + vmas_(glcr::MakeRefCounted()), + state_(RUNNING) {} -RefPtr Process::CreateThread() { +glcr::RefPtr Process::CreateThread() { MutexHolder lock(mutex_); - RefPtr thread = MakeRefCounted(*this, next_thread_id_++); + glcr::RefPtr thread = + glcr::MakeRefCounted(*this, next_thread_id_++); threads_.PushBack(thread); return thread; } -RefPtr Process::GetThread(uint64_t tid) { +glcr::RefPtr 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 Process::ReleaseCapability(uint64_t cid) { +glcr::RefPtr Process::ReleaseCapability(uint64_t cid) { return caps_.ReleaseCapability(cid); } -RefPtr Process::GetCapability(uint64_t cid) { +glcr::RefPtr Process::GetCapability(uint64_t cid) { return caps_.GetCapability(cid); } -uint64_t Process::AddExistingCapability(const RefPtr& cap) { +uint64_t Process::AddExistingCapability(const glcr::RefPtr& cap) { return caps_.AddExistingCapability(cap); } diff --git a/zion/object/process.h b/zion/object/process.h index 2eac7e9..0e86e15 100644 --- a/zion/object/process.h +++ b/zion/object/process.h @@ -1,12 +1,12 @@ #pragma once +#include #include #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 RootProcess(); - static RefPtr Create(); + static glcr::RefPtr RootProcess(); + static glcr::RefPtr Create(); uint64_t id() const { return id_; } - RefPtr vmas() { return vmas_; } + glcr::RefPtr vmas() { return vmas_; } - RefPtr CreateThread(); - RefPtr GetThread(uint64_t tid); + glcr::RefPtr CreateThread(); + glcr::RefPtr GetThread(uint64_t tid); - RefPtr ReleaseCapability(uint64_t cid); - RefPtr GetCapability(uint64_t cid); + glcr::RefPtr ReleaseCapability(uint64_t cid); + glcr::RefPtr GetCapability(uint64_t cid); template - uint64_t AddNewCapability(const RefPtr& obj, uint64_t permissions) { + uint64_t AddNewCapability(const glcr::RefPtr& obj, uint64_t permissions) { return caps_.AddNewCapability(obj, permissions); } - uint64_t AddExistingCapability(const RefPtr& cap); + uint64_t AddExistingCapability(const glcr::RefPtr& 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; + friend class glcr::MakeRefCountedFriend; Process(); Process(uint64_t id) : id_(id), vmas_(AddressSpace::ForRoot()) {} Mutex mutex_{"Process"}; uint64_t id_; - RefPtr vmas_; + glcr::RefPtr vmas_; State state_; uint64_t next_thread_id_ = 0; uint64_t next_cap_id_ = 0x100; - LinkedList> threads_; + LinkedList> threads_; CapabilityTable caps_; }; diff --git a/zion/object/thread.cpp b/zion/object/thread.cpp index 6930374..c90e950 100644 --- a/zion/object/thread.cpp +++ b/zion/object/thread.cpp @@ -21,12 +21,12 @@ extern "C" void thread_init() { } // namespace -RefPtr Thread::RootThread(Process& root_proc) { - return MakeRefCounted(root_proc); +glcr::RefPtr Thread::RootThread(Process& root_proc) { + return glcr::MakeRefCounted(root_proc); } -RefPtr Thread::Create(Process& proc, uint64_t tid) { - return MakeRefCounted(proc, tid); +glcr::RefPtr Thread::Create(Process& proc, uint64_t tid) { + return glcr::MakeRefCounted(proc, tid); } Thread::Thread(Process& proc, uint64_t tid) : process_(proc), id_(tid) { diff --git a/zion/object/thread.h b/zion/object/thread.h index 0353636..a47147f 100644 --- a/zion/object/thread.h +++ b/zion/object/thread.h @@ -1,8 +1,8 @@ #pragma once +#include #include -#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 RootThread(Process& root_proc); - static RefPtr Create(Process& proc, uint64_t tid); + static glcr::RefPtr RootThread(Process& root_proc); + static glcr::RefPtr 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; + friend class glcr::MakeRefCountedFriend; Thread(Process& proc, uint64_t tid); // Special constructor for the root thread only. Thread(Process& proc) : process_(proc), id_(0) {} diff --git a/zion/scheduler/process_manager.cpp b/zion/scheduler/process_manager.cpp index 586171b..d4318d2 100644 --- a/zion/scheduler/process_manager.cpp +++ b/zion/scheduler/process_manager.cpp @@ -7,7 +7,7 @@ void ProcessManager::Init() { gProcMan->InsertProcess(Process::RootProcess()); } -void ProcessManager::InsertProcess(const RefPtr& proc) { +void ProcessManager::InsertProcess(const glcr::RefPtr& proc) { proc_list_.PushBack(proc); } diff --git a/zion/scheduler/process_manager.h b/zion/scheduler/process_manager.h index 1f233df..88497e4 100644 --- a/zion/scheduler/process_manager.h +++ b/zion/scheduler/process_manager.h @@ -1,7 +1,8 @@ #pragma once +#include + #include "lib/linked_list.h" -#include "lib/ref_ptr.h" #include "object/process.h" class ProcessManager { @@ -10,14 +11,14 @@ class ProcessManager { // and stores it in the global variable. static void Init(); - void InsertProcess(const RefPtr& proc); + void InsertProcess(const glcr::RefPtr& proc); Process& FromId(uint64_t id); void DumpProcessStates(); private: // TODO: This should be a hashmap. - LinkedList> proc_list_; + LinkedList> proc_list_; }; extern ProcessManager* gProcMan; diff --git a/zion/scheduler/scheduler.cpp b/zion/scheduler/scheduler.cpp index cec378c..214b00f 100644 --- a/zion/scheduler/scheduler.cpp +++ b/zion/scheduler/scheduler.cpp @@ -59,7 +59,7 @@ void Scheduler::Preempt() { return; } - RefPtr prev = current_thread_; + glcr::RefPtr prev = current_thread_; prev->SetState(Thread::RUNNABLE); current_thread_ = runnable_threads_.CycleFront(prev); @@ -73,7 +73,7 @@ void Scheduler::Yield() { } asm volatile("cli"); - RefPtr prev = current_thread_; + glcr::RefPtr prev = current_thread_; if (prev == sleep_thread_) { if (runnable_threads_.size() == 0) { panic("Sleep thread yielded without next."); diff --git a/zion/scheduler/scheduler.h b/zion/scheduler/scheduler.h index c522480..fc29f4c 100644 --- a/zion/scheduler/scheduler.h +++ b/zion/scheduler/scheduler.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "object/process.h" #include "object/thread.h" @@ -13,9 +15,9 @@ class Scheduler { void Enable() { enabled_ = true; } Process& CurrentProcess() { return current_thread_->process(); } - RefPtr CurrentThread() { return current_thread_; } + glcr::RefPtr CurrentThread() { return current_thread_; } - void Enqueue(const RefPtr& thread) { + void Enqueue(const glcr::RefPtr& thread) { runnable_threads_.PushBack(thread); } @@ -25,10 +27,10 @@ class Scheduler { private: bool enabled_ = false; - RefPtr current_thread_; - LinkedList> runnable_threads_; + glcr::RefPtr current_thread_; + LinkedList> runnable_threads_; - RefPtr sleep_thread_; + glcr::RefPtr sleep_thread_; Scheduler(); void SwapToCurrent(Thread& prev); diff --git a/zion/syscall/memory_object.cpp b/zion/syscall/memory_object.cpp index 9f6a734..fb83409 100644 --- a/zion/syscall/memory_object.cpp +++ b/zion/syscall/memory_object.cpp @@ -7,14 +7,14 @@ z_err_t MemoryObjectCreate(ZMemoryObjectCreateReq* req) { auto& curr_proc = gScheduler->CurrentProcess(); *req->vmmo_cap = curr_proc.AddNewCapability( - MakeRefCounted(req->size), ZC_WRITE); + glcr::MakeRefCounted(req->size), ZC_WRITE); return Z_OK; } z_err_t MemoryObjectCreatePhysical(ZMemoryObjectCreatePhysicalReq* req) { auto& curr_proc = gScheduler->CurrentProcess(); uint64_t paddr = req->paddr; - auto vmmo_ref = MakeRefCounted(paddr, req->size); + auto vmmo_ref = glcr::MakeRefCounted(paddr, req->size); *req->vmmo_cap = curr_proc.AddNewCapability( StaticCastRefPtr(vmmo_ref), ZC_WRITE); return Z_OK; @@ -23,7 +23,7 @@ z_err_t MemoryObjectCreatePhysical(ZMemoryObjectCreatePhysicalReq* req) { z_err_t MemoryObjectCreateContiguous(ZMemoryObjectCreateContiguousReq* req) { auto& curr_proc = gScheduler->CurrentProcess(); uint64_t paddr = phys_mem::AllocateContinuous(((req->size - 1) / 0x1000) + 1); - auto vmmo_ref = MakeRefCounted(paddr, req->size); + auto vmmo_ref = glcr::MakeRefCounted(paddr, req->size); *req->vmmo_cap = curr_proc.AddNewCapability( StaticCastRefPtr(vmmo_ref), ZC_WRITE); *req->paddr = paddr; @@ -34,7 +34,7 @@ z_err_t TempPcieConfigObjectCreate(ZTempPcieConfigObjectCreateReq* req) { auto& curr_proc = gScheduler->CurrentProcess(); uint64_t pci_base, pci_size; RET_ERR(GetPciExtendedConfiguration(&pci_base, &pci_size)); - auto vmmo_ref = MakeRefCounted(pci_base, pci_size); + auto vmmo_ref = glcr::MakeRefCounted(pci_base, pci_size); *req->vmmo_cap = curr_proc.AddNewCapability( StaticCastRefPtr(vmmo_ref), ZC_WRITE); *req->vmmo_size = pci_size; diff --git a/zion/syscall/port.cpp b/zion/syscall/port.cpp index 2d60512..b3e0648 100644 --- a/zion/syscall/port.cpp +++ b/zion/syscall/port.cpp @@ -6,7 +6,7 @@ z_err_t PortCreate(ZPortCreateReq* req) { auto& proc = gScheduler->CurrentProcess(); - auto port = MakeRefCounted(); + auto port = glcr::MakeRefCounted(); *req->port_cap = proc.AddNewCapability(port, ZC_WRITE | ZC_READ); return Z_OK; } @@ -55,7 +55,7 @@ z_err_t IrqRegister(ZIrqRegisterReq* req) { // FIXME: Don't hardcode this nonsense. return Z_ERR_UNIMPLEMENTED; } - RefPtr port = MakeRefCounted(); + glcr::RefPtr port = glcr::MakeRefCounted(); *req->port_cap = proc.AddNewCapability(port, ZC_READ | ZC_WRITE); RegisterPciPort(port); return Z_OK; diff --git a/zion/syscall/process.cpp b/zion/syscall/process.cpp index 5a87fcb..77d04d2 100644 --- a/zion/syscall/process.cpp +++ b/zion/syscall/process.cpp @@ -18,7 +18,7 @@ z_err_t ProcessSpawn(ZProcessSpawnReq* req) { auto cap = curr_proc.GetCapability(req->proc_cap); RET_ERR(ValidateCapability(cap, ZC_PROC_SPAWN_PROC)); - RefPtr proc = Process::Create(); + glcr::RefPtr proc = Process::Create(); gProcMan->InsertProcess(proc); *req->new_proc_cap = curr_proc.AddNewCapability(