2023-05-18 12:43:53 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2023-05-30 23:55:42 -07:00
|
|
|
#include "capability/capability.h"
|
2023-05-29 15:08:02 -07:00
|
|
|
#include "lib/linked_list.h"
|
2023-06-06 19:05:03 -07:00
|
|
|
#include "lib/ref_ptr.h"
|
2023-05-29 15:50:38 -07:00
|
|
|
#include "lib/shared_ptr.h"
|
2023-06-06 20:43:15 -07:00
|
|
|
#include "object/address_space.h"
|
2023-05-29 15:08:02 -07:00
|
|
|
|
2023-05-18 12:43:53 -07:00
|
|
|
// Forward decl due to cyclic dependency.
|
|
|
|
class Thread;
|
|
|
|
|
2023-06-06 20:13:07 -07:00
|
|
|
class Process : public KernelObject {
|
2023-05-18 12:43:53 -07:00
|
|
|
public:
|
2023-05-29 13:51:00 -07:00
|
|
|
enum State {
|
|
|
|
UNSPECIFIED,
|
|
|
|
SETUP,
|
|
|
|
RUNNING,
|
|
|
|
FINISHED,
|
|
|
|
};
|
2023-06-06 19:12:46 -07:00
|
|
|
static RefPtr<Process> RootProcess();
|
|
|
|
static RefPtr<Process> Create();
|
2023-05-18 12:43:53 -07:00
|
|
|
|
2023-05-29 15:50:38 -07:00
|
|
|
uint64_t id() const { return id_; }
|
2023-06-07 00:30:26 -07:00
|
|
|
RefPtr<AddressSpace> vmas() { return vmas_; }
|
2023-05-18 12:43:53 -07:00
|
|
|
|
2023-06-06 19:05:03 -07:00
|
|
|
RefPtr<Thread> CreateThread();
|
|
|
|
RefPtr<Thread> GetThread(uint64_t tid);
|
2023-05-18 12:43:53 -07:00
|
|
|
|
2023-05-30 23:55:42 -07:00
|
|
|
SharedPtr<Capability> GetCapability(uint64_t cid);
|
2023-06-06 20:13:07 -07:00
|
|
|
uint64_t AddCapability(const RefPtr<Thread>& t);
|
2023-06-07 00:04:53 -07:00
|
|
|
uint64_t AddCapability(const RefPtr<Process>& p);
|
2023-06-07 00:30:26 -07:00
|
|
|
uint64_t AddCapability(const RefPtr<AddressSpace>& vmas);
|
|
|
|
uint64_t AddCapability(const RefPtr<MemoryObject>& vmmo);
|
2023-06-07 00:19:15 -07:00
|
|
|
|
2023-06-07 00:30:26 -07:00
|
|
|
void AddCapability(uint64_t cap_id, const RefPtr<MemoryObject>& vmmo);
|
2023-05-29 13:51:00 -07:00
|
|
|
// Checks the state of all child threads and transitions to
|
|
|
|
// finished if all have finished.
|
|
|
|
void CheckState();
|
|
|
|
|
|
|
|
State GetState() { return state_; }
|
|
|
|
|
2023-05-18 12:43:53 -07:00
|
|
|
private:
|
2023-06-06 19:12:46 -07:00
|
|
|
friend class MakeRefCountedFriend<Process>;
|
|
|
|
Process();
|
2023-06-07 00:30:26 -07:00
|
|
|
Process(uint64_t id) : id_(id), vmas_(AddressSpace::ForRoot()) {}
|
2023-05-18 12:43:53 -07:00
|
|
|
uint64_t id_;
|
2023-06-07 00:30:26 -07:00
|
|
|
RefPtr<AddressSpace> vmas_;
|
2023-05-29 13:51:00 -07:00
|
|
|
State state_;
|
2023-05-18 12:43:53 -07:00
|
|
|
|
|
|
|
uint64_t next_thread_id_ = 0;
|
2023-05-30 23:55:42 -07:00
|
|
|
uint64_t next_cap_id_ = 0x100;
|
2023-05-18 12:43:53 -07:00
|
|
|
|
2023-06-06 19:05:03 -07:00
|
|
|
LinkedList<RefPtr<Thread>> threads_;
|
2023-05-30 23:55:42 -07:00
|
|
|
LinkedList<SharedPtr<Capability>> caps_;
|
2023-05-18 12:43:53 -07:00
|
|
|
};
|