1 /* Includes for memory limit warnings.
2 Copyright (C) 1990, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
4 This file is part of SXEmacs
6 SXEmacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 SXEmacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* Synched up with: FSF 19.30. */
22 /* #### This ancient code really sucks.
23 configure should check for:
24 HAVE_SYS_RESOURCE_H, HAVE_ULIMIT_H, HAVE_GETRLIMIT, HAVE_ULIMIT,
25 and select action based on those values.
26 getrlimit() should be preferred to ulimit().
27 On Linux, ulimit() is deprecated and always returns -1. */
29 #ifndef INCLUDED_mem_limits_h_
30 #define INCLUDED_mem_limits_h_
40 /* Some systems need this before <sys/resource.h>. */
41 #include <sys/types.h>
45 #include <sys/resource.h>
46 #define BSD4_2 /* Tell code below to use getrlimit. */
48 /* Old Linux startup code won't define __data_start. */
49 extern int etext, __data_start;
50 weak_symbol(__data_start)
51 #define start_of_data() (&__data_start ?: &etext)
52 #else /* not GNU libc */
54 #if defined (__osf__) && (defined (__mips) || defined (mips) || defined (__alpha))
56 #include <sys/resource.h>
59 #if defined(__bsdi__) || defined(__NetBSD__) || defined(__linux__) || defined(__OpenBSD__)
65 #include <sys/vlimit.h>
69 #include <sys/resource.h>
73 /* The important properties of this type are that 1) it's a pointer, and
74 2) arithmetic on it should work as if the size of the object pointed
75 to has a size of 1. */
77 typedef void *POINTER;
79 typedef char *POINTER;
82 typedef unsigned long SIZE;
84 extern POINTER start_of_data(void);
85 #define EXCEEDS_LISP_PTR(ptr) 0
89 #define start_of_data() &etext
94 #define start_of_data() &etext
95 #endif /* not emacs */
97 #endif /* not _LIBC */
99 /* start of data space; can be changed by calling malloc_init */
100 static POINTER data_space_start;
102 /* Number of bytes of writable memory we can expect to be able to get */
103 #ifdef _RLIM_T_DECLARED
104 extern rlim_t lim_data;
106 extern unsigned long lim_data;
109 #if defined (HEAP_IN_DATA) && !defined(PDUMP)
110 extern unsigned long static_heap_size;
111 extern int initialized;
112 static inline void get_lim_data(void)
115 lim_data = (unsigned long)-1; /* static_heap_size; */
117 lim_data = (unsigned long)-1;
122 static inline void get_lim_data(void)
124 lim_data = (unsigned long)-1;
126 #else /* not NO_LIM_DATA */
128 #if defined(USG) && !defined(LINUX)
130 static inline void get_lim_data(void)
132 lim_data = (unsigned long)-1;
134 /* Use the ulimit call, if we seem to have it. */
135 #if !defined (ULIMIT_BREAK_VALUE)
136 lim_data = ulimit(3, 0);
139 /* If that didn't work, just use the macro's value. */
140 #ifdef ULIMIT_BREAK_VALUE
141 if (lim_data == (unsigned long)-1)
142 lim_data = ULIMIT_BREAK_VALUE;
145 lim_data -= (long)data_space_start;
149 #if !defined (BSD4_2) && !defined (__osf__) && !defined(LINUX)
151 static inline void get_lim_data(void)
153 lim_data = vlimit(LIM_DATA, -1);
158 static inline void get_lim_data(void)
160 struct rlimit XXrlimit;
162 getrlimit(RLIMIT_DATA, &XXrlimit);
164 lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
166 lim_data = XXrlimit.rlim_cur; /* soft limit */
171 #endif /* not NO_LIM_DATA */
172 #endif /* not HEAP_IN_DATA */
174 #endif /* INCLUDED_mem_limits_h_ */