|
42 | 42 | * |Offset | Content | Description |
|
43 | 43 | * |------------------------------------------------------------
|
44 | 44 | * |base_addr | 0xABABABABABABABAB | Head guard |
|
45 |
| - * |+16 | <size_t:user_size> | User data size | |
46 |
| - * |+sizeof(uintptr_t) | <tag> | Tag word | |
47 |
| - * |+sizeof(uintptr_t) | <tag2> | Tag word | |
| 45 | + * |+GUARD_SIZE | <size_t:user_size> | User data size | |
| 46 | + * |+sizeof(size_t) | <tag> | Tag word | |
| 47 | + * |+sizeof(void*) | <tag2> | Tag word | |
| 48 | + * |+sizeof(void*) | <pad bytes> | Padding | |
48 | 49 | * |+sizeof(void*) | 0xF1 <user_data> ( | User data |
|
49 | 50 | * |+user_size | 0xABABABABABABABAB | Tail guard |
|
50 | 51 | * -------------------------------------------------------------
|
51 | 52 | *
|
52 | 53 | * Where:
|
53 | 54 | * - guard padding uses "badResourceValue" (0xAB)
|
54 | 55 | * - tag word and tag2 word are general purpose
|
| 56 | + * - padding is inserted as-needed by the compiler to ensure |
| 57 | + * the user data is aligned on a 16-byte boundary |
55 | 58 | * - user data
|
56 | 59 | * -- initially padded with "uninitBlockPad" (0xF1),
|
57 | 60 | * -- to "freeBlockPad" (0xBA), when freed
|
@@ -132,12 +135,15 @@ class GuardedMemory : StackObj { // Wrapper on stack
|
132 | 135 |
|
133 | 136 | /**
|
134 | 137 | * Header guard and size
|
| 138 | + * |
| 139 | + * NB: the size and placement of the GuardHeader must be such that the |
| 140 | + * user-ptr is maximally aligned i.e. 16-byte alignment for x86 ABI for |
| 141 | + * stack alignment and use of vector (xmm) instructions. We use alignas |
| 142 | + * to achieve this. |
135 | 143 | */
|
136 |
| - class GuardHeader : Guard { |
| 144 | + class alignas(16) GuardHeader : Guard { |
137 | 145 | friend class GuardedMemory;
|
138 | 146 | protected:
|
139 |
| - // Take care in modifying fields here, will effect alignment |
140 |
| - // e.g. x86 ABI 16 byte stack alignment |
141 | 147 | union {
|
142 | 148 | uintptr_t __unused_full_word1;
|
143 | 149 | size_t _user_size;
|
|
0 commit comments