Test NOT_C_CODE instead of THIS_IS_YMAKEFILE.
[bpt/emacs.git] / src / mem-limits.h
CommitLineData
9889c728 1/* Includes for memory limit warnings.
240049aa 2 Copyright (C) 1990, 1993, 1994, 1995 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
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
004164c5
RS
20#ifdef MSDOS
21#include <dpmi.h>
22#endif
23
f920c441
RM
24/* Some systems need this before <sys/resource.h>. */
25#include <sys/types.h>
26
b1814de2
RM
27#ifdef _LIBC
28
29#include <sys/resource.h>
ab8fb193 30#define BSD4_2 /* Tell code below to use getrlimit. */
b1814de2 31
240049aa
RM
32extern int __data_start;
33#define start_of_data() &__data_start
34
3999f961 35#else /* not _LIBC */
b1814de2 36
9aae3fc9 37#if defined (__osf__) && (defined (__mips) || defined (mips) || defined(__alpha))
c027d070
JB
38#include <sys/time.h>
39#include <sys/resource.h>
40#endif
41
cd1168e1
RS
42#ifdef __bsdi__
43#define BSD4_2
44#endif
45
9889c728
JB
46#ifndef BSD4_2
47#ifndef USG
004164c5 48#ifndef MSDOS
dbecffaa 49#ifndef WINDOWSNT
9889c728 50#include <sys/vlimit.h>
dbecffaa 51#endif /* not WINDOWSNT */
004164c5 52#endif /* not MSDOS */
9889c728
JB
53#endif /* not USG */
54#else /* if BSD4_2 */
55#include <sys/time.h>
56#include <sys/resource.h>
57#endif /* BSD4_2 */
58
6fb48933 59#ifdef emacs
5399ec5d
JB
60/* The important properties of this type are that 1) it's a pointer, and
61 2) arithmetic on it should work as if the size of the object pointed
62 to has a size of 1. */
9889c728
JB
63#ifdef __STDC__
64typedef void *POINTER;
65#else
66typedef char *POINTER;
67#endif
68
69typedef unsigned long SIZE;
70
71#ifdef NULL
72#undef NULL
73#endif
74#define NULL ((POINTER) 0)
75
9889c728 76extern POINTER start_of_data ();
27050994
JB
77#ifdef DATA_SEG_BITS
78#define EXCEEDS_LISP_PTR(ptr) \
9aae3fc9 79 (((EMACS_UINT) (ptr) & ~DATA_SEG_BITS) >> VALBITS)
27050994 80#else
9aae3fc9 81#define EXCEEDS_LISP_PTR(ptr) ((EMACS_UINT) (ptr) >> VALBITS)
27050994 82#endif
9889c728
JB
83
84#ifdef BSD
85#ifndef DATA_SEG_BITS
94d7c01a 86extern char etext;
9889c728
JB
87#define start_of_data() &etext
88#endif
89#endif
90
3999f961 91#else /* not emacs */
94d7c01a 92extern char etext;
9889c728 93#define start_of_data() &etext
3999f961 94#endif /* not emacs */
9889c728 95
3999f961 96#endif /* not _LIBC */
240049aa 97
9889c728
JB
98
99/* start of data space; can be changed by calling malloc_init */
100static POINTER data_space_start;
101
102/* Number of bytes of writable memory we can expect to be able to get */
103static unsigned int lim_data;
104
19b8fb9d
RS
105#ifdef NO_LIM_DATA
106static void
107get_lim_data ()
108{
109 lim_data = -1;
110}
111#else /* not NO_LIM_DATA */
112
9889c728
JB
113#ifdef USG
114
c52713b1 115static void
9889c728
JB
116get_lim_data ()
117{
118 extern long ulimit ();
161aa2f8
JB
119
120 lim_data = -1;
121
122 /* Use the ulimit call, if we seem to have it. */
123#if !defined (ULIMIT_BREAK_VALUE) || defined (LINUX)
9889c728
JB
124 lim_data = ulimit (3, 0);
125#endif
126
161aa2f8
JB
127 /* If that didn't work, just use the macro's value. */
128#ifdef ULIMIT_BREAK_VALUE
129 if (lim_data == -1)
130 lim_data = ULIMIT_BREAK_VALUE;
131#endif
132
9889c728
JB
133 lim_data -= (long) data_space_start;
134}
135
136#else /* not USG */
dbecffaa
RS
137#ifdef WINDOWSNT
138
139static void
140get_lim_data ()
141{
142 extern unsigned long data_region_size;
143 lim_data = data_region_size;
144}
145
146#else
004164c5
RS
147#if !defined (BSD4_2) && !defined (__osf__)
148
149#ifdef MSDOS
150void
151get_lim_data ()
152{
153 _go32_dpmi_meminfo info;
9889c728 154
004164c5
RS
155 _go32_dpmi_get_free_memory_information (&info);
156 lim_data = info.available_memory;
157}
158#else /* not MSDOS */
c52713b1 159static void
9889c728
JB
160get_lim_data ()
161{
162 lim_data = vlimit (LIM_DATA, -1);
163}
004164c5 164#endif /* not MSDOS */
9889c728
JB
165
166#else /* BSD4_2 */
167
c52713b1 168static void
9889c728
JB
169get_lim_data ()
170{
171 struct rlimit XXrlimit;
172
173 getrlimit (RLIMIT_DATA, &XXrlimit);
174#ifdef RLIM_INFINITY
175 lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
176#else
177 lim_data = XXrlimit.rlim_cur; /* soft limit */
178#endif
179}
180#endif /* BSD4_2 */
dbecffaa 181#endif /* not WINDOWSNT */
9889c728 182#endif /* not USG */
19b8fb9d 183#endif /* not NO_LIM_DATA */