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_sparc.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_sparc.c')
-rw-r--r-- | erts/emulator/hipe/hipe_sparc.c | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/erts/emulator/hipe/hipe_sparc.c b/erts/emulator/hipe/hipe_sparc.c index 2052aa8498..fea3b623a9 100644 --- a/erts/emulator/hipe/hipe_sparc.c +++ b/erts/emulator/hipe/hipe_sparc.c @@ -130,7 +130,7 @@ static void atexit_alloc_code_stats(void) #define ALLOC_CODE_STATS(X) do{}while(0) #endif -static void morecore(unsigned int alloc_bytes) +static int morecore(unsigned int alloc_bytes) { unsigned int map_bytes; char *map_hint, *map_start; @@ -158,10 +158,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 @@ -177,6 +176,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) @@ -186,8 +187,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; @@ -211,6 +212,8 @@ void *hipe_make_native_stub(void *callee_exp, unsigned int beamArity) int i; code = alloc_code(5*sizeof(int)); + if (!code) + return NULL; /* sethi %hi(Address), %i4 */ code[0] = 0x39000000 | (((unsigned int)callee_exp >> 10) & 0x3FFFFF); |