1*a45ae5f8SJohn Marino /* Increase stack size limit if possible. 2*a45ae5f8SJohn Marino Copyright (C) 2011 Free Software Foundation, Inc. 3*a45ae5f8SJohn Marino 4*a45ae5f8SJohn Marino This file is part of the libiberty library. This library is free 5*a45ae5f8SJohn Marino software; you can redistribute it and/or modify it under the 6*a45ae5f8SJohn Marino terms of the GNU General Public License as published by the 7*a45ae5f8SJohn Marino Free Software Foundation; either version 2, or (at your option) 8*a45ae5f8SJohn Marino any later version. 9*a45ae5f8SJohn Marino 10*a45ae5f8SJohn Marino This library is distributed in the hope that it will be useful, 11*a45ae5f8SJohn Marino but WITHOUT ANY WARRANTY; without even the implied warranty of 12*a45ae5f8SJohn Marino MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13*a45ae5f8SJohn Marino GNU General Public License for more details. 14*a45ae5f8SJohn Marino 15*a45ae5f8SJohn Marino You should have received a copy of the GNU General Public License 16*a45ae5f8SJohn Marino along with GNU CC; see the file COPYING. If not, write to 17*a45ae5f8SJohn Marino the Free Software Foundation, 51 Franklin Street - Fifth Floor, 18*a45ae5f8SJohn Marino Boston, MA 02110-1301, USA. 19*a45ae5f8SJohn Marino 20*a45ae5f8SJohn Marino As a special exception, if you link this library with files 21*a45ae5f8SJohn Marino compiled with a GNU compiler to produce an executable, this does not cause 22*a45ae5f8SJohn Marino the resulting executable to be covered by the GNU General Public License. 23*a45ae5f8SJohn Marino This exception does not however invalidate any other reasons why 24*a45ae5f8SJohn Marino the executable file might be covered by the GNU General Public License. */ 25*a45ae5f8SJohn Marino 26*a45ae5f8SJohn Marino /* 27*a45ae5f8SJohn Marino 28*a45ae5f8SJohn Marino @deftypefn Extension void stack_limit_increase (unsigned long @var{pref}) 29*a45ae5f8SJohn Marino 30*a45ae5f8SJohn Marino Attempt to increase stack size limit to @var{pref} bytes if possible. 31*a45ae5f8SJohn Marino 32*a45ae5f8SJohn Marino @end deftypefn 33*a45ae5f8SJohn Marino 34*a45ae5f8SJohn Marino */ 35*a45ae5f8SJohn Marino 36*a45ae5f8SJohn Marino #include "config.h" 37*a45ae5f8SJohn Marino 38*a45ae5f8SJohn Marino #ifdef HAVE_STDINT_H 39*a45ae5f8SJohn Marino #include <stdint.h> 40*a45ae5f8SJohn Marino #endif 41*a45ae5f8SJohn Marino #ifdef HAVE_SYS_RESOURCE_H 42*a45ae5f8SJohn Marino #include <sys/resource.h> 43*a45ae5f8SJohn Marino #endif 44*a45ae5f8SJohn Marino 45*a45ae5f8SJohn Marino void 46*a45ae5f8SJohn Marino stack_limit_increase (unsigned long pref) 47*a45ae5f8SJohn Marino { 48*a45ae5f8SJohn Marino #if defined(HAVE_SETRLIMIT) && defined(HAVE_GETRLIMIT) \ 49*a45ae5f8SJohn Marino && defined(RLIMIT_STACK) && defined(RLIM_INFINITY) 50*a45ae5f8SJohn Marino struct rlimit rlim; 51*a45ae5f8SJohn Marino if (getrlimit (RLIMIT_STACK, &rlim) == 0 52*a45ae5f8SJohn Marino && rlim.rlim_cur != RLIM_INFINITY 53*a45ae5f8SJohn Marino && rlim.rlim_cur < pref 54*a45ae5f8SJohn Marino && (rlim.rlim_max == RLIM_INFINITY || rlim.rlim_cur < rlim.rlim_max)) 55*a45ae5f8SJohn Marino { 56*a45ae5f8SJohn Marino rlim.rlim_cur = pref; 57*a45ae5f8SJohn Marino if (rlim.rlim_max != RLIM_INFINITY && rlim.rlim_cur > rlim.rlim_max) 58*a45ae5f8SJohn Marino rlim.rlim_cur = rlim.rlim_max; 59*a45ae5f8SJohn Marino setrlimit (RLIMIT_STACK, &rlim); 60*a45ae5f8SJohn Marino } 61*a45ae5f8SJohn Marino #endif 62*a45ae5f8SJohn Marino } 63