Skip to content

Commit

Permalink
ioq: Ensure ioq_ent is sufficiently aligned
Browse files Browse the repository at this point in the history
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
  • Loading branch information
tavianator committed Feb 16, 2024
1 parent 60fb65a commit c749c11
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/ioq.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ typedef atomic uintptr_t ioq_slot;
#define IOQ_SKIP_ONE (~IOQ_BLOCKED)

// Need room for two flag bits
bfs_static_assert(alignof(struct ioq_ent) > 2);
bfs_static_assert(alignof(struct ioq_ent) >= (1 << 2));

/**
* An MPMC queue of I/O commands.
Expand Down
9 changes: 8 additions & 1 deletion src/ioq.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,19 @@ enum ioq_op {
IOQ_STAT,
};

/**
* The I/O queue implementation needs two tag bits in each pointer to a struct
* ioq_ent, so we need to ensure at least 4-byte alignment. The natural
* alignment is enough on most architectures, but not m68k, so over-align it.
*/
#define IOQ_ENT_ALIGN alignas(4)

/**
* An I/O queue entry.
*/
struct ioq_ent {
/** The I/O operation. */
enum ioq_op op;
IOQ_ENT_ALIGN enum ioq_op op;

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

0 comments on commit c749c11

Please sign in to comment.