comparison src/mem-limits.h @ 2263:702b5727498a

[xemacs-hg @ 2004-09-11 05:28:11 by malcolmp] mem-limits.h: Use configure to check for OS specific functions.
author malcolmp
date Sat, 11 Sep 2004 05:28:41 +0000
parents 34ca43a57692
children 308d34e9f07d
comparison
equal deleted inserted replaced
2262:09e68196904a 2263:702b5727498a
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */ 19 Boston, MA 02111-1307, USA. */
20 20
21 /* Synched up with: FSF 19.30. */ 21 /* Synched up with: FSF 19.30. */
22 22
23 /* #### This ancient code really sucks. 23 /* Subsequently cleaned up and reorganised, made to use configure. */
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 24
30 #ifndef INCLUDED_mem_limits_h_ 25 #ifndef INCLUDED_mem_limits_h_
31 #define INCLUDED_mem_limits_h_ 26 #define INCLUDED_mem_limits_h_
32 27
33 #ifdef HAVE_CONFIG_H 28 #ifdef HAVE_CONFIG_H
36 31
37 #ifdef HAVE_ULIMIT_H 32 #ifdef HAVE_ULIMIT_H
38 #include <ulimit.h> 33 #include <ulimit.h>
39 #endif 34 #endif
40 35
41 /* Some systems need this before <sys/resource.h>. */ 36 #ifdef HAVE_SYS_RESOURCE_H
37 /* Some systems need either sys/types.h or sys/time.h before <sys/resource.h>. */
42 #include <sys/types.h> 38 #include <sys/types.h>
39 #include <sys/time.h>
40 #include <sys/resource.h>
41 #endif
42
43 #ifdef HAVE_SYS_VLIMIT_H
44 #include <sys/vlimit.h>
45 #endif
43 46
44 #ifdef _LIBC 47 #ifdef _LIBC
45
46 #include <sys/resource.h>
47 #define BSD4_2 /* Tell code below to use getrlimit. */
48 48
49 /* Old Linux startup code won't define __data_start. */ 49 /* Old Linux startup code won't define __data_start. */
50 extern int etext, __data_start; weak_symbol (__data_start) 50 extern int etext, __data_start; weak_symbol (__data_start)
51 #define start_of_data() (&__data_start ?: &etext) 51 #define start_of_data() (&__data_start ?: &etext)
52 52
53 #else /* not GNU libc */ 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 #define BSD4_2
62 #endif
63
64 #ifndef BSD4_2
65 #ifndef USG
66 #ifndef WIN32_NATIVE
67 #ifndef CYGWIN
68 #include <sys/vlimit.h>
69 #endif /* not CYGWIN */
70 #endif /* not WIN32_NATIVE */
71 #endif /* not USG */
72 #else /* if BSD4_2 */
73 #include <sys/time.h>
74 #include <sys/resource.h>
75 #endif /* BSD4_2 */
76 54
77 #ifdef emacs 55 #ifdef emacs
78 typedef void *POINTER; 56 typedef void *POINTER;
79 57
80 #ifndef CYGWIN 58 #ifndef CYGWIN
102 static POINTER data_space_start; 80 static POINTER data_space_start;
103 81
104 /* Number of bytes of writable memory we can expect to be able to get */ 82 /* Number of bytes of writable memory we can expect to be able to get */
105 extern unsigned long lim_data; 83 extern unsigned long lim_data;
106 84
85 /* The implementation of get_lim_data() is very machine dependent. */
86
107 #if defined (HEAP_IN_DATA) && !defined(PDUMP) 87 #if defined (HEAP_IN_DATA) && !defined(PDUMP)
108 extern unsigned long static_heap_size; 88 extern unsigned long static_heap_size;
109 extern MODULE_API int initialized; 89 extern MODULE_API int initialized;
90
110 static void 91 static void
111 get_lim_data (void) 92 get_lim_data (void)
112 { 93 {
113 if (!initialized) 94 if (!initialized)
114 { 95 {
117 else 98 else
118 { 99 {
119 lim_data = (unsigned long) -1; 100 lim_data = (unsigned long) -1;
120 } 101 }
121 } 102 }
122 #else 103
123 #ifdef NO_LIM_DATA 104 #elif defined(NO_LIM_DATA)
105
124 static void 106 static void
125 get_lim_data (void) 107 get_lim_data (void)
126 { 108 {
127 lim_data = (unsigned long) -1; 109 lim_data = (unsigned long) -1;
128 } 110 }
129 #else /* not NO_LIM_DATA */
130 111
131 #if defined(USG) && !defined(LINUX) 112 #elif defined(HAVE_GETRLIMIT)
113
114 static void
115 get_lim_data (void)
116 {
117 struct rlimit XXrlimit;
118
119 getrlimit (RLIMIT_DATA, &XXrlimit);
120 #ifdef RLIM_INFINITY
121 lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
122 #else
123 lim_data = XXrlimit.rlim_cur; /* soft limit */
124 #endif
125 }
126
127 #elif defined(HAVE_ULIMIT)
132 128
133 static void 129 static void
134 get_lim_data (void) 130 get_lim_data (void)
135 { 131 {
136 lim_data = (unsigned long) -1; 132 lim_data = (unsigned long) -1;
147 #endif 143 #endif
148 144
149 lim_data -= (long) data_space_start; 145 lim_data -= (long) data_space_start;
150 } 146 }
151 147
152 #else /* not USG */ 148 #elif defined(WIN32_NATIVE)
153 #if defined( WIN32_NATIVE )
154 149
155 static void 150 static void
156 get_lim_data (void) 151 get_lim_data (void)
157 { 152 {
158 extern unsigned long data_region_size; 153 extern unsigned long data_region_size;
159 lim_data = data_region_size; 154 lim_data = data_region_size;
160 } 155 }
161 156
162 #else 157 #elif defined(HAVE_VLIMIT)
163 #if !defined (BSD4_2) && !defined (__osf__) && !defined(LINUX)
164 158
165 static void 159 static void
166 get_lim_data (void) 160 get_lim_data (void)
167 { 161 {
168 lim_data = vlimit (LIM_DATA, -1); 162 lim_data = vlimit (LIM_DATA, -1);
169 } 163 }
170 164
171 #else /* BSD4_2 */
172
173 static void
174 get_lim_data (void)
175 {
176 struct rlimit XXrlimit;
177
178 getrlimit (RLIMIT_DATA, &XXrlimit);
179 #ifdef RLIM_INFINITY
180 lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
181 #else 165 #else
182 lim_data = XXrlimit.rlim_cur; /* soft limit */ 166 #error Cannot determine an implementation of get_lim_data().
183 #endif 167 #endif /* not HAVE_VLIMIT */
184 }
185 #endif /* BSD4_2 */
186 #endif /* not WIN32_NATIVE */
187 #endif /* not USG */
188 #endif /* not NO_LIM_DATA */
189 #endif /* not HEAP_IN_DATA */
190 168
191 #endif /* INCLUDED_mem_limits_h_ */ 169 #endif /* INCLUDED_mem_limits_h_ */