2023-05-18 12:43:53 -07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
2023-05-29 15:08:02 -07:00
|
|
|
#include "lib/linked_list.h"
|
2023-05-29 15:50:38 -07:00
|
|
|
#include "lib/shared_ptr.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;
|
|
|
|
|
|
|
|
class Process {
|
|
|
|
public:
|
2023-05-29 13:51:00 -07:00
|
|
|
enum State {
|
|
|
|
UNSPECIFIED,
|
|
|
|
SETUP,
|
|
|
|
RUNNING,
|
|
|
|
FINISHED,
|
|
|
|
};
|
2023-05-29 15:50:38 -07:00
|
|
|
static SharedPtr<Process> RootProcess();
|
2023-05-30 01:27:47 -07:00
|
|
|
Process();
|
2023-05-18 12:43:53 -07:00
|
|
|
|
2023-05-29 15:50:38 -07:00
|
|
|
uint64_t id() const { return id_; }
|
|
|
|
uint64_t cr3() const { return cr3_; }
|
2023-05-18 12:43:53 -07:00
|
|
|
|
2023-05-30 01:27:47 -07:00
|
|
|
void CreateThread(uint64_t entry);
|
2023-05-29 15:50:38 -07:00
|
|
|
SharedPtr<Thread> GetThread(uint64_t tid);
|
2023-05-18 12:43:53 -07:00
|
|
|
|
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:
|
|
|
|
Process(uint64_t id, uint64_t cr3) : id_(id), cr3_(cr3) {}
|
|
|
|
uint64_t id_;
|
|
|
|
uint64_t cr3_;
|
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-29 15:50:38 -07:00
|
|
|
LinkedList<SharedPtr<Thread>> threads_;
|
2023-05-18 12:43:53 -07:00
|
|
|
};
|