Max OS 0.3
Loading...
Searching...
No Matches
process.h
Go to the documentation of this file.
1
9#ifndef MAXOS_PROCESSES_PROCESS_H
10#define MAXOS_PROCESSES_PROCESS_H
11
12#include <system/cpu.h>
13#include <common/vector.h>
14#include <common/map.h>
15#include <common/string.h>
16#include <cstdint>
17#include <memory/virtual.h>
19#include <memory/memoryIO.h>
20#include <processes/elf.h>
21#include <processes/resource.h>
22
23namespace MaxOS::processes {
24 class Process;
25
33 typedef enum class ThreadState {
34 NEW,
35 RUNNING,
36 READY,
37 SLEEPING,
38 WAITING,
39 STOPPED
40 } thread_state_t;
41
43 constexpr size_t STACK_SIZE = 0x10000;
44
49 class Thread {
50
51 private:
52
53 uintptr_t m_stack_pointer;
54 uintptr_t m_tss_stack_pointer;
55
56 char m_sse_save_region[512] __attribute__((aligned(16)));
57
58 public:
59 Thread(void (* _entry_point)(void*), void* args, int arg_amount, Process* parent);
61
62 void sleep(size_t milliseconds);
63
64 uint64_t tid;
65 uint64_t parent_pid;
66
69
70 size_t ticks;
71 size_t wakeup_time;
72
73 [[nodiscard]] uintptr_t tss_pointer() const { return m_tss_stack_pointer; }
74
75 void save_sse_state();
76 void restore_sse_state();
77
78 void save_cpu_state();
79 };
80
85 class Process {
86
87 private:
89
90 uint64_t m_pid = 0;
91 common::Spinlock m_lock;
92
93 public:
94 explicit Process(const string& name, bool is_kernel = false);
95 Process(const string& name, void (* _entry_point)(void*), void* args, int arg_amount, bool is_kernel = false);
96 Process(const string& name, void* args, int arg_amount, ELF64* elf, bool is_kernel = false);
97 ~Process();
98
100 void add_thread(Thread* thread);
101 void remove_thread(uint64_t tid);
102
103 void set_pid(uint64_t pid);
104 [[nodiscard]] uint64_t pid() const;
105 [[nodiscard]] uint64_t total_ticks();
106
108
109 string name;
110 string working_directory = "/";
111
114 };
115}
116
117#endif // MAXOS_PROCESSES_PROCESS_H
Stores the left, top, width and height of a rectangle.
Definition rectangle.h:22
Enables a resource to be used by only one instance at a time through locking and unlocking.
Definition spinlock.h:21
Handles memory allocation and deallocation.
Handles the loading and parsing of 64-bit ELF files.
Definition elf.h:217
A process that can be scheduled by the Scheduler, wraps & manages threads as well as its own address ...
Definition process.h:85
uint64_t pid() const
Gets the pid of the process.
Definition process.cpp:326
uint64_t total_ticks()
Gets the total ticks of the threads in the process (not this does not include any past killed threads...
Definition process.cpp:336
string name
The name of the process.
Definition process.h:109
ResourceManager resource_manager
The manger for resources used by this process.
Definition process.h:113
common::Vector< Thread * > threads()
Gets the threads of the process.
Definition process.cpp:316
void add_thread(Thread *thread)
Adds a thread to the process.
Definition process.cpp:256
~Process()
Destructor for the Process class.
Definition process.cpp:235
string working_directory
The working directory of the process.
Definition process.h:110
bool is_kernel
Whether this process is a kernel process.
Definition process.h:107
void set_pid(uint64_t pid)
Sets the pid of the process once added to the queue.
Definition process.cpp:296
void remove_thread(uint64_t tid)
Remove a thread by its tid (NOTE: this will not remove it from the scheduler)
Definition process.cpp:272
memory::MemoryManager * memory_manager
The manager for memory used by this process.
Definition process.h:112
Manages the open resources for a process.
Definition resource.h:141
The execution context of a sub-process thread.
Definition process.h:49
thread_state_t thread_state
The current state of the thread.
Definition process.h:68
uint64_t parent_pid
The parent process ID.
Definition process.h:65
void save_sse_state()
Saves the SSE, x87 FPU, and MMX states from memory to the thread.
Definition process.cpp:92
uint64_t tid
The thread ID.
Definition process.h:64
size_t wakeup_time
The time at which the thread should wake up (if sleeping)
Definition process.h:71
~Thread()
Destructor for the Thread class.
void save_cpu_state()
Saves the CPU state into the thread's execution_state structure.
Definition process.cpp:118
system::cpu_status_t execution_state
The CPU state of the thread.
Definition process.h:67
uintptr_t tss_pointer() const
Gets the stack pointer to use for the TSS when switching to this thread.
Definition process.h:73
void restore_sse_state()
Restores the SSE, x87 FPU, and MMX states from the thread to memory.
Definition process.cpp:105
size_t ticks
The number of ticks the thread has run for.
Definition process.h:70
void sleep(size_t milliseconds)
Sleeps the thread for a certain amount of time.
Definition process.cpp:82
Defines Central Processing Unit (CPU) structures and functions for managing CPU state and features.
struct PACKED MaxOS::system::CPUStatus cpu_status_t
Alias for CPUStatus struct.
Defines structures and enums for handling ELF (Executable and Linkable Format) files in MaxOS.
Defines a Map class for storing key-value pairs.
Defines classes for memory input and output operations of various bit widths (8, 16,...
Defines a MemoryManager class for handling memory allocation and deallocation.
constexpr size_t STACK_SIZE
The size of the stack for each thread (4KB)
Definition process.h:43
ThreadState
The different operational states a thread can be in.
Definition process.h:33
enum MaxOS::processes::ThreadState thread_state_t
Alias for ThreadState enum.
Defines classes for managing process resources such as files and devices.
Defines a String class for dynamically sized strings with various operations.
Defines a Vector class for dynamically storing an array of elements.
Defines a VirtualMemoryManager class for managing virtual memory allocation and mapping to physical m...