1*09d4459fSDaniel Fojt /* Stack overflow handling. 2*09d4459fSDaniel Fojt 3*09d4459fSDaniel Fojt Copyright (C) 2002, 2004, 2008-2020 Free Software Foundation, Inc. 4*09d4459fSDaniel Fojt 5*09d4459fSDaniel Fojt This program is free software: you can redistribute it and/or modify 6*09d4459fSDaniel Fojt it under the terms of the GNU General Public License as published by 7*09d4459fSDaniel Fojt the Free Software Foundation; either version 3 of the License, or 8*09d4459fSDaniel Fojt (at your option) any later version. 9*09d4459fSDaniel Fojt 10*09d4459fSDaniel Fojt This program is distributed in the hope that it will be useful, 11*09d4459fSDaniel Fojt but WITHOUT ANY WARRANTY; without even the implied warranty of 12*09d4459fSDaniel Fojt MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*09d4459fSDaniel Fojt GNU General Public License for more details. 14*09d4459fSDaniel Fojt 15*09d4459fSDaniel Fojt You should have received a copy of the GNU General Public License 16*09d4459fSDaniel Fojt along with this program. If not, see <https://www.gnu.org/licenses/>. */ 17*09d4459fSDaniel Fojt 18*09d4459fSDaniel Fojt 19*09d4459fSDaniel Fojt /* Set up ACTION so that it is invoked on C stack overflow and on other, 20*09d4459fSDaniel Fojt stack-unrelated, segmentation violation. 21*09d4459fSDaniel Fojt Return -1 (setting errno) if this cannot be done. 22*09d4459fSDaniel Fojt 23*09d4459fSDaniel Fojt When a stack overflow or segmentation violation occurs: 24*09d4459fSDaniel Fojt 1) ACTION is called. It is passed an argument equal to 25*09d4459fSDaniel Fojt - 0, for a stack overflow, 26*09d4459fSDaniel Fojt - SIGSEGV, for a segmentation violation that does not appear related 27*09d4459fSDaniel Fojt to stack overflow. 28*09d4459fSDaniel Fojt On many platforms the two cases are hard to distinguish; when in doubt, 29*09d4459fSDaniel Fojt zero is passed. 30*09d4459fSDaniel Fojt 2) If ACTION returns, a message is written to standard error, and the 31*09d4459fSDaniel Fojt program is terminated: in the case of stack overflow, with exit code 32*09d4459fSDaniel Fojt exit_failure (see "exitfail.h"), otherwise through a signal SIGSEGV. 33*09d4459fSDaniel Fojt 34*09d4459fSDaniel Fojt A null ACTION acts like an action that does nothing. 35*09d4459fSDaniel Fojt 36*09d4459fSDaniel Fojt ACTION must be async-signal-safe. ACTION together with its callees 37*09d4459fSDaniel Fojt must not require more than SIGSTKSZ bytes of stack space. Also, 38*09d4459fSDaniel Fojt ACTION should not call longjmp, because this implementation does 39*09d4459fSDaniel Fojt not guarantee that it is safe to return to the original stack. 40*09d4459fSDaniel Fojt 41*09d4459fSDaniel Fojt This function may install a handler for the SIGSEGV signal or for the SIGBUS 42*09d4459fSDaniel Fojt signal or exercise other system dependent exception handling APIs. */ 43*09d4459fSDaniel Fojt 44*09d4459fSDaniel Fojt extern int c_stack_action (_GL_ASYNC_SAFE void (* /*action*/) (int)); 45