734
|
1 /* Functions for memory limit warnings.
|
|
2 Copyright (C) 1990 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 1, 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 #include "config.h"
|
|
21 #include "lisp.h"
|
|
22 #include "mem_limits.h"
|
|
23
|
|
24 /*
|
|
25 Level number of warnings already issued.
|
|
26 0 -- no warnings issued.
|
|
27 1 -- 75% warning already issued.
|
|
28 2 -- 85% warning already issued.
|
|
29 */
|
|
30 static int warnlevel;
|
|
31
|
|
32 /* Function to call to issue a warning;
|
|
33 0 means don't issue them. */
|
|
34 static void (*warnfunction) ();
|
|
35
|
|
36 extern POINTER sbrk ();
|
|
37
|
|
38 /* Get more memory space, complaining if we're near the end. */
|
|
39
|
|
40 static POINTER
|
|
41 morecore_with_warning (size)
|
|
42 register int size;
|
|
43 {
|
|
44 POINTER result;
|
|
45 register POINTER cp;
|
|
46 register unsigned int siz;
|
|
47
|
|
48 if (!data_space_start)
|
|
49 {
|
|
50 data_space_start = start_of_data ();
|
|
51 }
|
|
52
|
|
53 if (lim_data == 0)
|
|
54 get_lim_data ();
|
|
55
|
|
56 /* Find current end of memory and issue warning if getting near max */
|
|
57 cp = sbrk (0);
|
|
58 siz = cp - data_space_start;
|
|
59
|
|
60 if (warnfunction)
|
|
61 switch (warnlevel)
|
|
62 {
|
|
63 case 0:
|
|
64 if (siz > (lim_data / 4) * 3)
|
|
65 {
|
|
66 warnlevel++;
|
|
67 (*warnfunction) ("Warning: past 75% of memory limit");
|
|
68 }
|
|
69 break;
|
|
70
|
|
71 case 1:
|
|
72 if (siz > (lim_data / 20) * 17)
|
|
73 {
|
|
74 warnlevel++;
|
|
75 (*warnfunction) ("Warning: past 85% of memory limit");
|
|
76 }
|
|
77 break;
|
|
78
|
|
79 case 2:
|
|
80 if (siz > (lim_data / 20) * 19)
|
|
81 {
|
|
82 warnlevel++;
|
|
83 (*warnfunction) ("Warning: past 95% of memory limit");
|
|
84 }
|
|
85 break;
|
|
86
|
|
87 default:
|
|
88 (*warnfunction) ("Warning: past acceptable memory limits");
|
|
89 break;
|
|
90 }
|
|
91
|
|
92 if (EXCEEDS_ELISP_PTR (cp))
|
|
93 (*warnfunction) ("Warning: memory in use exceeds lisp pointer size");
|
|
94
|
|
95 result = sbrk (size);
|
|
96 if (result == (POINTER) -1)
|
|
97 return NULL;
|
|
98 return result;
|
|
99 }
|
|
100
|
|
101 /* Cause reinitialization based on job parameters;
|
|
102 also declare where the end of pure storage is. */
|
|
103
|
|
104 void
|
|
105 malloc_init (start, warnfun)
|
|
106 POINTER start;
|
|
107 void (*warnfun) ();
|
|
108 {
|
|
109 extern POINTER (* __morecore) (); /* From gmalloc.c */
|
|
110
|
|
111 if (start)
|
|
112 data_space_start = start;
|
|
113 lim_data = 0;
|
|
114 warnlevel = 0;
|
|
115 warnfunction = warnfun;
|
|
116 __morecore = &morecore_with_warning;
|
|
117 }
|