annotate libiberty/stack-limit.c @ 145:1830386684a0

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