process.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #pragma once
  2. #include <kernel/interrupt.h>
  3. #include <kernel/task.h>
  4. #include <types/types.h>
  5. #ifdef __cplusplus
  6. #include <kernel/mm.hpp>
  7. #include <types/list.hpp>
  8. typedef size_t pid_t;
  9. class process;
  10. struct thread;
  11. struct process_attr {
  12. uint16_t system : 1;
  13. };
  14. struct thread_attr {
  15. uint32_t system : 1;
  16. uint32_t ready : 1;
  17. uint32_t wait : 1;
  18. };
  19. struct thread {
  20. void* eip;
  21. process* owner;
  22. regs_32 regs;
  23. uint32_t eflags;
  24. uint32_t esp;
  25. thread_attr attr;
  26. };
  27. class process {
  28. public:
  29. mm_list mms;
  30. types::list<thread> thds;
  31. void* k_esp;
  32. process_attr attr;
  33. pid_t pid;
  34. public:
  35. process(process&& val);
  36. process(const process&) = delete;
  37. process(const process& proc, const thread& main_thread);
  38. process(void* start_eip, uint8_t* image, size_t image_size, bool system);
  39. };
  40. // in process.cpp
  41. extern process* current_process;
  42. extern thread* current_thread;
  43. extern "C" void NORETURN init_scheduler();
  44. void do_scheduling(interrupt_stack* intrpt_data);
  45. void thread_context_save(interrupt_stack* int_stack, thread* thd, bool kernel);
  46. void thread_context_load(interrupt_stack* int_stack, thread* thd, bool kernel);
  47. void process_context_save(interrupt_stack*, process*);
  48. void process_context_load(interrupt_stack*, process* proc);
  49. void add_to_process_list(process&& proc);
  50. void add_to_ready_list(thread* thd);
  51. #else
  52. void NORETURN init_scheduler();
  53. #endif