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