aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoseph Arceneaux1992-06-30 22:41:21 +0000
committerJoseph Arceneaux1992-06-30 22:41:21 +0000
commit94d7c01aae32fcedca09c23baa0cf4d02f177455 (patch)
tree5ff54e61362537e19b03ef4436c24adad96a33d8
parentd8cafeb502e38d57a368708031d96cab3a8f58e6 (diff)
downloademacs-94d7c01aae32fcedca09c23baa0cf4d02f177455.tar.gz
emacs-94d7c01aae32fcedca09c23baa0cf4d02f177455.zip
entered into RCS
-rw-r--r--src/mem-limits.h3
-rw-r--r--src/ralloc.c1
-rw-r--r--src/vm-limit.c117
3 files changed, 120 insertions, 1 deletions
diff --git a/src/mem-limits.h b/src/mem-limits.h
index fe310542f2c..172f5dd1df1 100644
--- a/src/mem-limits.h
+++ b/src/mem-limits.h
@@ -44,14 +44,17 @@ typedef unsigned long SIZE;
44 44
45#ifdef emacs 45#ifdef emacs
46extern POINTER start_of_data (); 46extern POINTER start_of_data ();
47#define EXCEEDS_ELISP_PTR(ptr) ((unsigned int) (ptr) >> VALBITS)
47 48
48#ifdef BSD 49#ifdef BSD
49#ifndef DATA_SEG_BITS 50#ifndef DATA_SEG_BITS
51extern char etext;
50#define start_of_data() &etext 52#define start_of_data() &etext
51#endif 53#endif
52#endif 54#endif
53 55
54#else /* Not emacs */ 56#else /* Not emacs */
57extern char etext;
55#define start_of_data() &etext 58#define start_of_data() &etext
56#endif /* Not emacs */ 59#endif /* Not emacs */
57 60
diff --git a/src/ralloc.c b/src/ralloc.c
index 927c2dd5477..aceac44b938 100644
--- a/src/ralloc.c
+++ b/src/ralloc.c
@@ -52,7 +52,6 @@ static POINTER page_break_value;
52#define ALIGNED(addr) (((unsigned int) (addr) & (PAGE - 1)) == 0) 52#define ALIGNED(addr) (((unsigned int) (addr) & (PAGE - 1)) == 0)
53#define ROUNDUP(size) (((unsigned int) (size) + PAGE) & ~(PAGE - 1)) 53#define ROUNDUP(size) (((unsigned int) (size) + PAGE) & ~(PAGE - 1))
54#define ROUND_TO_PAGE(addr) (addr & (~(PAGE - 1))) 54#define ROUND_TO_PAGE(addr) (addr & (~(PAGE - 1)))
55#define EXCEEDS_ELISP_PTR(ptr) ((unsigned int) (ptr) >> VALBITS)
56 55
57/* Managing "almost out of memory" warnings. */ 56/* Managing "almost out of memory" warnings. */
58 57
diff --git a/src/vm-limit.c b/src/vm-limit.c
new file mode 100644
index 00000000000..496e392e5b0
--- /dev/null
+++ b/src/vm-limit.c
@@ -0,0 +1,117 @@
1/* Functions for memory limit warnings.
2 Copyright (C) 1990 Free Software Foundation, Inc.
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
8the Free Software Foundation; either version 1, or (at your option)
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
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*/
30static int warnlevel;
31
32/* Function to call to issue a warning;
33 0 means don't issue them. */
34static void (*warnfunction) ();
35
36extern POINTER sbrk ();
37
38/* Get more memory space, complaining if we're near the end. */
39
40static POINTER
41morecore_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
104void
105malloc_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}