@@ -23,6 +23,7 @@ struct hwloc_shmem_header {
23
23
uint32_t header_length ; /* where the actual topology starts in the file/mapping */
24
24
uint64_t mmap_address ; /* virtual address to pass to mmap */
25
25
uint64_t mmap_length ; /* length to pass to mmap (includes the header) */
26
+ /* we will pad the end to a multiple of pointer size so that the topology is well aligned */
26
27
};
27
28
28
29
#define HWLOC_SHMEM_MALLOC_ALIGN 8UL
@@ -85,6 +86,7 @@ hwloc_shmem_topology_write(hwloc_topology_t topology,
85
86
hwloc_topology_t new ;
86
87
struct hwloc_tma tma ;
87
88
struct hwloc_shmem_header header ;
89
+ uint32_t header_length = (sizeof (header ) + sizeof (void * ) - 1 ) & ~(sizeof (void * ) - 1 ); /* pad to a multiple of pointer size */
88
90
void * mmap_res ;
89
91
int err ;
90
92
@@ -100,7 +102,7 @@ hwloc_shmem_topology_write(hwloc_topology_t topology,
100
102
hwloc_internal_memattrs_refresh (topology );
101
103
102
104
header .header_version = HWLOC_SHMEM_HEADER_VERSION ;
103
- header .header_length = sizeof ( header ) ;
105
+ header .header_length = header_length ;
104
106
header .mmap_address = (uintptr_t ) mmap_address ;
105
107
header .mmap_length = length ;
106
108
@@ -127,7 +129,7 @@ hwloc_shmem_topology_write(hwloc_topology_t topology,
127
129
128
130
tma .malloc = tma_shmem_malloc ;
129
131
tma .dontfree = 1 ;
130
- tma .data = (char * )mmap_res + sizeof ( header ) ;
132
+ tma .data = (char * )mmap_res + header_length ;
131
133
err = hwloc__topology_dup (& new , topology , & tma );
132
134
if (err < 0 )
133
135
return err ;
@@ -154,6 +156,7 @@ hwloc_shmem_topology_adopt(hwloc_topology_t *topologyp,
154
156
{
155
157
hwloc_topology_t new , old ;
156
158
struct hwloc_shmem_header header ;
159
+ uint32_t header_length = (sizeof (header ) + sizeof (void * ) - 1 ) & ~(sizeof (void * ) - 1 ); /* pad to a multiple of pointer size */
157
160
void * mmap_res ;
158
161
int err ;
159
162
@@ -171,7 +174,7 @@ hwloc_shmem_topology_adopt(hwloc_topology_t *topologyp,
171
174
return -1 ;
172
175
173
176
if (header .header_version != HWLOC_SHMEM_HEADER_VERSION
174
- || header .header_length != sizeof ( header )
177
+ || header .header_length != header_length
175
178
|| header .mmap_address != (uintptr_t ) mmap_address
176
179
|| header .mmap_length != length ) {
177
180
errno = EINVAL ;
@@ -186,7 +189,7 @@ hwloc_shmem_topology_adopt(hwloc_topology_t *topologyp,
186
189
goto out_with_mmap ;
187
190
}
188
191
189
- old = (hwloc_topology_t )((char * )mmap_address + sizeof ( header ) );
192
+ old = (hwloc_topology_t )((char * )mmap_address + header_length );
190
193
if (hwloc_topology_abi_check (old ) < 0 ) {
191
194
errno = EINVAL ;
192
195
goto out_with_mmap ;
0 commit comments