428
|
1 /* Includes for memory limit warnings.
|
|
2 Copyright (C) 1990, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 /* Synched up with: FSF 19.30. */
|
|
22
|
|
23 /* #### This ancient code really sucks.
|
|
24 configure should check for:
|
|
25 HAVE_SYS_RESOURCE_H, HAVE_ULIMIT_H, HAVE_GETRLIMIT, HAVE_ULIMIT,
|
|
26 and select action based on those values.
|
|
27 getrlimit() should be preferred to ulimit().
|
|
28 On Linux, ulimit() is deprecated and always returns -1. */
|
|
29
|
440
|
30 #ifndef INCLUDED_mem_limits_h_
|
|
31 #define INCLUDED_mem_limits_h_
|
428
|
32
|
|
33 #ifdef HAVE_CONFIG_H
|
|
34 #include <config.h>
|
|
35 #endif
|
|
36
|
|
37 #ifdef HAVE_ULIMIT_H
|
|
38 #include <ulimit.h>
|
|
39 #endif
|
|
40
|
|
41 /* Some systems need this before <sys/resource.h>. */
|
|
42 #include <sys/types.h>
|
|
43
|
|
44 #ifdef _LIBC
|
|
45
|
|
46 #include <sys/resource.h>
|
|
47 #define BSD4_2 /* Tell code below to use getrlimit. */
|
|
48
|
|
49 /* Old Linux startup code won't define __data_start. */
|
|
50 extern int etext, __data_start; weak_symbol (__data_start)
|
|
51 #define start_of_data() (&__data_start ?: &etext)
|
|
52
|
|
53 #else /* not GNU libc */
|
|
54
|
|
55 #if defined (__osf__) && (defined (__mips) || defined (mips) || defined (__alpha))
|
|
56 #include <sys/time.h>
|
|
57 #include <sys/resource.h>
|
|
58 #endif
|
|
59
|
|
60 #if defined(__bsdi__) || defined(__NetBSD__) || defined(__linux__) || defined(__OpenBSD__)
|
|
61 #define BSD4_2
|
|
62 #endif
|
|
63
|
|
64 #ifndef BSD4_2
|
|
65 #ifndef USG
|
442
|
66 #ifndef WIN32_NATIVE
|
|
67 #ifndef CYGWIN
|
428
|
68 #include <sys/vlimit.h>
|
442
|
69 #endif /* not CYGWIN */
|
|
70 #endif /* not WIN32_NATIVE */
|
428
|
71 #endif /* not USG */
|
|
72 #else /* if BSD4_2 */
|
|
73 #include <sys/time.h>
|
|
74 #include <sys/resource.h>
|
|
75 #endif /* BSD4_2 */
|
|
76
|
|
77 #ifdef emacs
|
|
78 typedef void *POINTER;
|
|
79
|
442
|
80 #ifndef CYGWIN
|
428
|
81 typedef unsigned long SIZE;
|
|
82 #endif
|
|
83
|
|
84 extern POINTER start_of_data (void);
|
|
85 #define EXCEEDS_LISP_PTR(ptr) 0
|
|
86
|
|
87 #ifdef BSD
|
|
88 extern int etext;
|
|
89 #define start_of_data() &etext
|
|
90 #endif
|
|
91
|
|
92 #else /* not emacs */
|
|
93 extern char etext;
|
|
94 #define start_of_data() &etext
|
|
95 #endif /* not emacs */
|
|
96
|
|
97 #endif /* not _LIBC */
|
|
98
|
|
99
|
|
100
|
|
101 /* start of data space; can be changed by calling malloc_init */
|
|
102 static POINTER data_space_start;
|
|
103
|
|
104 /* Number of bytes of writable memory we can expect to be able to get */
|
2132
|
105 extern unsigned long lim_data;
|
428
|
106
|
442
|
107 #if defined (HEAP_IN_DATA) && !defined(PDUMP)
|
428
|
108 extern unsigned long static_heap_size;
|
1632
|
109 extern MODULE_API int initialized;
|
428
|
110 static void
|
|
111 get_lim_data (void)
|
|
112 {
|
|
113 if (!initialized)
|
|
114 {
|
2132
|
115 lim_data = (unsigned long) -1; /* static_heap_size; */
|
428
|
116 }
|
|
117 else
|
|
118 {
|
2132
|
119 lim_data = (unsigned long) -1;
|
428
|
120 }
|
|
121 }
|
|
122 #else
|
|
123 #ifdef NO_LIM_DATA
|
|
124 static void
|
|
125 get_lim_data (void)
|
|
126 {
|
2132
|
127 lim_data = (unsigned long) -1;
|
428
|
128 }
|
|
129 #else /* not NO_LIM_DATA */
|
|
130
|
2132
|
131 #if defined(USG) && !defined(LINUX)
|
428
|
132
|
|
133 static void
|
|
134 get_lim_data (void)
|
|
135 {
|
2132
|
136 lim_data = (unsigned long) -1;
|
428
|
137
|
|
138 /* Use the ulimit call, if we seem to have it. */
|
2132
|
139 #if !defined (ULIMIT_BREAK_VALUE)
|
428
|
140 lim_data = ulimit (3, 0);
|
|
141 #endif
|
|
142
|
|
143 /* If that didn't work, just use the macro's value. */
|
|
144 #ifdef ULIMIT_BREAK_VALUE
|
2132
|
145 if (lim_data == (unsigned long) -1)
|
428
|
146 lim_data = ULIMIT_BREAK_VALUE;
|
|
147 #endif
|
|
148
|
|
149 lim_data -= (long) data_space_start;
|
|
150 }
|
|
151
|
|
152 #else /* not USG */
|
442
|
153 #if defined( WIN32_NATIVE )
|
428
|
154
|
|
155 static void
|
|
156 get_lim_data (void)
|
|
157 {
|
|
158 extern unsigned long data_region_size;
|
|
159 lim_data = data_region_size;
|
|
160 }
|
|
161
|
|
162 #else
|
2132
|
163 #if !defined (BSD4_2) && !defined (__osf__) && !defined(LINUX)
|
428
|
164
|
|
165 static void
|
|
166 get_lim_data (void)
|
|
167 {
|
|
168 lim_data = vlimit (LIM_DATA, -1);
|
|
169 }
|
|
170
|
|
171 #else /* BSD4_2 */
|
|
172
|
|
173 static void
|
|
174 get_lim_data (void)
|
|
175 {
|
|
176 struct rlimit XXrlimit;
|
|
177
|
|
178 getrlimit (RLIMIT_DATA, &XXrlimit);
|
|
179 #ifdef RLIM_INFINITY
|
|
180 lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
|
|
181 #else
|
|
182 lim_data = XXrlimit.rlim_cur; /* soft limit */
|
|
183 #endif
|
|
184 }
|
|
185 #endif /* BSD4_2 */
|
442
|
186 #endif /* not WIN32_NATIVE */
|
428
|
187 #endif /* not USG */
|
|
188 #endif /* not NO_LIM_DATA */
|
|
189 #endif /* not HEAP_IN_DATA */
|
|
190
|
440
|
191 #endif /* INCLUDED_mem_limits_h_ */
|