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