summaryrefslogtreecommitdiff
path: root/mem.c
diff options
context:
space:
mode:
authorMichael Pavone <pavone@retrodev.com>2015-07-21 21:29:43 -0700
committerMichael Pavone <pavone@retrodev.com>2015-07-21 21:29:43 -0700
commit5aa414e068c120a74a1f42e8e7de8692e8c1a55a (patch)
tree858e90960fcea73932749bf74d17ed0659f83078 /mem.c
parente7b2812fbdb135338db7a5bade0db8a16dc772b2 (diff)
Better error handling in alloc_code
Diffstat (limited to 'mem.c')
-rw-r--r--mem.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/mem.c b/mem.c
index 048f751..c9bb75a 100644
--- a/mem.c
+++ b/mem.c
@@ -8,6 +8,8 @@
#include <stdint.h>
#include <stdlib.h>
#include <unistd.h>
+#include <errno.h>
+#include <stdio.h>
#include "mem.h"
#ifndef MAP_ANONYMOUS
@@ -25,6 +27,10 @@ void * alloc_code(size_t *size)
static uint8_t *next = (uint8_t *)0x40000000;
*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);
+ if (ret == MAP_FAILED) {
+ perror("alloc_code");
+ return NULL;
+ }
next = ret + *size;
return ret;
}