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