signal.hpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #pragma once
  2. #include <map>
  3. #include <list>
  4. #include <signal.h>
  5. #include <stdint.h>
  6. #include <types/types.h>
  7. #include <types/cplusplus.hpp>
  8. #include <kernel/interrupt.h>
  9. namespace kernel {
  10. using sigmask_type = uint64_t;
  11. struct sigaction {
  12. sighandler_t sa_handler;
  13. unsigned long sa_flags;
  14. sigrestorer_t sa_restorer;
  15. sigmask_type sa_mask;
  16. };
  17. class signal_list {
  18. public:
  19. using signo_type = uint32_t;
  20. using list_type = std::list<signo_type>;
  21. private:
  22. list_type m_list;
  23. sigmask_type m_mask { };
  24. std::map<signo_type, sigaction> m_handlers;
  25. public:
  26. static constexpr bool check_valid(signo_type sig)
  27. {
  28. return sig >= 1 && sig <= 64;
  29. }
  30. public:
  31. constexpr signal_list() = default;
  32. constexpr signal_list(const signal_list& val) = default;
  33. constexpr signal_list(signal_list&& val) = default;
  34. void on_exec();
  35. sigmask_type get_mask() const;
  36. void set_mask(sigmask_type mask);
  37. void mask(sigmask_type mask);
  38. void unmask(sigmask_type mask);
  39. void set_handler(signo_type signal, const sigaction& action);
  40. void get_handler(signo_type signal, sigaction& action) const;
  41. signo_type pending_signal();
  42. // return value: whether the thread should wake up
  43. bool raise(signo_type signal);
  44. void handle(interrupt_stack* context, mmx_registers* mmxregs);
  45. void after_signal(signo_type signal);
  46. };
  47. } // namespace kernel