Account for big-endian architectures for poll event encoding

This commit is contained in:
Guillaume Lessard committed 2026-07-28 16:46:32 -07:00
1 parent 5b7e24a6b1
commit 75c85d47e7
2 files changed
+22 -1

No files matched your search

+1 -1
View File
@@ -609,7 +609,7 @@ extension IORing.Request {
if isMultiShot {
request.rawValue.len = Self.SWIFT_IORING_POLL_ADD_MULTI
}
request.rawValue.poll32_events = pollEvents.rawValue
request.pollEvents = pollEvents
}
return request
+21
View File
@@ -75,6 +75,27 @@ extension RawIORequest {
set { rawValue.addr = newValue }
}
/// The poll event mask, stored in `sqe->poll32_events`.
///
/// Big-endian kernels swap the halfwords of this field before reading it.
/// Equivalent to liburing's `__io_uring_prep_poll_mask`.
@_alwaysEmitIntoClient var pollEvents: IORing.Request.PollEvents {
get { .init(rawValue: _applyPollMask(rawValue.poll32_events)) }
set { rawValue.poll32_events = _applyPollMask(newValue.rawValue) }
}
/// Converts a poll event mask between its in-memory and `sqe` encodings.
///
/// This is a halfword rotate (`swahw32` from `<linux/swab.h>`), which keeps
/// the byte order within each half.
@_alwaysEmitIntoClient func _applyPollMask(_ mask: UInt32) -> UInt32 {
#if _endian(big)
return (mask &<< 16) | (mask &>> 16)
#else
return mask
#endif
}
@inlinable public var flags: Flags {
get { Flags(rawValue: rawValue.flags) }
set { rawValue.flags = newValue.rawValue }