thread.hpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. };
  32. public:
  33. kernel_stack kstack;
  34. pid_t owner;
  35. thd_attr_t attr;
  36. signal_list signals;
  37. int* __user set_child_tid {};
  38. int* __user clear_child_tid {};
  39. std::string name {};
  40. uint64_t tls_desc[2] {};
  41. explicit thread(std::string name, pid_t owner);
  42. thread(const thread& val, pid_t owner);
  43. int set_thread_area(user::user_desc* ptr);
  44. int load_thread_area() const;
  45. void set_attr(thd_attr_t new_attr);
  46. void send_signal(signal_list::signo_type signal);
  47. thread(thread&& val) = default;
  48. tid_t tid() const;
  49. bool operator<(const thread& rhs) const;
  50. bool operator==(const thread& rhs) const;
  51. };
  52. } // namespace kernel::task