block-signals.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* Block signals used by gdb
  2. Copyright (C) 2019-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #ifndef GDBSUPPORT_BLOCK_SIGNALS_H
  15. #define GDBSUPPORT_BLOCK_SIGNALS_H
  16. #include <signal.h>
  17. #include "gdbsupport/gdb-sigmask.h"
  18. namespace gdb
  19. {
  20. /* This is an RAII class that temporarily blocks the signals needed by
  21. gdb. This can be used before starting a new thread to ensure that
  22. this thread starts with the appropriate signals blocked. */
  23. class block_signals
  24. {
  25. public:
  26. block_signals ()
  27. {
  28. #ifdef HAVE_SIGPROCMASK
  29. sigset_t mask;
  30. sigemptyset (&mask);
  31. sigaddset (&mask, SIGINT);
  32. sigaddset (&mask, SIGCHLD);
  33. sigaddset (&mask, SIGALRM);
  34. sigaddset (&mask, SIGWINCH);
  35. gdb_sigmask (SIG_BLOCK, &mask, &m_old_mask);
  36. #endif
  37. }
  38. ~block_signals ()
  39. {
  40. #ifdef HAVE_SIGPROCMASK
  41. gdb_sigmask (SIG_SETMASK, &m_old_mask, nullptr);
  42. #endif
  43. }
  44. DISABLE_COPY_AND_ASSIGN (block_signals);
  45. private:
  46. #ifdef HAVE_SIGPROCMASK
  47. sigset_t m_old_mask;
  48. #endif
  49. };
  50. }
  51. #endif /* GDBSUPPORT_BLOCK_SIGNALS_H */