Skip to content

Commit c749c11

Browse files
committed
ioq: Ensure ioq_ent is sufficiently aligned
The natural alignment of struct ioq_ent is only 2 on m68k, so over-align it to at least 4 bytes on all platforms. Link: https://buildd.debian.org/status/fetch.php?pkg=bfs&arch=m68k&ver=3.1-1&stamp=1707699583
1 parent 60fb65a commit c749c11

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/ioq.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ typedef atomic uintptr_t ioq_slot;
177177
#define IOQ_SKIP_ONE (~IOQ_BLOCKED)
178178

179179
// Need room for two flag bits
180-
bfs_static_assert(alignof(struct ioq_ent) > 2);
180+
bfs_static_assert(alignof(struct ioq_ent) >= (1 << 2));
181181

182182
/**
183183
* An MPMC queue of I/O commands.

src/ioq.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,19 @@ enum ioq_op {
3232
IOQ_STAT,
3333
};
3434

35+
/**
36+
* The I/O queue implementation needs two tag bits in each pointer to a struct
37+
* ioq_ent, so we need to ensure at least 4-byte alignment. The natural
38+
* alignment is enough on most architectures, but not m68k, so over-align it.
39+
*/
40+
#define IOQ_ENT_ALIGN alignas(4)
41+
3542
/**
3643
* An I/O queue entry.
3744
*/
3845
struct ioq_ent {
3946
/** The I/O operation. */
40-
enum ioq_op op;
47+
IOQ_ENT_ALIGN enum ioq_op op;
4148

4249
/** The return value (on success) or negative error code (on failure). */
4350
int result;

0 commit comments

Comments
 (0)