XEmacs 21.2.30 "Hygeia".
[chise/xemacs-chise.git.1] / src / mem-limits.h
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
30 #ifndef INCLUDED_mem_limits_h_
31 #define INCLUDED_mem_limits_h_
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 #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
57 #else /* not GNU libc */
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__) || defined(__linux__) || defined(__OpenBSD__)
65 #if defined(__linux__) && defined (powerpc)     /*Added by Fukui*/
66 #else                                   /*Added by Fukui*/
67 #define BSD4_2
68 #endif                                  /*Added by Fukui*/
69 #endif
70
71 #ifndef BSD4_2
72 #ifndef USG
73 #ifndef MSDOS
74 #ifndef WINDOWSNT
75 #ifndef __CYGWIN32__
76 #if defined(__linux__) && defined(powerpc)      /*Added Kaoru Fukui*/
77 #else                                           /*Added Kaoru Fukui*/
78 #include <sys/vlimit.h>
79 #endif                          /*Added by Fukui*/
80 #endif /* not __CYGWIN32__ */
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
99 #ifndef __CYGWIN32__
100 typedef unsigned long SIZE;
101 #endif
102
103 extern POINTER start_of_data (void);
104 #define EXCEEDS_LISP_PTR(ptr) 0
105
106 #ifdef BSD
107 extern int etext;
108 #define start_of_data() &etext
109 #endif
110
111 #else  /* not emacs */
112 extern char etext;
113 #define start_of_data() &etext
114 #endif /* not emacs */
115
116 #endif /* not _LIBC */
117
118
119
120 /* start of data space; can be changed by calling malloc_init */
121 static POINTER data_space_start;
122
123 /* Number of bytes of writable memory we can expect to be able to get */
124 extern unsigned int lim_data;
125
126 #ifdef HEAP_IN_DATA
127 extern unsigned long static_heap_size;
128 extern int initialized;
129 static void
130 get_lim_data (void)
131 {
132   if (!initialized)
133     {
134       lim_data = (unsigned int) -1; /* static_heap_size; */
135     }
136   else
137     {
138       lim_data = (unsigned int) -1;
139     }
140 }
141 #else
142 #ifdef NO_LIM_DATA
143 static void
144 get_lim_data (void)
145 {
146   lim_data = (unsigned int) -1;
147 }
148 #else /* not NO_LIM_DATA */
149
150 #ifdef USG
151
152 static void
153 get_lim_data (void)
154 {
155   lim_data = (unsigned int) -1;
156
157   /* Use the ulimit call, if we seem to have it.  */
158 #if !defined (ULIMIT_BREAK_VALUE) || defined (LINUX)
159   lim_data = ulimit (3, 0);
160 #endif
161
162   /* If that didn't work, just use the macro's value.  */
163 #ifdef ULIMIT_BREAK_VALUE
164   if (lim_data == (unsigned int) -1)
165     lim_data = ULIMIT_BREAK_VALUE;
166 #endif
167
168   lim_data -= (long) data_space_start;
169 }
170
171 #else /* not USG */
172 #if defined( WINDOWSNT )
173
174 static void
175 get_lim_data (void)
176 {
177   extern unsigned long data_region_size;
178   lim_data = data_region_size;
179 }
180
181 #else
182 #if !defined (BSD4_2) && !defined (__osf__)
183
184 #ifdef MSDOS
185 void
186 get_lim_data (void)
187 {
188   _go32_dpmi_meminfo info;
189
190   _go32_dpmi_get_free_memory_information (&info);
191   lim_data = info.available_memory;
192 }
193 #else /* not MSDOS */
194 static void
195 get_lim_data (void)
196 {
197   lim_data = vlimit (LIM_DATA, -1);
198 }
199 #endif /* not MSDOS */
200
201 #else /* BSD4_2 */
202
203 static void
204 get_lim_data (void)
205 {
206   struct rlimit XXrlimit;
207
208   getrlimit (RLIMIT_DATA, &XXrlimit);
209 #ifdef RLIM_INFINITY
210   lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
211 #else
212   lim_data = XXrlimit.rlim_cur; /* soft limit */
213 #endif
214 }
215 #endif /* BSD4_2 */
216 #endif /* not WINDOWSNT */
217 #endif /* not USG */
218 #endif /* not NO_LIM_DATA */
219 #endif /* not HEAP_IN_DATA */
220
221 #endif /* INCLUDED_mem_limits_h_ */