#pragma once #include #include "capability/capability.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" // Forward decl due to cyclic dependency. class Thread; class Process : public KernelObject { public: enum State { UNSPECIFIED, SETUP, RUNNING, FINISHED, }; static RefPtr RootProcess(); static RefPtr Create(); uint64_t id() const { return id_; } RefPtr vmas() { return vmas_; } RefPtr CreateThread(); RefPtr GetThread(uint64_t tid); RefPtr ReleaseCapability(uint64_t cid); RefPtr GetCapability(uint64_t cid); // FIXME: We can't reset the cap id here. uint64_t AddCapability(const RefPtr& cap); uint64_t AddCapability(const RefPtr& t); uint64_t AddCapability(const RefPtr& p); uint64_t AddCapability(const RefPtr& vmas); uint64_t AddCapability(const RefPtr& vmmo); uint64_t AddCapability(const RefPtr& chan); uint64_t AddCapability(const RefPtr& chan); void AddCapability(uint64_t cap_id, const RefPtr& vmmo); // Checks the state of all child threads and transitions to // finished if all have finished. void CheckState(); State GetState() { return state_; } private: friend class MakeRefCountedFriend; Process(); Process(uint64_t id) : id_(id), vmas_(AddressSpace::ForRoot()) {} Mutex mutex_{"Process"}; uint64_t id_; RefPtr vmas_; State state_; uint64_t next_thread_id_ = 0; uint64_t next_cap_id_ = 0x100; LinkedList> threads_; LinkedList> caps_; };