@@ -105,7 +105,8 @@ static const uint BLOCK_SIZES[] = {
105105 8 , /* for instr bits */
106106#ifndef X64
107107 /* for x64 future_fragment_t is 24 bytes (could be 20 if we could put flags last) */
108- sizeof (future_fragment_t ), /* 12 (24 x64) */
108+ ALIGN_FORWARD (sizeof (future_fragment_t ), /* 12 (24 x64) */
109+ HEAP_ALIGNMENT ),
109110#endif
110111 /* we have a lot of size 16 requests for IR but they are transient */
111112 24 , /* fcache empties and vm_area_t are now 20, vm area extras still 24 */
@@ -119,8 +120,9 @@ static const uint BLOCK_SIZES[] = {
119120 sizeof (instr_t ), /* 112 x64 */
120121# endif
121122#else
122- sizeof (fragment_t ) + sizeof (direct_linkstub_t ) +
123- sizeof (cbr_fallthrough_linkstub_t ), /* 60 dbg / 56 rel */
123+ ALIGN_FORWARD (sizeof (fragment_t ) + sizeof (direct_linkstub_t ) +
124+ sizeof (cbr_fallthrough_linkstub_t ), /* 60 dbg / 56 rel */
125+ HEAP_ALIGNMENT ),
124126# ifndef DEBUG
125127 sizeof (instr_t ), /* 72 */
126128# endif
@@ -156,11 +158,21 @@ DECLARE_NEVERPROT_VAR(static int block_peak_align_pad[BLOCK_TYPES], { 0 });
156158DECLARE_NEVERPROT_VAR (static bool out_of_vmheap_once , false);
157159#endif
158160
159- /* variable-length: we steal one int for the size */
160- #define HEADER_SIZE (sizeof(size_t))
161+ /* The size of a variable-size allocation is stored as a size_t in the header.
162+ * On 32-bit ARM, HEAP_ALIGNMENT is twice the size of a size_t but the wasted
163+ * space for DR's own use is not expected to be significant as only allocs
164+ * that do not fit in the buckets use headers. Client heap allocations
165+ * probably bear the biggest hit.
166+ */
167+ #define HEADER_SIZE HEAP_ALIGNMENT
161168/* VARIABLE_SIZE is assignable */
162169#define VARIABLE_SIZE (p ) (*(size_t *)((p)-HEADER_SIZE))
163- #define MEMSET_HEADER (p , value ) VARIABLE_SIZE(p) = HEAP_TO_PTR_UINT(value)
170+ #define MEMSET_HEADER (p , value ) \
171+ do { \
172+ ASSERT(HEADER_SIZE % sizeof(VARIABLE_SIZE(p)) == 0); \
173+ for (size_t k = 0; k < HEADER_SIZE / sizeof(VARIABLE_SIZE(p)); k++) \
174+ (&VARIABLE_SIZE(p))[k] = HEAP_TO_PTR_UINT(value); \
175+ } while (0)
164176#define GET_VARIABLE_ALLOCATION_SIZE (p ) (VARIABLE_SIZE(p) + HEADER_SIZE)
165177
166178/* The heap is allocated in units.
0 commit comments