authorgravatar for vincent@rischmann.frVincent Rischmann <vincent@rischmann.fr> 2021-02-28 18:43:02+01:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-03-02 14:13:11+02:00
log3dd8396a5542af26636e8bf1e16a2f7f245121ac
treed2167a2ceb0df41ef4b86bbc1e222c7e787f0f0e
parentf296c95599dc66b5aed48dcb93c6b63784c853d8

os/linux: fix IO_Uring.timeout

According to the io_uring PDF (https://kernel.dk/io_uring.pdf) the timeout struct must be 64 bits on both 32 and 64 bit architectures.

2 files changed, 10 insertions(+), 5 deletions(-)

lib/std/os/bits/linux.zig+5
......@@ -2244,3 +2244,8 @@ pub const MADV_COLD = 20;
22442244pub const MADV_PAGEOUT = 21;
22452245pub const MADV_HWPOISON = 100;
22462246pub const MADV_SOFT_OFFLINE = 101;
2247
2248pub const __kernel_timespec = extern struct {
2249 tv_sec: i64,
2250 tv_nsec: i64,
2251};
lib/std/os/linux/io_uring.zig+5-5
......@@ -526,7 +526,7 @@ pub const IO_Uring = struct {
526526 pub fn timeout(
527527 self: *IO_Uring,
528528 user_data: u64,
529 ts: *const os.timespec,
529 ts: *const os.__kernel_timespec,
530530 count: u32,
531531 flags: u32,
532532 ) !*io_uring_sqe {
......@@ -884,7 +884,7 @@ pub fn io_uring_prep_close(sqe: *io_uring_sqe, fd: os.fd_t) void {
884884
885885pub fn io_uring_prep_timeout(
886886 sqe: *io_uring_sqe,
887 ts: *const os.timespec,
887 ts: *const os.__kernel_timespec,
888888 count: u32,
889889 flags: u32,
890890) void {
......@@ -1339,7 +1339,7 @@ test "timeout (after a relative time)" {
13391339
13401340 const ms = 10;
13411341 const margin = 5;
1342 const ts = os.timespec{ .tv_sec = 0, .tv_nsec = ms * 1000000 };
1342 const ts = os.__kernel_timespec{ .tv_sec = 0, .tv_nsec = ms * 1000000 };
13431343
13441344 const started = std.time.milliTimestamp();
13451345 const sqe = try ring.timeout(0x55555555, &ts, 0, 0);
......@@ -1366,7 +1366,7 @@ test "timeout (after a number of completions)" {
13661366 };
13671367 defer ring.deinit();
13681368
1369 const ts = os.timespec{ .tv_sec = 3, .tv_nsec = 0 };
1369 const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 };
13701370 const count_completions: u64 = 1;
13711371 const sqe_timeout = try ring.timeout(0x66666666, &ts, count_completions, 0);
13721372 testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
......@@ -1399,7 +1399,7 @@ test "timeout_remove" {
13991399 };
14001400 defer ring.deinit();
14011401
1402 const ts = os.timespec{ .tv_sec = 3, .tv_nsec = 0 };
1402 const ts = os.__kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 };
14031403 const sqe_timeout = try ring.timeout(0x88888888, &ts, 0, 0);
14041404 testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
14051405 testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data);