diff options
author | Magnus Lång <[email protected]> | 2017-03-24 16:23:52 +0100 |
---|---|---|
committer | Sverker Eriksson <[email protected]> | 2017-03-27 17:31:11 +0200 |
commit | 29bf1c9b7f33d64871c0f973be4a732850d98572 (patch) | |
tree | ea6b3f0465e28c4eab693ca2241bc025a7e1d4ba | |
parent | a603a15503c6e11290c354c8c5c18578ccd8acff (diff) | |
download | otp-29bf1c9b7f33d64871c0f973be4a732850d98572.tar.gz otp-29bf1c9b7f33d64871c0f973be4a732850d98572.tar.bz2 otp-29bf1c9b7f33d64871c0f973be4a732850d98572.zip |
Make hipe_bifs:alloc_data/3 pad addr to alignment
7814ec18b made hipe_bifs:alloc_data/3 expect alignments greater than 8
from erts_alloc(), which is not something that it guarantees. Fix it up
so that it pads the allocation up to the required alignment, in case it
does not initially satisfy the alignment requirement.
-rw-r--r-- | erts/emulator/hipe/hipe_bif0.c | 19 |
1 files changed, 8 insertions, 11 deletions
diff --git a/erts/emulator/hipe/hipe_bif0.c b/erts/emulator/hipe/hipe_bif0.c index 4babb2db4e..8b420b9e9b 100644 --- a/erts/emulator/hipe/hipe_bif0.c +++ b/erts/emulator/hipe/hipe_bif0.c @@ -447,6 +447,7 @@ BIF_RETTYPE hipe_bifs_alloc_data_3(BIF_ALIST_3) { Uint align; HipeLoaderState *stp; + void *aligned_block; if (is_not_small(BIF_ARG_1) || is_not_small(BIF_ARG_2) || (!(stp = get_loader_state(BIF_ARG_3))) || @@ -459,18 +460,14 @@ BIF_RETTYPE hipe_bifs_alloc_data_3(BIF_ALIST_3) stp->data_segment_size = unsigned_val(BIF_ARG_2); if (stp->data_segment_size == 0) BIF_RET(make_small(0)); + + stp->data_segment_size += align-1; /* Make room to align the pointer */ stp->data_segment = erts_alloc(ERTS_ALC_T_HIPE_LL, stp->data_segment_size); - if ((unsigned long)stp->data_segment & (align-1)) { - fprintf(stderr, "%s: erts_alloc(%lu) returned %p which is not %lu-byte " - "aligned\r\n", - __FUNCTION__, (unsigned long)stp->data_segment_size, - stp->data_segment, (unsigned long)align); - erts_free(ERTS_ALC_T_HIPE_LL, stp->data_segment); - stp->data_segment = NULL; - stp->data_segment_size = 0; - BIF_ERROR(BIF_P, EXC_NOTSUP); - } - BIF_RET(address_to_term(stp->data_segment, BIF_P)); + + /* Align the pointer */ + aligned_block = (void*)((UWord)(stp->data_segment + align - 1) + & ~(UWord)(align-1)); + BIF_RET(address_to_term(aligned_block, BIF_P)); } /* |