# HG changeset patch # User Michael Pavone # Date 1437539383 25200 # Node ID c3e3a0d734e2bc2b9dc3cfee2e5ecb27aa4a3b37 # Parent e64975fc5f98405f5a03c11cd2655fa6a4cd47bf Better error handling in alloc_code diff -r e64975fc5f98 -r c3e3a0d734e2 mem.c --- a/mem.c Tue Jul 21 00:52:21 2015 -0700 +++ b/mem.c Tue Jul 21 21:29:43 2015 -0700 @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include "mem.h" #ifndef MAP_ANONYMOUS @@ -25,6 +27,10 @@ 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; }