0
|
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
|
243
|
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
|
0
|
30 #ifndef _XEMACS_MEM_LIMITS_H_
|
|
31 #define _XEMACS_MEM_LIMITS_H_
|
|
32
|
169
|
33 #ifdef HAVE_CONFIG_H
|
|
34 #include <config.h>
|
|
35 #endif
|
|
36
|
|
37 #ifdef HAVE_ULIMIT_H
|
|
38 #include <ulimit.h>
|
|
39 #endif
|
|
40
|
0
|
41 #ifdef MSDOS
|
|
42 #include <dpmi.h>
|
|
43 #endif
|
|
44
|
|
45 /* Some systems need this before <sys/resource.h>. */
|
|
46 #include <sys/types.h>
|
|
47
|
|
48 #ifdef _LIBC
|
|
49
|
|
50 #include <sys/resource.h>
|
|
51 #define BSD4_2 /* Tell code below to use getrlimit. */
|
|
52
|
|
53 /* Old Linux startup code won't define __data_start. */
|
|
54 extern int etext, __data_start; weak_symbol (__data_start)
|
|
55 #define start_of_data() (&__data_start ?: &etext)
|
|
56
|
243
|
57 #else /* not GNU libc */
|
0
|
58
|
|
59 #if defined (__osf__) && (defined (__mips) || defined (mips) || defined (__alpha))
|
|
60 #include <sys/time.h>
|
|
61 #include <sys/resource.h>
|
|
62 #endif
|
|
63
|
286
|
64 #if defined(__bsdi__) || defined(__NetBSD__) || defined(__linux__) || defined(__OpenBSD__)
|
276
|
65 #if defined(__linux__) && defined (powerpc) /*Added by Fukui*/
|
|
66 #else /*Added by Fukui*/
|
0
|
67 #define BSD4_2
|
276
|
68 #endif /*Added by Fukui*/
|
0
|
69 #endif
|
|
70
|
|
71 #ifndef BSD4_2
|
|
72 #ifndef USG
|
|
73 #ifndef MSDOS
|
|
74 #ifndef WINDOWSNT
|
231
|
75 #ifndef __CYGWIN32__
|
276
|
76 #if defined(__linux__) && defined(powerpc) /*Added Kaoru Fukui*/
|
|
77 #else /*Added Kaoru Fukui*/
|
0
|
78 #include <sys/vlimit.h>
|
276
|
79 #endif /*Added by Fukui*/
|
231
|
80 #endif /* not __CYGWIN32__ */
|
0
|
81 #endif /* not WINDOWSNT */
|
|
82 #endif /* not MSDOS */
|
|
83 #endif /* not USG */
|
|
84 #else /* if BSD4_2 */
|
|
85 #include <sys/time.h>
|
|
86 #include <sys/resource.h>
|
|
87 #endif /* BSD4_2 */
|
|
88
|
|
89 #ifdef emacs
|
|
90 /* The important properties of this type are that 1) it's a pointer, and
|
|
91 2) arithmetic on it should work as if the size of the object pointed
|
|
92 to has a size of 1. */
|
|
93 #ifdef __STDC__
|
|
94 typedef void *POINTER;
|
|
95 #else
|
|
96 typedef char *POINTER;
|
|
97 #endif
|
|
98
|
231
|
99 #ifndef __CYGWIN32__
|
0
|
100 typedef unsigned long SIZE;
|
231
|
101 #endif
|
0
|
102
|
|
103 extern POINTER start_of_data ();
|
|
104 #ifdef DATA_SEG_BITS
|
|
105 #define EXCEEDS_LISP_PTR(ptr) \
|
|
106 (((EMACS_UINT) (ptr) & ~DATA_SEG_BITS) >> VALBITS)
|
|
107 #else
|
|
108 #define EXCEEDS_LISP_PTR(ptr) ((EMACS_UINT) (ptr) >> VALBITS)
|
|
109 #endif
|
|
110
|
|
111 #ifdef BSD
|
|
112 #ifndef DATA_SEG_BITS
|
|
113 extern int etext;
|
|
114 #define start_of_data() &etext
|
|
115 #endif
|
|
116 #endif
|
|
117
|
272
|
118 #else /* not emacs */
|
0
|
119 extern char etext;
|
|
120 #define start_of_data() &etext
|
|
121 #endif /* not emacs */
|
|
122
|
|
123 #endif /* not _LIBC */
|
|
124
|
272
|
125
|
0
|
126
|
|
127 /* start of data space; can be changed by calling malloc_init */
|
|
128 static POINTER data_space_start;
|
|
129
|
|
130 /* Number of bytes of writable memory we can expect to be able to get */
|
|
131 extern unsigned int lim_data;
|
|
132
|
251
|
133 #ifdef HEAP_IN_DATA
|
|
134 extern unsigned long static_heap_size;
|
|
135 extern int initialized;
|
|
136 static void
|
|
137 get_lim_data (void)
|
|
138 {
|
|
139 if (!initialized)
|
|
140 {
|
272
|
141 lim_data = (unsigned int) -1; /* static_heap_size; */
|
251
|
142 }
|
|
143 else
|
|
144 {
|
272
|
145 lim_data = (unsigned int) -1;
|
251
|
146 }
|
|
147 }
|
|
148 #else
|
0
|
149 #ifdef NO_LIM_DATA
|
|
150 static void
|
74
|
151 get_lim_data (void)
|
0
|
152 {
|
272
|
153 lim_data = (unsigned int) -1;
|
0
|
154 }
|
|
155 #else /* not NO_LIM_DATA */
|
|
156
|
|
157 #ifdef USG
|
|
158
|
|
159 static void
|
74
|
160 get_lim_data (void)
|
0
|
161 {
|
272
|
162 lim_data = (unsigned int) -1;
|
0
|
163
|
|
164 /* Use the ulimit call, if we seem to have it. */
|
|
165 #if !defined (ULIMIT_BREAK_VALUE) || defined (LINUX)
|
|
166 lim_data = ulimit (3, 0);
|
|
167 #endif
|
|
168
|
|
169 /* If that didn't work, just use the macro's value. */
|
|
170 #ifdef ULIMIT_BREAK_VALUE
|
272
|
171 if (lim_data == (unsigned int) -1)
|
0
|
172 lim_data = ULIMIT_BREAK_VALUE;
|
|
173 #endif
|
|
174
|
|
175 lim_data -= (long) data_space_start;
|
|
176 }
|
|
177
|
|
178 #else /* not USG */
|
251
|
179 #if defined( WINDOWSNT )
|
0
|
180
|
|
181 static void
|
74
|
182 get_lim_data (void)
|
0
|
183 {
|
|
184 extern unsigned long data_region_size;
|
|
185 lim_data = data_region_size;
|
|
186 }
|
|
187
|
|
188 #else
|
|
189 #if !defined (BSD4_2) && !defined (__osf__)
|
|
190
|
|
191 #ifdef MSDOS
|
|
192 void
|
74
|
193 get_lim_data (void)
|
0
|
194 {
|
|
195 _go32_dpmi_meminfo info;
|
|
196
|
|
197 _go32_dpmi_get_free_memory_information (&info);
|
|
198 lim_data = info.available_memory;
|
|
199 }
|
|
200 #else /* not MSDOS */
|
|
201 static void
|
74
|
202 get_lim_data (void)
|
0
|
203 {
|
|
204 lim_data = vlimit (LIM_DATA, -1);
|
|
205 }
|
|
206 #endif /* not MSDOS */
|
|
207
|
|
208 #else /* BSD4_2 */
|
|
209
|
|
210 static void
|
74
|
211 get_lim_data (void)
|
0
|
212 {
|
|
213 struct rlimit XXrlimit;
|
|
214
|
|
215 getrlimit (RLIMIT_DATA, &XXrlimit);
|
|
216 #ifdef RLIM_INFINITY
|
|
217 lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
|
|
218 #else
|
|
219 lim_data = XXrlimit.rlim_cur; /* soft limit */
|
|
220 #endif
|
|
221 }
|
|
222 #endif /* BSD4_2 */
|
|
223 #endif /* not WINDOWSNT */
|
|
224 #endif /* not USG */
|
|
225 #endif /* not NO_LIM_DATA */
|
251
|
226 #endif /* not HEAP_IN_DATA */
|
0
|
227
|
|
228 #endif /* _XEMACS_MEM_LIMITS_H_ */
|