1 /*	$NetBSD: mem-limits.h,v 1.2 2016/01/13 21:56:38 christos Exp $	*/
2 
3 /* Includes for memory limit warnings.
4    Copyright (C) 1990, 1993, 1994 Free Software Foundation, Inc.
5 
6 
7 This file is part of the GNU C Library.  Its master source is NOT part of
8 the C library, however.  The master source lives in /gd/gnu/lib.
9 
10 The GNU C Library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Library General Public License as
12 published by the Free Software Foundation; either version 2 of the
13 License, or (at your option) any later version.
14 
15 The GNU C Library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 Library General Public License for more details.
19 
20 You should have received a copy of the GNU Library General Public
21 License along with the GNU C Library; see the file COPYING.LIB.  If
22 not, write to the Free Software Foundation, Inc., 675 Mass Ave,
23 Cambridge, MA 02139, USA.  */
24 
25 #ifdef MSDOS
26 #include <dpmi.h>
27 #endif
28 
29 /* Some systems need this before <sys/resource.h>.  */
30 #include <sys/types.h>
31 
32 #ifdef _LIBC
33 
34 #include <sys/resource.h>
35 #define BSD4_2			/* Tell code below to use getrlimit.  */
36 
37 #else
38 
39 #if defined (__osf__) && (defined (__mips) || defined (mips) || defined(__alpha))
40 #include <sys/time.h>
41 #include <sys/resource.h>
42 #endif
43 
44 #if defined(__bsdi__) || defined(__NetBSD__)
45 #define BSD4_2
46 #endif
47 
48 #ifndef BSD4_2
49 #ifndef USG
50 #ifndef MSDOS
51 #ifndef WINDOWSNT
52 #include <sys/vlimit.h>
53 #endif /* not WINDOWSNT */
54 #endif /* not MSDOS */
55 #endif /* not USG */
56 #else /* if BSD4_2 */
57 #include <sys/time.h>
58 #include <sys/resource.h>
59 #endif /* BSD4_2 */
60 
61 #endif /* _LIBC */
62 
63 #ifdef emacs
64 /* The important properties of this type are that 1) it's a pointer, and
65    2) arithmetic on it should work as if the size of the object pointed
66    to has a size of 1.  */
67 #ifdef __STDC__
68 typedef void *POINTER;
69 #else
70 typedef char *POINTER;
71 #endif
72 
73 typedef unsigned long SIZE;
74 
75 #ifdef NULL
76 #undef NULL
77 #endif
78 #define NULL ((POINTER) 0)
79 
80 extern POINTER start_of_data ();
81 #ifdef DATA_SEG_BITS
82 #define EXCEEDS_LISP_PTR(ptr) \
83   (((EMACS_UINT) (ptr) & ~DATA_SEG_BITS) >> VALBITS)
84 #else
85 #define EXCEEDS_LISP_PTR(ptr) ((EMACS_UINT) (ptr) >> VALBITS)
86 #endif
87 
88 #ifdef BSD
89 #ifndef DATA_SEG_BITS
90 extern char etext;
91 #define start_of_data() &etext
92 #endif
93 #endif
94 
95 #else  /* Not emacs */
96 extern char etext;
97 #define start_of_data() &etext
98 #endif /* Not emacs */
99 
100 
101 
102 /* start of data space; can be changed by calling malloc_init */
103 static POINTER data_space_start;
104 
105 /* Number of bytes of writable memory we can expect to be able to get */
106 static unsigned int lim_data;
107 
108 #ifdef NO_LIM_DATA
109 static void
get_lim_data()110 get_lim_data ()
111 {
112   lim_data = -1;
113 }
114 #else /* not NO_LIM_DATA */
115 
116 #ifdef USG
117 
118 static void
get_lim_data()119 get_lim_data ()
120 {
121   extern long ulimit ();
122 
123   lim_data = -1;
124 
125   /* Use the ulimit call, if we seem to have it.  */
126 #if !defined (ULIMIT_BREAK_VALUE) || defined (LINUX)
127   lim_data = ulimit (3, 0);
128 #endif
129 
130   /* If that didn't work, just use the macro's value.  */
131 #ifdef ULIMIT_BREAK_VALUE
132   if (lim_data == -1)
133     lim_data = ULIMIT_BREAK_VALUE;
134 #endif
135 
136   lim_data -= (long) data_space_start;
137 }
138 
139 #else /* not USG */
140 #ifdef WINDOWSNT
141 
142 static void
get_lim_data()143 get_lim_data ()
144 {
145   extern unsigned long data_region_size;
146   lim_data = data_region_size;
147 }
148 
149 #else
150 #if !defined (BSD4_2) && !defined (__osf__)
151 
152 #ifdef MSDOS
153 void
get_lim_data()154 get_lim_data ()
155 {
156   _go32_dpmi_meminfo info;
157 
158   _go32_dpmi_get_free_memory_information (&info);
159   lim_data = info.available_memory;
160 }
161 #else /* not MSDOS */
162 static void
get_lim_data()163 get_lim_data ()
164 {
165   lim_data = vlimit (LIM_DATA, -1);
166 }
167 #endif /* not MSDOS */
168 
169 #else /* BSD4_2 */
170 
171 static void
get_lim_data()172 get_lim_data ()
173 {
174   struct rlimit XXrlimit;
175 
176   if (getrlimit (RLIMIT_DATA, &XXrlimit) == -1)
177 	XXrlimit.rlim_cur = -1;
178 #ifdef RLIM_INFINITY
179   lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
180 #else
181   lim_data = XXrlimit.rlim_cur;	/* soft limit */
182 #endif
183 }
184 #endif /* BSD4_2 */
185 #endif /* not WINDOWSNT */
186 #endif /* not USG */
187 #endif /* not NO_LIM_DATA */
188