exp2l: Work around a NetBSD 10.0/i386 bug.
[gnulib.git] / lib / c-stack.h
blob4db4519343b70c1909194ab81e103a09e18e0658
1 /* Stack overflow handling.
3 Copyright (C) 2002, 2004, 2008-2024 Free Software Foundation, Inc.
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 /* This file uses _GL_ASYNC_SAFE. */
19 #if !_GL_CONFIG_H_INCLUDED
20 #error "Please include config.h first."
21 #endif
23 #ifdef __cplusplus
24 extern "C"
26 #endif
28 /* Set up ACTION so that it is invoked on C stack overflow and on other,
29 stack-unrelated, segmentation violation.
30 Return -1 (setting errno) if this cannot be done.
32 When a stack overflow or segmentation violation occurs:
33 1) ACTION is called. It is passed an argument equal to
34 - 0, for a stack overflow,
35 - SIGSEGV, for a segmentation violation that does not appear related
36 to stack overflow.
37 On many platforms the two cases are hard to distinguish; when in doubt,
38 zero is passed.
39 2) If ACTION returns, a message is written to standard error, and the
40 program is terminated: in the case of stack overflow, with exit code
41 exit_failure (see "exitfail.h"), otherwise through a signal SIGSEGV.
43 A null ACTION acts like an action that does nothing.
45 Restrictions:
46 - ACTION must be async-signal-safe.
47 - ACTION together with its callees must not require more than 64 KiB of
48 stack space.
49 - ACTION must not create and then invoke nested functions
50 <https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html>, because
51 this implementation does not guarantee an executable stack.
52 - ACTION should not call longjmp, because this implementation does not
53 guarantee that it is safe to return to the original stack.
55 This function may install a handler for the SIGSEGV signal or for the SIGBUS
56 signal or exercise other system dependent exception handling APIs. */
58 extern int c_stack_action (_GL_ASYNC_SAFE void (* /*action*/) (int));
60 #ifdef __cplusplus
62 #endif