authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-09-01 17:51:22-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-09-01 17:54:07-07:00
log2264fca03e6ce9203baf52d70825ec3bc32f8262
tree33cfda1ae8fb44e36cc0b1e6dcdad76063f345d7
parent21171fd71b6b3c69a404176e8fe4620b9768d5a6

fix regression on linux with kernel_timespec

I incorrectly assumed that __kernel_timespec was used when not linking libc, however that is not the case. `std.os.timespec` is used both for libc and non-libc cases. `__kernel_timespec` is a special struct that is used only for io_uring.

11 files changed, 21 insertions(+), 51 deletions(-)

lib/std/os/linux.zig+7-2
......@@ -81,7 +81,6 @@ pub const msghdr_const = arch_bits.msghdr_const;
8181pub const nlink_t = arch_bits.nlink_t;
8282pub const off_t = arch_bits.off_t;
8383pub const time_t = arch_bits.time_t;
84pub const timespec = arch_bits.timespec;
8584pub const timeval = arch_bits.timeval;
8685pub const timezone = arch_bits.timezone;
8786pub const ucontext_t = arch_bits.ucontext_t;
......@@ -4149,11 +4148,17 @@ pub const POSIX_FADV = switch (native_arch) {
41494148 },
41504149};
41514150
4152pub const __kernel_timespec = extern struct {
4151/// The timespec struct used by the kernel.
4152pub const kernel_timespec = if (@sizeOf(usize) >= 8) timespec else extern struct {
41534153 tv_sec: i64,
41544154 tv_nsec: i64,
41554155};
41564156
4157pub const timespec = extern struct {
4158 tv_sec: isize,
4159 tv_nsec: isize,
4160};
4161
41574162pub const XDP = struct {
41584163 pub const SHARED_UMEM = (1 << 0);
41594164 pub const COPY = (1 << 1);
lib/std/os/linux/arm-eabi.zig+1-5
......@@ -10,6 +10,7 @@ const uid_t = linux.uid_t;
1010const gid_t = linux.gid_t;
1111const pid_t = linux.pid_t;
1212const sockaddr = linux.sockaddr;
13const timespec = linux.timespec;
1314
1415pub fn syscall0(number: SYS) usize {
1516 return asm volatile ("svc #0"
......@@ -703,11 +704,6 @@ pub const Stat = extern struct {
703704 }
704705};
705706
706pub const timespec = extern struct {
707 tv_sec: i32,
708 tv_nsec: i32,
709};
710
711707pub const timeval = extern struct {
712708 tv_sec: i32,
713709 tv_usec: i32,
lib/std/os/linux/arm64.zig+1-5
......@@ -10,6 +10,7 @@ const gid_t = linux.gid_t;
1010const pid_t = linux.pid_t;
1111const stack_t = linux.stack_t;
1212const sigset_t = linux.sigset_t;
13const timespec = std.os.linux.timespec;
1314
1415pub fn syscall0(number: SYS) usize {
1516 return asm volatile ("svc #0"
......@@ -558,11 +559,6 @@ pub const Stat = extern struct {
558559 }
559560};
560561
561pub const timespec = extern struct {
562 tv_sec: time_t,
563 tv_nsec: isize,
564};
565
566562pub const timeval = extern struct {
567563 tv_sec: isize,
568564 tv_usec: isize,
lib/std/os/linux/i386.zig+1-5
......@@ -10,6 +10,7 @@ const pid_t = linux.pid_t;
1010const stack_t = linux.stack_t;
1111const sigset_t = linux.sigset_t;
1212const sockaddr = linux.sockaddr;
13const timespec = linux.timespec;
1314
1415pub fn syscall0(number: SYS) usize {
1516 return asm volatile ("int $0x80"
......@@ -710,11 +711,6 @@ pub const Stat = extern struct {
710711 }
711712};
712713
713pub const timespec = extern struct {
714 tv_sec: i32,
715 tv_nsec: i32,
716};
717
718714pub const timeval = extern struct {
719715 tv_sec: i32,
720716 tv_usec: i32,
lib/std/os/linux/io_uring.zig+5-5
......@@ -539,7 +539,7 @@ pub const IO_Uring = struct {
539539 pub fn timeout(
540540 self: *IO_Uring,
541541 user_data: u64,
542 ts: *const os.linux.timespec,
542 ts: *const os.linux.kernel_timespec,
543543 count: u32,
544544 flags: u32,
545545 ) !*io_uring_sqe {
......@@ -979,7 +979,7 @@ pub fn io_uring_prep_close(sqe: *io_uring_sqe, fd: os.fd_t) void {
979979
980980pub fn io_uring_prep_timeout(
981981 sqe: *io_uring_sqe,
982 ts: *const os.linux.timespec,
982 ts: *const os.linux.kernel_timespec,
983983 count: u32,
984984 flags: u32,
985985) void {
......@@ -1450,7 +1450,7 @@ test "timeout (after a relative time)" {
14501450
14511451 const ms = 10;
14521452 const margin = 5;
1453 const ts = os.linux.timespec{ .tv_sec = 0, .tv_nsec = ms * 1000000 };
1453 const ts = os.linux.kernel_timespec{ .tv_sec = 0, .tv_nsec = ms * 1000000 };
14541454
14551455 const started = std.time.milliTimestamp();
14561456 const sqe = try ring.timeout(0x55555555, &ts, 0, 0);
......@@ -1479,7 +1479,7 @@ test "timeout (after a number of completions)" {
14791479 };
14801480 defer ring.deinit();
14811481
1482 const ts = os.linux.timespec{ .tv_sec = 3, .tv_nsec = 0 };
1482 const ts = os.linux.kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 };
14831483 const count_completions: u64 = 1;
14841484 const sqe_timeout = try ring.timeout(0x66666666, &ts, count_completions, 0);
14851485 try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
......@@ -1512,7 +1512,7 @@ test "timeout_remove" {
15121512 };
15131513 defer ring.deinit();
15141514
1515 const ts = os.linux.timespec{ .tv_sec = 3, .tv_nsec = 0 };
1515 const ts = os.linux.kernel_timespec{ .tv_sec = 3, .tv_nsec = 0 };
15161516 const sqe_timeout = try ring.timeout(0x88888888, &ts, 0, 0);
15171517 try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
15181518 try testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data);
lib/std/os/linux/mips.zig+1-5
......@@ -7,6 +7,7 @@ const iovec_const = linux.iovec_const;
77const uid_t = linux.uid_t;
88const gid_t = linux.gid_t;
99const pid_t = linux.pid_t;
10const timespec = linux.timespec;
1011
1112pub fn syscall0(number: SYS) usize {
1213 return asm volatile (
......@@ -753,11 +754,6 @@ pub const Stat = extern struct {
753754 }
754755};
755756
756pub const timespec = extern struct {
757 tv_sec: isize,
758 tv_nsec: isize,
759};
760
761757pub const timeval = extern struct {
762758 tv_sec: isize,
763759 tv_usec: isize,
lib/std/os/linux/powerpc.zig+1-5
......@@ -10,6 +10,7 @@ const pid_t = linux.pid_t;
1010const stack_t = linux.stack_t;
1111const sigset_t = linux.sigset_t;
1212const sockaddr = linux.sockaddr;
13const timespec = linux.timespec;
1314
1415pub fn syscall0(number: SYS) usize {
1516 return asm volatile (
......@@ -704,11 +705,6 @@ pub const Stat = extern struct {
704705 }
705706};
706707
707pub const timespec = extern struct {
708 tv_sec: time_t,
709 tv_nsec: isize,
710};
711
712708pub const timeval = extern struct {
713709 tv_sec: time_t,
714710 tv_usec: isize,
lib/std/os/linux/powerpc64.zig+1-5
......@@ -10,6 +10,7 @@ const pid_t = linux.pid_t;
1010const stack_t = linux.stack_t;
1111const sigset_t = linux.sigset_t;
1212const sockaddr = linux.sockaddr;
13const timespec = linux.timespec;
1314
1415pub fn syscall0(number: SYS) usize {
1516 return asm volatile (
......@@ -679,11 +680,6 @@ pub const Stat = extern struct {
679680 }
680681};
681682
682pub const timespec = extern struct {
683 tv_sec: time_t,
684 tv_nsec: isize,
685};
686
687683pub const timeval = extern struct {
688684 tv_sec: isize,
689685 tv_usec: isize,
lib/std/os/linux/riscv64.zig+1-4
......@@ -2,6 +2,7 @@ const std = @import("../../std.zig");
22const uid_t = std.os.linux.uid_t;
33const gid_t = std.os.linux.gid_t;
44const pid_t = std.os.linux.pid_t;
5const timespec = std.os.linux.timespec;
56
67pub fn syscall0(number: SYS) usize {
78 return asm volatile ("ecall"
......@@ -468,10 +469,6 @@ pub const off_t = isize;
468469pub const ino_t = usize;
469470pub const dev_t = usize;
470471pub const blkcnt_t = isize;
471pub const timespec = extern struct {
472 tv_sec: time_t,
473 tv_nsec: isize,
474};
475472
476473pub const timeval = extern struct {
477474 tv_sec: time_t,
lib/std/os/linux/sparc64.zig+1-5
......@@ -11,6 +11,7 @@ const sockaddr = linux.sockaddr;
1111const socklen_t = linux.socklen_t;
1212const iovec = linux.iovec;
1313const iovec_const = linux.iovec_const;
14const timespec = linux.timespec;
1415
1516pub fn syscall_pipe(fd: *[2]i32) usize {
1617 return asm volatile (
......@@ -708,11 +709,6 @@ pub const Stat = extern struct {
708709 }
709710};
710711
711pub const timespec = extern struct {
712 tv_sec: isize,
713 tv_nsec: isize,
714};
715
716712pub const timeval = extern struct {
717713 tv_sec: isize,
718714 tv_usec: isize,
lib/std/os/linux/x86_64.zig+1-5
......@@ -12,6 +12,7 @@ const stack_t = linux.stack_t;
1212const sigset_t = linux.sigset_t;
1313const sockaddr = linux.sockaddr;
1414const socklen_t = linux.socklen_t;
15const timespec = linux.timespec;
1516
1617pub fn syscall0(number: SYS) usize {
1718 return asm volatile ("syscall"
......@@ -653,11 +654,6 @@ pub const Stat = extern struct {
653654 }
654655};
655656
656pub const timespec = extern struct {
657 tv_sec: isize,
658 tv_nsec: isize,
659};
660
661657pub const timeval = extern struct {
662658 tv_sec: isize,
663659 tv_usec: isize,