Updated Russian translation for the bfd directory
[binutils-gdb.git] / gdbsupport / alt-stack.h
blob142479338f0586077bd9194f8c3763fd419186a7
1 /* Temporarily install an alternate signal stack
3 Copyright (C) 2019-2023 Free Software Foundation, Inc.
5 This file is part of GDB.
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.
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.
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/>. */
20 #ifndef GDBSUPPORT_ALT_STACK_H
21 #define GDBSUPPORT_ALT_STACK_H
23 #include <signal.h>
25 namespace gdb
28 /* Try to set up an alternate signal stack for SIGSEGV handlers.
29 This allows us to handle SIGSEGV signals generated when the
30 normal process stack is exhausted. If this stack is not set
31 up (sigaltstack is unavailable or fails) and a SIGSEGV is
32 generated when the normal stack is exhausted then the program
33 will behave as though no SIGSEGV handler was installed. */
34 class alternate_signal_stack
36 public:
37 alternate_signal_stack ()
39 #ifdef HAVE_SIGALTSTACK
40 m_stack.reset ((char *) xmalloc (SIGSTKSZ));
42 stack_t stack;
43 stack.ss_sp = m_stack.get ();
44 stack.ss_size = SIGSTKSZ;
45 stack.ss_flags = 0;
47 sigaltstack (&stack, &m_old_stack);
48 #endif
51 ~alternate_signal_stack ()
53 #ifdef HAVE_SIGALTSTACK
54 sigaltstack (&m_old_stack, nullptr);
55 #endif
58 DISABLE_COPY_AND_ASSIGN (alternate_signal_stack);
60 private:
62 #ifdef HAVE_SIGALTSTACK
63 gdb::unique_xmalloc_ptr<char> m_stack;
64 stack_t m_old_stack;
65 #endif
70 #endif /* GDBSUPPORT_ALT_STACK_H */