thread.hpp 1.7 KB

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