import -ko -b 1.1.3 XEmacs XEmacs-21_2 r21-2-35
[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 /* 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 #if defined(__linux__) && defined (powerpc)     /*Added by Fukui*/
62 #else                                   /*Added by Fukui*/
63 #define BSD4_2
64 #endif                                  /*Added by Fukui*/
65 #endif
66
67 #ifndef BSD4_2
68 #ifndef USG
69 #ifndef WIN32_NATIVE
70 #ifndef CYGWIN
71 #if defined(__linux__) && defined(powerpc)      /*Added Kaoru Fukui*/
72 #else                                           /*Added Kaoru Fukui*/
73 #include <sys/vlimit.h>
74 #endif                          /*Added by Fukui*/
75 #endif /* not CYGWIN */
76 #endif /* not WIN32_NATIVE */
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
93 #ifndef CYGWIN
94 typedef unsigned long SIZE;
95 #endif
96
97 extern POINTER start_of_data (void);
98 #define EXCEEDS_LISP_PTR(ptr) 0
99
100 #ifdef BSD
101 extern int etext;
102 #define start_of_data() &etext
103 #endif
104
105 #else  /* not emacs */
106 extern char etext;
107 #define start_of_data() &etext
108 #endif /* not emacs */
109
110 #endif /* not _LIBC */
111
112
113
114 /* start of data space; can be changed by calling malloc_init */
115 static POINTER data_space_start;
116
117 /* Number of bytes of writable memory we can expect to be able to get */
118 extern unsigned int lim_data;
119
120 #if defined (HEAP_IN_DATA) && !defined(PDUMP)
121 extern unsigned long static_heap_size;
122 extern int initialized;
123 static void
124 get_lim_data (void)
125 {
126   if (!initialized)
127     {
128       lim_data = (unsigned int) -1; /* static_heap_size; */
129     }
130   else
131     {
132       lim_data = (unsigned int) -1;
133     }
134 }
135 #else
136 #ifdef NO_LIM_DATA
137 static void
138 get_lim_data (void)
139 {
140   lim_data = (unsigned int) -1;
141 }
142 #else /* not NO_LIM_DATA */
143
144 #ifdef USG
145
146 static void
147 get_lim_data (void)
148 {
149   lim_data = (unsigned int) -1;
150
151   /* Use the ulimit call, if we seem to have it.  */
152 #if !defined (ULIMIT_BREAK_VALUE) || defined (LINUX)
153   lim_data = ulimit (3, 0);
154 #endif
155
156   /* If that didn't work, just use the macro's value.  */
157 #ifdef ULIMIT_BREAK_VALUE
158   if (lim_data == (unsigned int) -1)
159     lim_data = ULIMIT_BREAK_VALUE;
160 #endif
161
162   lim_data -= (long) data_space_start;
163 }
164
165 #else /* not USG */
166 #if defined( WIN32_NATIVE )
167
168 static void
169 get_lim_data (void)
170 {
171   extern unsigned long data_region_size;
172   lim_data = data_region_size;
173 }
174
175 #else
176 #if !defined (BSD4_2) && !defined (__osf__)
177
178 static void
179 get_lim_data (void)
180 {
181   lim_data = vlimit (LIM_DATA, -1);
182 }
183
184 #else /* BSD4_2 */
185
186 static void
187 get_lim_data (void)
188 {
189   struct rlimit XXrlimit;
190
191   getrlimit (RLIMIT_DATA, &XXrlimit);
192 #ifdef RLIM_INFINITY
193   lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
194 #else
195   lim_data = XXrlimit.rlim_cur; /* soft limit */
196 #endif
197 }
198 #endif /* BSD4_2 */
199 #endif /* not WIN32_NATIVE */
200 #endif /* not USG */
201 #endif /* not NO_LIM_DATA */
202 #endif /* not HEAP_IN_DATA */
203
204 #endif /* INCLUDED_mem_limits_h_ */