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
26 #include "mm/memory.h"
29 #include "vm/global.h"
34 static const int TLH_MAX_SIZE = (20 * 1024 * 1024);
36 static inline bool tlh_avail(tlh_t *tlh, unsigned n) {
43 return (tlh->top + n) <= tlh->end;
46 void tlh_init(tlh_t *tlh) {
52 MAP_ANONYMOUS|MAP_PRIVATE,
57 if (heap == MAP_FAILED) {
58 /* The top pointer points to end, so all allocations will fail. */
64 tlh->start = (uint8_t *)heap;
65 tlh->top = tlh->start;
66 tlh->base = tlh->start;
67 tlh->end = tlh->start + TLH_MAX_SIZE;
73 void tlh_destroy(tlh_t *tlh) {
74 int res = munmap(tlh->start, TLH_MAX_SIZE);
85 void tlh_add_frame(tlh_t *tlh) {
86 if (tlh_avail(tlh, SIZEOF_VOID_P)) {
87 *(uint8_t **)tlh->top = tlh->base;
89 tlh->top += SIZEOF_VOID_P;
95 void tlh_remove_frame(tlh_t *tlh) {
96 if (tlh->overflows > 0) {
100 tlh->base = *(uint8_t **)tlh->top;
104 void *tlh_alloc(tlh_t *tlh, size_t size) {
106 if (tlh_avail(tlh, size)) {
109 MZERO(ret, char, size);
117 * These are local overrides for various environment variables in Emacs.
118 * Please do not remove this and leave it at the end of the file, where
119 * Emacs will automagically detect them.
120 * ---------------------------------------------------------------------
123 * indent-tabs-mode: t
127 * vim:noexpandtab:sw=4:ts=4: