diff options
author | Mikael Pettersson <[email protected]> | 2015-01-11 16:48:20 +0100 |
---|---|---|
committer | Marcus Arendt <[email protected]> | 2015-01-26 15:57:04 +0100 |
commit | 3d41006a0e17d57fef4324c2a49c778f7a4a3390 (patch) | |
tree | 3bef60849913ccfabfc605a78d542cb955f70154 /erts/emulator/hipe/hipe_x86.c | |
parent | 14d585fdcafad61a377feeba1035d6ddcfaf0248 (diff) | |
download | otp-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_x86.c')
-rw-r--r-- | erts/emulator/hipe/hipe_x86.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/erts/emulator/hipe/hipe_x86.c b/erts/emulator/hipe/hipe_x86.c index 314f6b597c..998905ea63 100644 --- a/erts/emulator/hipe/hipe_x86.c +++ b/erts/emulator/hipe/hipe_x86.c @@ -108,7 +108,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; @@ -136,10 +136,9 @@ static void morecore(unsigned int alloc_bytes) #endif , -1, 0); - 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 @@ -155,6 +154,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) @@ -164,8 +165,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; @@ -207,6 +208,8 @@ void *hipe_make_native_stub(void *callee_exp, unsigned int beamArity) (P_CALLEE_EXP >= 128 ? 3 : 0) + (P_ARITY >= 128 ? 3 : 0); codep = code = alloc_code(codeSize); + if (!code) + return NULL; /* movl $beamAddress, P_CALLEE_EXP(%ebp); 3 or 6 bytes, plus 4 */ codep[0] = 0xc7; |