From 5aa414e068c120a74a1f42e8e7de8692e8c1a55a Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Tue, 21 Jul 2015 21:29:43 -0700 Subject: Better error handling in alloc_code --- mem.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'mem.c') diff --git a/mem.c b/mem.c index 048f751..c9bb75a 100644 --- a/mem.c +++ b/mem.c @@ -8,6 +8,8 @@ #include #include #include +#include +#include #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; } -- cgit v1.2.3