]> code.delx.au - gnu-emacs/blob - src/mem-limits.h
*** empty log message ***
[gnu-emacs] / src / mem-limits.h
1 /* Includes for memory limit warnings.
2 Copyright (C) 1990, 1993 Free Software Foundation, Inc.
3
4 This file is part of GNU Emacs.
5
6 GNU Emacs 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 2, or (at your option)
9 any later version.
10
11 GNU Emacs 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.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #ifdef _LIBC
21
22 #include <sys/resource.h>
23 #define BSD4_2 /* Tell code below to use getrlimit. */
24
25 #else
26
27 #if defined(__osf__) && (defined(__mips) || defined(mips))
28 #include <sys/time.h>
29 #include <sys/resource.h>
30 #endif
31
32 #ifdef __bsdi__
33 #define BSD4_2
34 #endif
35
36 #ifndef BSD4_2
37 #ifndef USG
38 #include <sys/vlimit.h>
39 #endif /* not USG */
40 #else /* if BSD4_2 */
41 #include <sys/time.h>
42 #include <sys/resource.h>
43 #endif /* BSD4_2 */
44
45 #endif /* _LIBC */
46
47 #ifdef emacs
48 /* The important properties of this type are that 1) it's a pointer, and
49 2) arithmetic on it should work as if the size of the object pointed
50 to has a size of 1. */
51 #ifdef __STDC__
52 typedef void *POINTER;
53 #else
54 typedef char *POINTER;
55 #endif
56
57 typedef unsigned long SIZE;
58
59 #ifdef NULL
60 #undef NULL
61 #endif
62 #define NULL ((POINTER) 0)
63
64 extern POINTER start_of_data ();
65 #ifdef DATA_SEG_BITS
66 #define EXCEEDS_LISP_PTR(ptr) \
67 (((unsigned int) (ptr) & ~DATA_SEG_BITS) >> VALBITS)
68 #else
69 #define EXCEEDS_LISP_PTR(ptr) ((unsigned int) (ptr) >> VALBITS)
70 #endif
71
72 #ifdef BSD
73 #ifndef DATA_SEG_BITS
74 extern char etext;
75 #define start_of_data() &etext
76 #endif
77 #endif
78
79 #else /* Not emacs */
80 extern char etext;
81 #define start_of_data() &etext
82 #endif /* Not emacs */
83
84
85
86 /* start of data space; can be changed by calling malloc_init */
87 static POINTER data_space_start;
88
89 /* Number of bytes of writable memory we can expect to be able to get */
90 static unsigned int lim_data;
91
92 #ifdef USG
93
94 static void
95 get_lim_data ()
96 {
97 extern long ulimit ();
98
99 lim_data = -1;
100
101 /* Use the ulimit call, if we seem to have it. */
102 #if !defined (ULIMIT_BREAK_VALUE) || defined (LINUX)
103 lim_data = ulimit (3, 0);
104 #endif
105
106 /* If that didn't work, just use the macro's value. */
107 #ifdef ULIMIT_BREAK_VALUE
108 if (lim_data == -1)
109 lim_data = ULIMIT_BREAK_VALUE;
110 #endif
111
112 lim_data -= (long) data_space_start;
113 }
114
115 #else /* not USG */
116 #if !defined(BSD4_2) && !defined(__osf__)
117
118 static void
119 get_lim_data ()
120 {
121 lim_data = vlimit (LIM_DATA, -1);
122 }
123
124 #else /* BSD4_2 */
125
126 static void
127 get_lim_data ()
128 {
129 struct rlimit XXrlimit;
130
131 getrlimit (RLIMIT_DATA, &XXrlimit);
132 #ifdef RLIM_INFINITY
133 lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
134 #else
135 lim_data = XXrlimit.rlim_cur; /* soft limit */
136 #endif
137 }
138 #endif /* BSD4_2 */
139 #endif /* not USG */