1 /* -*-C-*-
2 
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994,
4     1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
5     2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Massachusetts
6     Institute of Technology
7 
8 This file is part of MIT/GNU Scheme.
9 
10 MIT/GNU Scheme is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or (at
13 your option) any later version.
14 
15 MIT/GNU Scheme is distributed in the hope that it will be useful, but
16 WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 General Public License for more details.
19 
20 You should have received a copy of the GNU General Public License
21 along with MIT/GNU Scheme; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301,
23 USA.
24 
25 */
26 
27 /* Memory management */
28 
29 #ifndef SCM_MEMMAG_H
30 #define SCM_MEMMAG_H 1
31 
32 /* Overflow detection, various cases */
33 
34 #define GC_ENABLED_P() (INTERRUPT_ENABLED_P (INT_GC))
35 
36 #define HEAP_AVAILABLE							\
37   ((unsigned long) ((FREE_OK_P (Free)) ? (heap_alloc_limit - Free) : 0))
38 
39 #define FREE_OK_P(free)							\
40   (((free) >= heap_start) && ((free) < heap_alloc_limit))
41 
42 #define HEAP_AVAILABLE_P(n_words)					\
43   ((FREE_OK_P (Free)) && ((Free + (n_words)) <= heap_alloc_limit))
44 
45 #define GC_NEEDED_P(n_words)						\
46   ((!HEAP_AVAILABLE_P (n_words)) && (GC_ENABLED_P ()))
47 
48 #define SPACE_BEFORE_GC()						\
49   ((GC_ENABLED_P ())							\
50    ? HEAP_AVAILABLE							\
51    : (ADDRESS_IN_HEAP_P (Free))						\
52    ? ((unsigned long) (heap_end - Free))				\
53    : 0)
54 
55 #define REQUEST_GC(n_words) do						\
56 {									\
57   REQUEST_INTERRUPT (INT_GC);						\
58   gc_space_needed = (n_words);						\
59 } while (0)
60 
61 #define RESET_HEAP_ALLOC_LIMIT() do					\
62 {									\
63   heap_alloc_limit = (heap_end - heap_reserved);			\
64   COMPILER_SETUP_INTERRUPT ();						\
65 } while (0)
66 
67 #define ARG_HEAP_RESERVED(n)						\
68   (arg_ulong_index_integer ((n), ((heap_end - heap_start) / 2)))
69 
70 #define ADDRESS_IN_MEMORY_BLOCK_P(address)				\
71   (((address) >= memory_block_start) && ((address) < memory_block_end))
72 
73 #define ADDRESS_IN_HEAP_P(address)					\
74   (((address) >= heap_start) && ((address) < heap_end))
75 
76 #define ADDRESS_IN_STACK_P(address)					\
77   (((address) >= stack_start) && ((address) < stack_end))
78 
79 #define ADDRESS_IN_CONSTANT_P(address)					\
80   (((address) >= constant_start) && ((address) < constant_end))
81 
82 /* buffer for impurify, etc. */
83 #ifndef CONSTANT_SPACE_FUDGE
84 #  define CONSTANT_SPACE_FUDGE 128
85 #endif
86 
87 extern bool allocations_ok_p (unsigned long, unsigned long, unsigned long);
88 extern void reset_allocator_parameters (unsigned long, unsigned long);
89 extern bool object_in_heap_p (SCHEME_OBJECT);
90 extern void std_gc_pt1 (void);
91 extern void std_gc_pt2 (void);
92 extern void stack_death (const char *) NORETURN;
93 
94 #endif /* SCM_MEMMAG_H */
95