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;...@@ -2244,3 +2244,8 @@ pub const MADV_COLD = 20;
2244pub const MADV_PAGEOUT = 21;2244pub const MADV_PAGEOUT = 21;
2245pub const MADV_HWPOISON = 100;2245pub const MADV_HWPOISON = 100;
2246pub const MADV_SOFT_OFFLINE = 101;2246pub 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 {...@@ -526,7 +526,7 @@ pub const IO_Uring = struct {
526 pub fn timeout(526 pub fn timeout(
527 self: *IO_Uring,527 self: *IO_Uring,
528 user_data: u64,528 user_data: u64,
529 ts: *const os.timespec,529 ts: *const os.__kernel_timespec,
530 count: u32,530 count: u32,
531 flags: u32,531 flags: u32,
532 ) !*io_uring_sqe {532 ) !*io_uring_sqe {
...@@ -884,7 +884,7 @@ pub fn io_uring_prep_close(sqe: *io_uring_sqe, fd: os.fd_t) void {...@@ -884,7 +884,7 @@ pub fn io_uring_prep_close(sqe: *io_uring_sqe, fd: os.fd_t) void {
884884
885pub fn io_uring_prep_timeout(885pub fn io_uring_prep_timeout(
886 sqe: *io_uring_sqe,886 sqe: *io_uring_sqe,
887 ts: *const os.timespec,887 ts: *const os.__kernel_timespec,
888 count: u32,888 count: u32,
889 flags: u32,889 flags: u32,
890) void {890) void {
...@@ -1339,7 +1339,7 @@ test "timeout (after a relative time)" {...@@ -1339,7 +1339,7 @@ test "timeout (after a relative time)" {
13391339
1340 const ms = 10;1340 const ms = 10;
1341 const margin = 5;1341 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
1344 const started = std.time.milliTimestamp();1344 const started = std.time.milliTimestamp();
1345 const sqe = try ring.timeout(0x55555555, &ts, 0, 0);1345 const sqe = try ring.timeout(0x55555555, &ts, 0, 0);
...@@ -1366,7 +1366,7 @@ test "timeout (after a number of completions)" {...@@ -1366,7 +1366,7 @@ test "timeout (after a number of completions)" {
1366 };1366 };
1367 defer ring.deinit();1367 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 };
1370 const count_completions: u64 = 1;1370 const count_completions: u64 = 1;
1371 const sqe_timeout = try ring.timeout(0x66666666, &ts, count_completions, 0);1371 const sqe_timeout = try ring.timeout(0x66666666, &ts, count_completions, 0);
1372 testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);1372 testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
...@@ -1399,7 +1399,7 @@ test "timeout_remove" {...@@ -1399,7 +1399,7 @@ test "timeout_remove" {
1399 };1399 };
1400 defer ring.deinit();1400 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 };
1403 const sqe_timeout = try ring.timeout(0x88888888, &ts, 0, 0);1403 const sqe_timeout = try ring.timeout(0x88888888, &ts, 0, 0);
1404 testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);1404 testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
1405 testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data);1405 testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data);