aboutsummaryrefslogtreecommitdiffstats
path: root/erts/emulator/hipe/hipe_amd64.c
diff options
context:
space:
mode:
authorMikael Pettersson <[email protected]>2015-01-11 16:48:20 +0100
committerMarcus Arendt <[email protected]>2015-01-26 15:57:04 +0100
commit3d41006a0e17d57fef4324c2a49c778f7a4a3390 (patch)
tree3bef60849913ccfabfc605a78d542cb955f70154 /erts/emulator/hipe/hipe_amd64.c
parent14d585fdcafad61a377feeba1035d6ddcfaf0248 (diff)
downloadotp-3d41006a0e17d57fef4324c2a49c778f7a4a3390.tar.gz
otp-3d41006a0e17d57fef4324c2a49c778f7a4a3390.tar.bz2
otp-3d41006a0e17d57fef4324c2a49c778f7a4a3390.zip
hipe: improve error handling at code allocation failure
Diffstat (limited to 'erts/emulator/hipe/hipe_amd64.c')
-rw-r--r--erts/emulator/hipe/hipe_amd64.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/erts/emulator/hipe/hipe_amd64.c b/erts/emulator/hipe/hipe_amd64.c
index 627ba7603d..63646825b2 100644
--- a/erts/emulator/hipe/hipe_amd64.c
+++ b/erts/emulator/hipe/hipe_amd64.c
@@ -125,7 +125,7 @@ static void atexit_alloc_code_stats(void)
#define MAP_ANONYMOUS MAP_ANON
#endif
-static void morecore(unsigned int alloc_bytes)
+static int morecore(unsigned int alloc_bytes)
{
unsigned int map_bytes;
char *map_hint, *map_start;
@@ -174,10 +174,9 @@ static void morecore(unsigned int alloc_bytes)
abort();
}
#endif
- if (map_start == MAP_FAILED) {
- perror("mmap");
- abort();
- }
+ if (map_start == MAP_FAILED)
+ return -1;
+
ALLOC_CODE_STATS(total_mapped += map_bytes);
/* Merge adjacent mappings, so the trailing portion of the previous
@@ -197,6 +196,8 @@ static void morecore(unsigned int alloc_bytes)
}
ALLOC_CODE_STATS(atexit_alloc_code_stats());
+
+ return 0;
}
static void *alloc_code(unsigned int alloc_bytes)
@@ -206,8 +207,8 @@ static void *alloc_code(unsigned int alloc_bytes)
/* Align function entries. */
alloc_bytes = (alloc_bytes + 3) & ~3;
- if (code_bytes < alloc_bytes)
- morecore(alloc_bytes);
+ if (code_bytes < alloc_bytes && morecore(alloc_bytes) != 0)
+ return NULL;
ALLOC_CODE_STATS(++nr_allocs);
ALLOC_CODE_STATS(total_alloc += alloc_bytes);
res = code_next;
@@ -252,6 +253,8 @@ void *hipe_make_native_stub(void *callee_exp, unsigned int beamArity)
((P_CALLEE_EXP + 4) >= 128 ? 3 : 0) +
(P_ARITY >= 128 ? 3 : 0);
codep = code = alloc_code(codeSize);
+ if (!code)
+ return NULL;
/* movl $callee_exp, P_CALLEE_EXP(%ebp); 3 or 6 bytes, plus 4 */
codep[0] = 0xc7;