Skip to content

Commit 69404b7

Browse files
authored
Merge pull request #617 from bgoglin/cheri
Fixes for 128bit pointers on the CHERI architecture
2 parents ea7f6ba + 43ad0c9 commit 69404b7

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

hwloc/shmem.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ struct hwloc_shmem_header {
2323
uint32_t header_length; /* where the actual topology starts in the file/mapping */
2424
uint64_t mmap_address; /* virtual address to pass to mmap */
2525
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 */
2627
};
2728

2829
#define HWLOC_SHMEM_MALLOC_ALIGN 8UL
@@ -85,6 +86,7 @@ hwloc_shmem_topology_write(hwloc_topology_t topology,
8586
hwloc_topology_t new;
8687
struct hwloc_tma tma;
8788
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 */
8890
void *mmap_res;
8991
int err;
9092

@@ -100,7 +102,7 @@ hwloc_shmem_topology_write(hwloc_topology_t topology,
100102
hwloc_internal_memattrs_refresh(topology);
101103

102104
header.header_version = HWLOC_SHMEM_HEADER_VERSION;
103-
header.header_length = sizeof(header);
105+
header.header_length = header_length;
104106
header.mmap_address = (uintptr_t) mmap_address;
105107
header.mmap_length = length;
106108

@@ -127,7 +129,7 @@ hwloc_shmem_topology_write(hwloc_topology_t topology,
127129

128130
tma.malloc = tma_shmem_malloc;
129131
tma.dontfree = 1;
130-
tma.data = (char *)mmap_res + sizeof(header);
132+
tma.data = (char *)mmap_res + header_length;
131133
err = hwloc__topology_dup(&new, topology, &tma);
132134
if (err < 0)
133135
return err;
@@ -154,6 +156,7 @@ hwloc_shmem_topology_adopt(hwloc_topology_t *topologyp,
154156
{
155157
hwloc_topology_t new, old;
156158
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 */
157160
void *mmap_res;
158161
int err;
159162

@@ -171,7 +174,7 @@ hwloc_shmem_topology_adopt(hwloc_topology_t *topologyp,
171174
return -1;
172175

173176
if (header.header_version != HWLOC_SHMEM_HEADER_VERSION
174-
|| header.header_length != sizeof(header)
177+
|| header.header_length != header_length
175178
|| header.mmap_address != (uintptr_t) mmap_address
176179
|| header.mmap_length != length) {
177180
errno = EINVAL;
@@ -186,7 +189,7 @@ hwloc_shmem_topology_adopt(hwloc_topology_t *topologyp,
186189
goto out_with_mmap;
187190
}
188191

189-
old = (hwloc_topology_t)((char*)mmap_address + sizeof(header));
192+
old = (hwloc_topology_t)((char*)mmap_address + header_length);
190193
if (hwloc_topology_abi_check(old) < 0) {
191194
errno = EINVAL;
192195
goto out_with_mmap;

include/private/xml.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ typedef struct hwloc__xml_import_state_s {
2424

2525
/* opaque data used to store backend-specific data.
2626
* statically allocated to allow stack-allocation by the common code without knowing actual backend needs.
27+
* libxml is 3 ptrs. nolibxml is 3 ptr + one int.
2728
*/
28-
char data[32];
29+
char data[4 * SIZEOF_VOID_P];
2930
} * hwloc__xml_import_state_t;
3031

3132
HWLOC_DECLSPEC int hwloc__xml_import_diff(hwloc__xml_import_state_t state, hwloc_topology_diff_t *firstdiffp);
@@ -65,8 +66,9 @@ typedef struct hwloc__xml_export_state_s {
6566

6667
/* opaque data used to store backend-specific data.
6768
* statically allocated to allow stack-allocation by the common code without knowing actual backend needs.
69+
* libxml is 1 ptr. nolibxml is 1 ptr + 2 size_t + 3 ints.
6870
*/
69-
char data[40];
71+
char data[6 * SIZEOF_VOID_P];
7072
} * hwloc__xml_export_state_t;
7173

7274
HWLOC_DECLSPEC void hwloc__xml_export_topology(hwloc__xml_export_state_t parentstate, hwloc_topology_t topology, unsigned long flags);

0 commit comments

Comments
 (0)