4 CACAOVM - Verein zu Foerderung der freien virtuellen Machine CACAO
6 This file is part of CACAO.
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2, or (at
11 your option) any later version.
13 This program is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 #include "vm/global.h"
32 static const int TLH_MAX_SIZE = (20 * 1024 * 1024);
34 static inline bool tlh_avail(tlh_t *tlh, unsigned n) {
41 return (tlh->top + n) <= tlh->end;
44 void tlh_init(tlh_t *tlh) {
50 MAP_ANONYMOUS|MAP_PRIVATE,
55 if (heap == MAP_FAILED) {
56 /* The top pointer points to end, so all allocations will fail. */
62 tlh->start = (uint8_t *)heap;
63 tlh->top = tlh->start;
64 tlh->base = tlh->start;
65 tlh->end = tlh->start + TLH_MAX_SIZE;
71 void tlh_destroy(tlh_t *tlh) {
72 int res = munmap(tlh->start, TLH_MAX_SIZE);
83 void tlh_add_frame(tlh_t *tlh) {
84 if (tlh_avail(tlh, SIZEOF_VOID_P)) {
85 *(uint8_t **)tlh->top = tlh->base;
87 tlh->top += SIZEOF_VOID_P;
93 void tlh_remove_frame(tlh_t *tlh) {
94 if (tlh->overflows > 0) {
98 tlh->base = *(uint8_t **)tlh->top;
102 void *tlh_alloc(tlh_t *tlh, size_t size) {
104 if (tlh_avail(tlh, size)) {
114 * These are local overrides for various environment variables in Emacs.
115 * Please do not remove this and leave it at the end of the file, where
116 * Emacs will automagically detect them.
117 * ---------------------------------------------------------------------
120 * indent-tabs-mode: t
124 * vim:noexpandtab:sw=4:ts=4: