(specpdl_ptr): Declare volatile.
[bpt/emacs.git] / src / mem-limits.h
CommitLineData
9889c728 1/* Includes for memory limit warnings.
6d0dbbaf 2 Copyright (C) 1990, 1993, 1994, 1995, 1996 Free Software Foundation, Inc.
9889c728
JB
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
cd1168e1 8the Free Software Foundation; either version 2, or (at your option)
9889c728
JB
9any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
3b7ad313
EN
18the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
9889c728 20
004164c5
RS
21#ifdef MSDOS
22#include <dpmi.h>
a8c1733b 23extern int etext;
004164c5
RS
24#endif
25
f920c441
RM
26/* Some systems need this before <sys/resource.h>. */
27#include <sys/types.h>
28
b1814de2
RM
29#ifdef _LIBC
30
31#include <sys/resource.h>
ab8fb193 32#define BSD4_2 /* Tell code below to use getrlimit. */
b1814de2 33
6c6b28ea 34/* Old Linux startup code won't define __data_start. */
6d0dbbaf 35extern int etext, __data_start; weak_extern (__data_start)
6c6b28ea 36#define start_of_data() (&__data_start ?: &etext)
240049aa 37
3999f961 38#else /* not _LIBC */
b1814de2 39
9aae3fc9 40#if defined (__osf__) && (defined (__mips) || defined (mips) || defined(__alpha))
c027d070
JB
41#include <sys/time.h>
42#include <sys/resource.h>
43#endif
44
cd1168e1
RS
45#ifdef __bsdi__
46#define BSD4_2
47#endif
48
c60ee5e7
JB
49#ifdef CYGWIN
50#define BSD4_2
51#endif
52
9889c728
JB
53#ifndef BSD4_2
54#ifndef USG
004164c5 55#ifndef MSDOS
dbecffaa 56#ifndef WINDOWSNT
9889c728 57#include <sys/vlimit.h>
dbecffaa 58#endif /* not WINDOWSNT */
004164c5 59#endif /* not MSDOS */
9889c728
JB
60#endif /* not USG */
61#else /* if BSD4_2 */
62#include <sys/time.h>
63#include <sys/resource.h>
64#endif /* BSD4_2 */
65
6fb48933 66#ifdef emacs
5399ec5d
JB
67/* The important properties of this type are that 1) it's a pointer, and
68 2) arithmetic on it should work as if the size of the object pointed
69 to has a size of 1. */
8bbffb13 70typedef POINTER_TYPE *POINTER;
9889c728
JB
71
72typedef unsigned long SIZE;
73
74#ifdef NULL
75#undef NULL
76#endif
77#define NULL ((POINTER) 0)
78
9889c728 79extern POINTER start_of_data ();
27050994
JB
80#ifdef DATA_SEG_BITS
81#define EXCEEDS_LISP_PTR(ptr) \
9aae3fc9 82 (((EMACS_UINT) (ptr) & ~DATA_SEG_BITS) >> VALBITS)
27050994 83#else
9aae3fc9 84#define EXCEEDS_LISP_PTR(ptr) ((EMACS_UINT) (ptr) >> VALBITS)
27050994 85#endif
9889c728 86
f456a2bc
KR
87#ifdef DATA_START
88#define start_of_data() ((char *)DATA_START)
89#endif
90
6df54671 91#ifdef BSD_SYSTEM
9889c728 92#ifndef DATA_SEG_BITS
f456a2bc 93#ifndef DATA_START
94d7c01a 94extern char etext;
9889c728
JB
95#define start_of_data() &etext
96#endif
97#endif
f456a2bc 98#endif
9889c728 99
6c6b28ea 100#else /* not emacs */
94d7c01a 101extern char etext;
9889c728 102#define start_of_data() &etext
3999f961 103#endif /* not emacs */
9889c728 104
3999f961 105#endif /* not _LIBC */
240049aa 106
9889c728
JB
107
108/* start of data space; can be changed by calling malloc_init */
109static POINTER data_space_start;
110
111/* Number of bytes of writable memory we can expect to be able to get */
78c33db1 112static unsigned long lim_data;
9889c728 113
19b8fb9d
RS
114#ifdef NO_LIM_DATA
115static void
116get_lim_data ()
117{
118 lim_data = -1;
119}
120#else /* not NO_LIM_DATA */
121
9889c728
JB
122#ifdef USG
123
c52713b1 124static void
9889c728
JB
125get_lim_data ()
126{
127 extern long ulimit ();
161aa2f8
JB
128
129 lim_data = -1;
130
131 /* Use the ulimit call, if we seem to have it. */
8a2a6032 132#if !defined (ULIMIT_BREAK_VALUE) || defined (GNU_LINUX)
9889c728
JB
133 lim_data = ulimit (3, 0);
134#endif
135
161aa2f8
JB
136 /* If that didn't work, just use the macro's value. */
137#ifdef ULIMIT_BREAK_VALUE
138 if (lim_data == -1)
139 lim_data = ULIMIT_BREAK_VALUE;
140#endif
141
9889c728
JB
142 lim_data -= (long) data_space_start;
143}
144
145#else /* not USG */
dbecffaa
RS
146#ifdef WINDOWSNT
147
148static void
149get_lim_data ()
150{
3bc2366f
AI
151 extern unsigned long reserved_heap_size;
152 lim_data = reserved_heap_size;
dbecffaa
RS
153}
154
155#else
004164c5
RS
156#if !defined (BSD4_2) && !defined (__osf__)
157
158#ifdef MSDOS
159void
160get_lim_data ()
161{
162 _go32_dpmi_meminfo info;
9889c728 163
004164c5
RS
164 _go32_dpmi_get_free_memory_information (&info);
165 lim_data = info.available_memory;
166}
167#else /* not MSDOS */
c52713b1 168static void
9889c728
JB
169get_lim_data ()
170{
171 lim_data = vlimit (LIM_DATA, -1);
172}
004164c5 173#endif /* not MSDOS */
9889c728
JB
174
175#else /* BSD4_2 */
176
c52713b1 177static void
9889c728
JB
178get_lim_data ()
179{
180 struct rlimit XXrlimit;
181
182 getrlimit (RLIMIT_DATA, &XXrlimit);
183#ifdef RLIM_INFINITY
184 lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
185#else
186 lim_data = XXrlimit.rlim_cur; /* soft limit */
187#endif
188}
189#endif /* BSD4_2 */
dbecffaa 190#endif /* not WINDOWSNT */
9889c728 191#endif /* not USG */
19b8fb9d 192#endif /* not NO_LIM_DATA */