summaryrefslogtreecommitdiff
path: root/mem.c
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2015-11-13 19:15:37 -0800
committerMichael Pavone <pavone@retrodev.com>2015-11-13 19:15:37 -0800
commit802454482c2843234a19a06f6acce360e0be3d60 (patch)
tree5b64111a903c93c75789390121965c055da45dd9 /mem.c
parent3834192b16663bb4bf5098df5b7a053e9c9dd086 (diff)
It is now possible to switch back and forth between the menu ROM and the game
Diffstat (limited to 'mem.c')
-rw-r--r--mem.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/mem.c b/mem.c
index c9bb75a..b801bea 100644
--- a/mem.c
+++ b/mem.c
@@ -1,6 +1,6 @@
/*
Copyright 2013 Michael Pavone
- This file is part of BlastEm.
+ This file is part of BlastEm.
BlastEm is free software distributed under the terms of the GNU General Public License version 3 or greater. See COPYING for full license text.
*/
#include <sys/mman.h>
@@ -12,6 +12,7 @@
#include <stdio.h>
#include "mem.h"
+#include "arena.h"
#ifndef MAP_ANONYMOUS
#define MAP_ANONYMOUS MAP_ANON
#endif
@@ -25,8 +26,12 @@ void * alloc_code(size_t *size)
//start at the 1GB mark to allow plenty of room for sbrk based malloc implementations
//while still keeping well within 32-bit displacement range for calling code compiled into the executable
static uint8_t *next = (uint8_t *)0x40000000;
+ uint8_t *ret = try_alloc_arena();
+ if (ret) {
+ return ret;
+ }
*size += PAGE_SIZE - (*size & (PAGE_SIZE - 1));
- uint8_t *ret = mmap(NULL, *size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0);
+ ret = mmap(NULL, *size, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_32BIT, -1, 0);
if (ret == MAP_FAILED) {
perror("alloc_code");
return NULL;