#pragma once #include #if defined(__x86_64__) #include #elif defined(__aarch64__) #include #endif #include #include #include #define PROCESS_NONE 1 #define PROCESS_LIVE 2 #define PROCESS_KILLED 3 #define PROCESS_ZOMBIE 4 #define PROCESS_SLEEP 5 struct signal_member { void* restorer; void* handler; std::uint32_t flags; }; struct thread { std::uint32_t id; std::uint32_t pid; std::uint32_t exit_code; #if defined(__x86_64__) std::uint8_t* sse_ctx; std::uint64_t fs_base; x86_64::idt::int_frame_t ctx; #elif defined(__aarch64__) aarch64::el::int_frame ctx; #endif signal_manager* sig; signal_member signals_handlers[32]; sig_stack signal_stack; locks::spinlock lock; std::atomic futex; std::atomic status; std::atomic cpu; std::uint64_t syscall_stack; std::uint64_t original_root; char* name; char* cwd; char* chroot; thread* next; }; static_assert(sizeof(thread) < 4096, "thread struct is bigger than page size (bug)"); namespace process { thread* create_process(bool is_user); thread* by_id(std::uint32_t id); thread* kthread(void (*func)(void*), void* arg); void wakeup(thread* thread); void kill(thread* thread); extern "C" void schedule(void* frame); extern "C" void switch_ctx(void* frame); extern "C" void yield(); };