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
|
|
132 #ifdef NO_LIM_DATA
|
|
133 static void
|
74
|
134 get_lim_data (void)
|
0
|
135 {
|
|
136 lim_data = -1;
|
|
137 }
|
|
138 #else /* not NO_LIM_DATA */
|
|
139
|
|
140 #ifdef USG
|
|
141
|
|
142 static void
|
74
|
143 get_lim_data (void)
|
0
|
144 {
|
|
145 lim_data = -1;
|
|
146
|
|
147 /* Use the ulimit call, if we seem to have it. */
|
|
148 #if !defined (ULIMIT_BREAK_VALUE) || defined (LINUX)
|
|
149 lim_data = ulimit (3, 0);
|
|
150 #endif
|
|
151
|
|
152 /* If that didn't work, just use the macro's value. */
|
|
153 #ifdef ULIMIT_BREAK_VALUE
|
|
154 if (lim_data == -1)
|
|
155 lim_data = ULIMIT_BREAK_VALUE;
|
|
156 #endif
|
|
157
|
|
158 lim_data -= (long) data_space_start;
|
|
159 }
|
|
160
|
|
161 #else /* not USG */
|
231
|
162 #if defined( WINDOWSNT ) || defined (__CYGWIN32__)
|
0
|
163
|
|
164 static void
|
74
|
165 get_lim_data (void)
|
0
|
166 {
|
|
167 extern unsigned long data_region_size;
|
|
168 lim_data = data_region_size;
|
|
169 }
|
|
170
|
|
171 #else
|
|
172 #if !defined (BSD4_2) && !defined (__osf__)
|
|
173
|
|
174 #ifdef MSDOS
|
|
175 void
|
74
|
176 get_lim_data (void)
|
0
|
177 {
|
|
178 _go32_dpmi_meminfo info;
|
|
179
|
|
180 _go32_dpmi_get_free_memory_information (&info);
|
|
181 lim_data = info.available_memory;
|
|
182 }
|
|
183 #else /* not MSDOS */
|
|
184 static void
|
74
|
185 get_lim_data (void)
|
0
|
186 {
|
|
187 lim_data = vlimit (LIM_DATA, -1);
|
|
188 }
|
|
189 #endif /* not MSDOS */
|
|
190
|
|
191 #else /* BSD4_2 */
|
|
192
|
|
193 static void
|
74
|
194 get_lim_data (void)
|
0
|
195 {
|
|
196 struct rlimit XXrlimit;
|
|
197
|
|
198 getrlimit (RLIMIT_DATA, &XXrlimit);
|
|
199 #ifdef RLIM_INFINITY
|
|
200 lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
|
|
201 #else
|
|
202 lim_data = XXrlimit.rlim_cur; /* soft limit */
|
|
203 #endif
|
|
204 }
|
|
205 #endif /* BSD4_2 */
|
|
206 #endif /* not WINDOWSNT */
|
|
207 #endif /* not USG */
|
|
208 #endif /* not NO_LIM_DATA */
|
|
209
|
|
210 #endif /* _XEMACS_MEM_LIMITS_H_ */
|