annotate src/vm-limit.c @ 110706:ab3815920cc5

* emacsclient.c (main): Return EXIT_FAILURE if Emacs sends us an error string (Bug#6963).
author Chong Yidong <cyd@stupidchicken.com>
date Sat, 02 Oct 2010 20:00:01 -0400
parents faeb6f3341b1
children b9752b72e1ee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
1 /* Functions for memory limit warnings.
94963
8971ddf55736 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79759
diff changeset
2 Copyright (C) 1990, 1992, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 105669
diff changeset
3 2008, 2009, 2010 Free Software Foundation, Inc.
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
4
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
5 This file is part of GNU Emacs.
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
6
94963
8971ddf55736 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79759
diff changeset
7 GNU Emacs is free software: you can redistribute it and/or modify
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
94963
8971ddf55736 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79759
diff changeset
9 the Free Software Foundation, either version 3 of the License, or
8971ddf55736 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79759
diff changeset
10 (at your option) any later version.
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
11
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
12 GNU Emacs is distributed in the hope that it will be useful,
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
15 GNU General Public License for more details.
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
16
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
94963
8971ddf55736 Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 79759
diff changeset
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
19
1392
ad64a94cd81c (morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 734
diff changeset
20 #ifdef emacs
4696
1fc792473491 Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents: 3935
diff changeset
21 #include <config.h>
105669
68dd71358159 * alloc.c: Do not define struct catchtag.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 100864
diff changeset
22 #include <setjmp.h>
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
23 #include "lisp.h"
1392
ad64a94cd81c (morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 734
diff changeset
24 #endif
ad64a94cd81c (morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 734
diff changeset
25
1398
70d0cd4c5bff mem_limits.h is now called mem-limits.h.
Roland McGrath <roland@gnu.org>
parents: 1392
diff changeset
26 #include "mem-limits.h"
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
27
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
28 /*
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
29 Level number of warnings already issued.
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
30 0 -- no warnings issued.
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
31 1 -- 75% warning already issued.
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
32 2 -- 85% warning already issued.
1392
ad64a94cd81c (morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 734
diff changeset
33 3 -- 95% warning issued; keep warning frequently.
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
34 */
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
35 enum warnlevel { not_warned, warned_75, warned_85, warned_95 };
109576
faeb6f3341b1 Fix some stuff that didn't compile.
Jan D. <jan.h.d@swipnet.se>
parents: 109575
diff changeset
36 static enum warnlevel warnlevel;
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
37
109576
faeb6f3341b1 Fix some stuff that didn't compile.
Jan D. <jan.h.d@swipnet.se>
parents: 109575
diff changeset
38 typedef POINTER_TYPE *POINTER;
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
39
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
40 /* Function to call to issue a warning;
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
41 0 means don't issue them. */
109313
e856a274549b Constify functions taking char *
Andreas Schwab <schwab@linux-m68k.org>
parents: 109168
diff changeset
42 static void (*warn_function) (const char *);
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
43
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
44 /* Start of data space; can be changed by calling malloc_init. */
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
45 static POINTER data_space_start;
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
46
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
47 /* Number of bytes of writable memory we can expect to be able to get. */
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
48 static unsigned long lim_data;
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
49
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
50
97252
c2be97b488c4 (get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Andreas Schwab <schwab@suse.de>
parents: 97251
diff changeset
51 #if defined (HAVE_GETRLIMIT) && defined (RLIMIT_AS)
c2be97b488c4 (get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Andreas Schwab <schwab@suse.de>
parents: 97251
diff changeset
52 static void
109144
7dceae91724c Convert most remaining function definitions to standard C.
Juanma Barranquero <lekktu@gmail.com>
parents: 109097
diff changeset
53 get_lim_data (void)
97252
c2be97b488c4 (get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Andreas Schwab <schwab@suse.de>
parents: 97251
diff changeset
54 {
c2be97b488c4 (get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Andreas Schwab <schwab@suse.de>
parents: 97251
diff changeset
55 struct rlimit rlimit;
c2be97b488c4 (get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Andreas Schwab <schwab@suse.de>
parents: 97251
diff changeset
56
c2be97b488c4 (get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Andreas Schwab <schwab@suse.de>
parents: 97251
diff changeset
57 getrlimit (RLIMIT_AS, &rlimit);
c2be97b488c4 (get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Andreas Schwab <schwab@suse.de>
parents: 97251
diff changeset
58 if (rlimit.rlim_cur == RLIM_INFINITY)
c2be97b488c4 (get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Andreas Schwab <schwab@suse.de>
parents: 97251
diff changeset
59 lim_data = -1;
c2be97b488c4 (get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Andreas Schwab <schwab@suse.de>
parents: 97251
diff changeset
60 else
c2be97b488c4 (get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Andreas Schwab <schwab@suse.de>
parents: 97251
diff changeset
61 lim_data = rlimit.rlim_cur;
c2be97b488c4 (get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Andreas Schwab <schwab@suse.de>
parents: 97251
diff changeset
62 }
c2be97b488c4 (get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Andreas Schwab <schwab@suse.de>
parents: 97251
diff changeset
63
c2be97b488c4 (get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Andreas Schwab <schwab@suse.de>
parents: 97251
diff changeset
64 #else /* not HAVE_GETRLIMIT */
c2be97b488c4 (get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Andreas Schwab <schwab@suse.de>
parents: 97251
diff changeset
65
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
66 #ifdef USG
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
67
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
68 static void
109480
d12162869c07 Convert some more functions to standard C.
Juanma Barranquero <lekktu@gmail.com>
parents: 109313
diff changeset
69 get_lim_data (void)
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
70 {
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
71 extern long ulimit ();
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
72
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
73 lim_data = -1;
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
74
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
75 /* Use the ulimit call, if we seem to have it. */
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
76 #if !defined (ULIMIT_BREAK_VALUE) || defined (GNU_LINUX)
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
77 lim_data = ulimit (3, 0);
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
78 #endif
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
79
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
80 /* If that didn't work, just use the macro's value. */
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
81 #ifdef ULIMIT_BREAK_VALUE
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
82 if (lim_data == -1)
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
83 lim_data = ULIMIT_BREAK_VALUE;
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
84 #endif
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
85
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
86 lim_data -= (long) data_space_start;
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
87 }
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
88
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
89 #else /* not USG */
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
90 #ifdef WINDOWSNT
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
91
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
92 static void
109480
d12162869c07 Convert some more functions to standard C.
Juanma Barranquero <lekktu@gmail.com>
parents: 109313
diff changeset
93 get_lim_data (void)
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
94 {
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
95 extern unsigned long reserved_heap_size;
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
96 lim_data = reserved_heap_size;
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
97 }
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
98
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
99 #else
109575
ad36da121d41 * src/vm-limit.c: Do not include sys/resource.h, mem-limits.h does it.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109537
diff changeset
100 #if !defined (BSD4_2) && !defined (CYGWIN)
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
101
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
102 #ifdef MSDOS
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
103 void
109480
d12162869c07 Convert some more functions to standard C.
Juanma Barranquero <lekktu@gmail.com>
parents: 109313
diff changeset
104 get_lim_data (void)
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
105 {
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
106 _go32_dpmi_meminfo info;
97687
05ccdea3b63e (get_lim_data) [MSDOS]: Use alternative methods of estimating available memory.
Eli Zaretskii <eliz@gnu.org>
parents: 97252
diff changeset
107 unsigned long lim1, lim2;
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
108
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
109 _go32_dpmi_get_free_memory_information (&info);
97687
05ccdea3b63e (get_lim_data) [MSDOS]: Use alternative methods of estimating available memory.
Eli Zaretskii <eliz@gnu.org>
parents: 97252
diff changeset
110 /* DPMI server of Windows NT and its descendants reports in
05ccdea3b63e (get_lim_data) [MSDOS]: Use alternative methods of estimating available memory.
Eli Zaretskii <eliz@gnu.org>
parents: 97252
diff changeset
111 info.available_memory a much lower amount that is really
05ccdea3b63e (get_lim_data) [MSDOS]: Use alternative methods of estimating available memory.
Eli Zaretskii <eliz@gnu.org>
parents: 97252
diff changeset
112 available, which causes bogus "past 95% of memory limit"
05ccdea3b63e (get_lim_data) [MSDOS]: Use alternative methods of estimating available memory.
Eli Zaretskii <eliz@gnu.org>
parents: 97252
diff changeset
113 warnings. Try to overcome that via circumstantial evidence. */
05ccdea3b63e (get_lim_data) [MSDOS]: Use alternative methods of estimating available memory.
Eli Zaretskii <eliz@gnu.org>
parents: 97252
diff changeset
114 lim1 = info.available_memory;
99457
439bc48615be (get_lim_data): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents: 97687
diff changeset
115 lim2 = info.available_physical_pages;
97687
05ccdea3b63e (get_lim_data) [MSDOS]: Use alternative methods of estimating available memory.
Eli Zaretskii <eliz@gnu.org>
parents: 97252
diff changeset
116 /* DPMI Spec: "Fields that are unavailable will hold -1." */
05ccdea3b63e (get_lim_data) [MSDOS]: Use alternative methods of estimating available memory.
Eli Zaretskii <eliz@gnu.org>
parents: 97252
diff changeset
117 if ((long)lim1 == -1L)
05ccdea3b63e (get_lim_data) [MSDOS]: Use alternative methods of estimating available memory.
Eli Zaretskii <eliz@gnu.org>
parents: 97252
diff changeset
118 lim1 = 0;
05ccdea3b63e (get_lim_data) [MSDOS]: Use alternative methods of estimating available memory.
Eli Zaretskii <eliz@gnu.org>
parents: 97252
diff changeset
119 if ((long)lim2 == -1L)
05ccdea3b63e (get_lim_data) [MSDOS]: Use alternative methods of estimating available memory.
Eli Zaretskii <eliz@gnu.org>
parents: 97252
diff changeset
120 lim2 = 0;
99457
439bc48615be (get_lim_data): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents: 97687
diff changeset
121 else
439bc48615be (get_lim_data): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents: 97687
diff changeset
122 lim2 *= 4096;
97687
05ccdea3b63e (get_lim_data) [MSDOS]: Use alternative methods of estimating available memory.
Eli Zaretskii <eliz@gnu.org>
parents: 97252
diff changeset
123 /* Surely, the available memory is at least what we have physically
05ccdea3b63e (get_lim_data) [MSDOS]: Use alternative methods of estimating available memory.
Eli Zaretskii <eliz@gnu.org>
parents: 97252
diff changeset
124 available, right? */
99457
439bc48615be (get_lim_data): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents: 97687
diff changeset
125 if (lim1 >= lim2)
97687
05ccdea3b63e (get_lim_data) [MSDOS]: Use alternative methods of estimating available memory.
Eli Zaretskii <eliz@gnu.org>
parents: 97252
diff changeset
126 lim_data = lim1;
05ccdea3b63e (get_lim_data) [MSDOS]: Use alternative methods of estimating available memory.
Eli Zaretskii <eliz@gnu.org>
parents: 97252
diff changeset
127 else
05ccdea3b63e (get_lim_data) [MSDOS]: Use alternative methods of estimating available memory.
Eli Zaretskii <eliz@gnu.org>
parents: 97252
diff changeset
128 lim_data = lim2;
05ccdea3b63e (get_lim_data) [MSDOS]: Use alternative methods of estimating available memory.
Eli Zaretskii <eliz@gnu.org>
parents: 97252
diff changeset
129 /* Don't believe they will give us more that 0.5 GB. */
99457
439bc48615be (get_lim_data): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents: 97687
diff changeset
130 if (lim_data > 512U * 1024U * 1024U)
439bc48615be (get_lim_data): Fix last change.
Eli Zaretskii <eliz@gnu.org>
parents: 97687
diff changeset
131 lim_data = 512U * 1024U * 1024U;
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
132 }
100861
c089527800d9 (ret_lim_data) [MSDOS]: New function.
Eli Zaretskii <eliz@gnu.org>
parents: 99457
diff changeset
133
c089527800d9 (ret_lim_data) [MSDOS]: New function.
Eli Zaretskii <eliz@gnu.org>
parents: 99457
diff changeset
134 unsigned long
109480
d12162869c07 Convert some more functions to standard C.
Juanma Barranquero <lekktu@gmail.com>
parents: 109313
diff changeset
135 ret_lim_data (void)
100861
c089527800d9 (ret_lim_data) [MSDOS]: New function.
Eli Zaretskii <eliz@gnu.org>
parents: 99457
diff changeset
136 {
c089527800d9 (ret_lim_data) [MSDOS]: New function.
Eli Zaretskii <eliz@gnu.org>
parents: 99457
diff changeset
137 get_lim_data ();
c089527800d9 (ret_lim_data) [MSDOS]: New function.
Eli Zaretskii <eliz@gnu.org>
parents: 99457
diff changeset
138 return lim_data;
c089527800d9 (ret_lim_data) [MSDOS]: New function.
Eli Zaretskii <eliz@gnu.org>
parents: 99457
diff changeset
139 }
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
140 #else /* not MSDOS */
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
141 static void
109480
d12162869c07 Convert some more functions to standard C.
Juanma Barranquero <lekktu@gmail.com>
parents: 109313
diff changeset
142 get_lim_data (void)
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
143 {
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
144 lim_data = vlimit (LIM_DATA, -1);
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
145 }
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
146 #endif /* not MSDOS */
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
147
109575
ad36da121d41 * src/vm-limit.c: Do not include sys/resource.h, mem-limits.h does it.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109537
diff changeset
148 #else /* BSD4_2 || CYGWIN */
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
149
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
150 static void
109480
d12162869c07 Convert some more functions to standard C.
Juanma Barranquero <lekktu@gmail.com>
parents: 109313
diff changeset
151 get_lim_data (void)
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
152 {
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
153 struct rlimit XXrlimit;
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
154
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
155 getrlimit (RLIMIT_DATA, &XXrlimit);
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
156 #ifdef RLIM_INFINITY
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
157 lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
158 #else
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
159 lim_data = XXrlimit.rlim_cur; /* soft limit */
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
160 #endif
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
161 }
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
162 #endif /* BSD4_2 */
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
163 #endif /* not WINDOWSNT */
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
164 #endif /* not USG */
97252
c2be97b488c4 (get_lim_data) [HAVE_GETRLIMIT && RLIMIT_AS]: Define.
Andreas Schwab <schwab@suse.de>
parents: 97251
diff changeset
165 #endif /* not HAVE_GETRLIMIT */
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
166
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
167 /* Verify amount of memory available, complaining if we're near the end. */
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
168
1416
60bb5e719468 (morecore_with_warning): Removed.
Roland McGrath <roland@gnu.org>
parents: 1400
diff changeset
169 static void
109144
7dceae91724c Convert most remaining function definitions to standard C.
Juanma Barranquero <lekktu@gmail.com>
parents: 109097
diff changeset
170 check_memory_limits (void)
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
171 {
30062
9a026d470bc9 (check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents: 24366
diff changeset
172 #ifdef REL_ALLOC
109537
b8b5b9f67570 * vm-limit.c (check_memory_limits): Fix previous change; accidentally reverted an earlier change.
Ken Brown <kbrown@cornell.edu>
parents: 109536
diff changeset
173 extern POINTER (*real_morecore) (SIZE);
30062
9a026d470bc9 (check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents: 24366
diff changeset
174 #endif
109537
b8b5b9f67570 * vm-limit.c (check_memory_limits): Fix previous change; accidentally reverted an earlier change.
Ken Brown <kbrown@cornell.edu>
parents: 109536
diff changeset
175 extern POINTER (*__morecore) (SIZE);
1417
3a1576d52874 (check_memory_limits): Declare __morecore.
Roland McGrath <roland@gnu.org>
parents: 1416
diff changeset
176
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
177 register POINTER cp;
3935
cecc2b59e875 (check_memory_limits): Use unsigned long to hold memory size values.
Richard M. Stallman <rms@gnu.org>
parents: 1417
diff changeset
178 unsigned long five_percent;
cecc2b59e875 (check_memory_limits): Use unsigned long to hold memory size values.
Richard M. Stallman <rms@gnu.org>
parents: 1417
diff changeset
179 unsigned long data_size;
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
180 enum warnlevel new_warnlevel;
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
181
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
182 if (lim_data == 0)
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
183 get_lim_data ();
1392
ad64a94cd81c (morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 734
diff changeset
184 five_percent = lim_data / 20;
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
185
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
186 /* Find current end of memory and issue warning if getting near max */
30062
9a026d470bc9 (check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents: 24366
diff changeset
187 #ifdef REL_ALLOC
9a026d470bc9 (check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents: 24366
diff changeset
188 if (real_morecore)
9a026d470bc9 (check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents: 24366
diff changeset
189 cp = (char *) (*real_morecore) (0);
9a026d470bc9 (check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents: 24366
diff changeset
190 else
9a026d470bc9 (check_memory_limits) [REL_ALLOC]: Use real_morecore
Andrew Innes <andrewi@gnu.org>
parents: 24366
diff changeset
191 #endif
1416
60bb5e719468 (morecore_with_warning): Removed.
Roland McGrath <roland@gnu.org>
parents: 1400
diff changeset
192 cp = (char *) (*__morecore) (0);
1400
af08281c0cbe (warnfunction): Renamed to warn_function (was used inconsistently).
Roland McGrath <roland@gnu.org>
parents: 1398
diff changeset
193 data_size = (char *) cp - (char *) data_space_start;
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
194
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
195 if (!warn_function)
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
196 return;
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
197
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
198 /* What level of warning does current memory usage demand? */
97250
1533ce04b4b8 (check_memory_limits): Don't use getrlimit on cygwin. Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 94963
diff changeset
199 new_warnlevel
1533ce04b4b8 (check_memory_limits): Don't use getrlimit on cygwin. Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 94963
diff changeset
200 = (data_size > five_percent * 19) ? warned_95
1533ce04b4b8 (check_memory_limits): Don't use getrlimit on cygwin. Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 94963
diff changeset
201 : (data_size > five_percent * 17) ? warned_85
1533ce04b4b8 (check_memory_limits): Don't use getrlimit on cygwin. Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 94963
diff changeset
202 : (data_size > five_percent * 15) ? warned_75
1533ce04b4b8 (check_memory_limits): Don't use getrlimit on cygwin. Don't use
Chong Yidong <cyd@stupidchicken.com>
parents: 94963
diff changeset
203 : not_warned;
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
204
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
205 /* If we have gone up a level, give the appropriate warning. */
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
206 if (new_warnlevel > warnlevel || new_warnlevel == warned_95)
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
207 {
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
208 warnlevel = new_warnlevel;
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
209 switch (warnlevel)
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
210 {
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
211 case warned_75:
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
212 (*warn_function) ("Warning: past 75% of memory limit");
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
213 break;
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
214
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
215 case warned_85:
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
216 (*warn_function) ("Warning: past 85% of memory limit");
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
217 break;
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
218
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
219 case warned_95:
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
220 (*warn_function) ("Warning: past 95% of memory limit");
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
221 }
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
222 }
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
223 /* Handle going down in usage levels, with some hysteresis. */
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
224 else
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
225 {
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
226 /* If we go down below 70% full, issue another 75% warning
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
227 when we go up again. */
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
228 if (data_size < five_percent * 14)
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
229 warnlevel = not_warned;
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
230 /* If we go down below 80% full, issue another 85% warning
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
231 when we go up again. */
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
232 else if (warnlevel > warned_75 && data_size < five_percent * 16)
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
233 warnlevel = warned_75;
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
234 /* If we go down below 90% full, issue another 95% warning
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
235 when we go up again. */
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
236 else if (warnlevel > warned_85 && data_size < five_percent * 18)
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
237 warnlevel = warned_85;
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
238 }
1392
ad64a94cd81c (morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 734
diff changeset
239
ad64a94cd81c (morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 734
diff changeset
240 if (EXCEEDS_LISP_PTR (cp))
1400
af08281c0cbe (warnfunction): Renamed to warn_function (was used inconsistently).
Roland McGrath <roland@gnu.org>
parents: 1398
diff changeset
241 (*warn_function) ("Warning: memory in use exceeds lisp pointer size");
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
242 }
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
243
109168
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
244 #if !defined(CANNOT_DUMP) || !defined(SYSTEM_MALLOC)
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
245 /* Some systems that cannot dump also cannot implement these. */
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
246
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
247 /*
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
248 * Return the address of the start of the data segment prior to
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
249 * doing an unexec. After unexec the return value is undefined.
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
250 * See crt0.c for further information and definition of data_start.
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
251 *
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
252 * Apparently, on BSD systems this is etext at startup. On
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
253 * USG systems (swapping) this is highly mmu dependent and
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
254 * is also dependent on whether or not the program is running
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
255 * with shared text. Generally there is a (possibly large)
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
256 * gap between end of text and start of data with shared text.
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
257 *
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
258 */
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
259
109576
faeb6f3341b1 Fix some stuff that didn't compile.
Jan D. <jan.h.d@swipnet.se>
parents: 109575
diff changeset
260 char *
109168
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
261 start_of_data (void)
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
262 {
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
263 #ifdef BSD_SYSTEM
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
264 extern char etext;
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
265 return (POINTER)(&etext);
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
266 #elif defined DATA_START
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
267 return ((POINTER) DATA_START);
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
268 #elif defined ORDINARY_LINK
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
269 /*
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
270 * This is a hack. Since we're not linking crt0.c or pre_crt0.c,
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
271 * data_start isn't defined. We take the address of environ, which
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
272 * is known to live at or near the start of the system crt0.c, and
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
273 * we don't sweat the handful of bytes that might lose.
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
274 */
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
275 extern char **environ;
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
276 return ((POINTER) &environ);
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
277 #else
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
278 extern int data_start;
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
279 return ((POINTER) &data_start);
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
280 #endif
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
281 }
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
282 #endif /* (not CANNOT_DUMP or not SYSTEM_MALLOC) */
fb5779a6cf4b Simplify start_of_data, start_of_text and related code.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109145
diff changeset
283
69390
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
284 /* Enable memory usage warnings.
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
285 START says where the end of pure storage is.
7e58bc915ffe (get_lim_data, lim_data, data_space_start): Moved from mem-limits.h.
Richard M. Stallman <rms@gnu.org>
parents: 69019
diff changeset
286 WARNFUN specifies the function to call to issue a warning. */
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
287
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
288 void
109313
e856a274549b Constify functions taking char *
Andreas Schwab <schwab@linux-m68k.org>
parents: 109168
diff changeset
289 memory_warnings (POINTER start, void (*warnfun) (const char *))
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
290 {
109145
d0090a8b66c3 Convert function definitions and declarations to standard C.
Dan Nicolaescu <dann@ics.uci.edu>
parents: 109144
diff changeset
291 extern void (* __after_morecore_hook) (void); /* From gmalloc.c */
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
292
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
293 if (start)
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
294 data_space_start = start;
1392
ad64a94cd81c (morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 734
diff changeset
295 else
ad64a94cd81c (morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 734
diff changeset
296 data_space_start = start_of_data ();
ad64a94cd81c (morecore_with_warning): Reduce warnlevel when usage drops far enough.
Richard M. Stallman <rms@gnu.org>
parents: 734
diff changeset
297
1400
af08281c0cbe (warnfunction): Renamed to warn_function (was used inconsistently).
Roland McGrath <roland@gnu.org>
parents: 1398
diff changeset
298 warn_function = warnfun;
1416
60bb5e719468 (morecore_with_warning): Removed.
Roland McGrath <roland@gnu.org>
parents: 1400
diff changeset
299 __after_morecore_hook = check_memory_limits;
24366
274b79aeb3b7 (memory_warnings) [WINDOWSNT]: Reset lim_data on each
Andrew Innes <andrewi@gnu.org>
parents: 14186
diff changeset
300
274b79aeb3b7 (memory_warnings) [WINDOWSNT]: Reset lim_data on each
Andrew Innes <andrewi@gnu.org>
parents: 14186
diff changeset
301 /* Force data limit to be recalculated on each run. */
274b79aeb3b7 (memory_warnings) [WINDOWSNT]: Reset lim_data on each
Andrew Innes <andrewi@gnu.org>
parents: 14186
diff changeset
302 lim_data = 0;
734
64e152d639af entered into RCS
Joseph Arceneaux <jla@gnu.org>
parents:
diff changeset
303 }
52401
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
304
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
305 /* arch-tag: eab04eda-1f69-447a-8d9f-95f0a3983ca5
695cf19ef79e Add arch taglines
Miles Bader <miles@gnu.org>
parents: 49600
diff changeset
306 (do not change this comment) */