thread.hpp 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #pragma once
  2. #include <cstddef>
  3. #include <stdint.h>
  4. #include <sys/types.h>
  5. #include <types/string.hpp>
  6. #include <types/types.h>
  7. #include <kernel/signal.hpp>
  8. #include <kernel/user/thread_local.hpp>
  9. namespace kernel::task {
  10. using tid_t = uint32_t;
  11. struct thread {
  12. public:
  13. using thd_attr_t = uint32_t;
  14. static constexpr thd_attr_t SYSTEM = 0x01;
  15. static constexpr thd_attr_t READY = 0x02;
  16. static constexpr thd_attr_t STOPPED = 0x04;
  17. static constexpr thd_attr_t ZOMBIE = 0x08;
  18. static constexpr thd_attr_t ISLEEP = 0x10;
  19. static constexpr thd_attr_t USLEEP = 0x20;
  20. private:
  21. struct kernel_stack {
  22. std::byte* stack_base;
  23. uint32_t* esp;
  24. kernel_stack();
  25. kernel_stack(const kernel_stack& other);
  26. kernel_stack(kernel_stack&& other);
  27. ~kernel_stack();
  28. };
  29. public:
  30. kernel_stack kstack;
  31. pid_t owner;
  32. thd_attr_t attr;
  33. signal_list signals;
  34. int* __user set_child_tid {};
  35. int* __user clear_child_tid {};
  36. types::string<> name {};
  37. segment_descriptor tls_desc {};
  38. explicit thread(types::string<> name, pid_t owner);
  39. thread(const thread& val, pid_t owner);
  40. int set_thread_area(user::user_desc* ptr);
  41. int load_thread_area() const;
  42. void set_attr(thd_attr_t new_attr);
  43. void send_signal(signal_list::signo_type signal);
  44. thread(thread&& val) = default;
  45. tid_t tid() const;
  46. bool operator<(const thread& rhs) const;
  47. bool operator==(const thread& rhs) const;
  48. };
  49. } // namespace kernel::task