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;...@@ -81,7 +81,6 @@ pub const msghdr_const = arch_bits.msghdr_const;
81pub const nlink_t = arch_bits.nlink_t;81pub const nlink_t = arch_bits.nlink_t;
82pub const off_t = arch_bits.off_t;82pub const off_t = arch_bits.off_t;
83pub const time_t = arch_bits.time_t;83pub const time_t = arch_bits.time_t;
84pub const timespec = arch_bits.timespec;
85pub const timeval = arch_bits.timeval;84pub const timeval = arch_bits.timeval;
86pub const timezone = arch_bits.timezone;85pub const timezone = arch_bits.timezone;
87pub const ucontext_t = arch_bits.ucontext_t;86pub const ucontext_t = arch_bits.ucontext_t;
...@@ -4149,11 +4148,17 @@ pub const POSIX_FADV = switch (native_arch) {...@@ -4149,11 +4148,17 @@ pub const POSIX_FADV = switch (native_arch) {
4149 },4148 },
4150};4149};
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 {
4153 tv_sec: i64,4153 tv_sec: i64,
4154 tv_nsec: i64,4154 tv_nsec: i64,
4155};4155};
41564156
4157pub const timespec = extern struct {
4158 tv_sec: isize,
4159 tv_nsec: isize,
4160};
4161
4157pub const XDP = struct {4162pub const XDP = struct {
4158 pub const SHARED_UMEM = (1 << 0);4163 pub const SHARED_UMEM = (1 << 0);
4159 pub const COPY = (1 << 1);4164 pub const COPY = (1 << 1);
lib/std/os/linux/arm-eabi.zig+1-5
...@@ -10,6 +10,7 @@ const uid_t = linux.uid_t;...@@ -10,6 +10,7 @@ const uid_t = linux.uid_t;
10const gid_t = linux.gid_t;10const gid_t = linux.gid_t;
11const pid_t = linux.pid_t;11const pid_t = linux.pid_t;
12const sockaddr = linux.sockaddr;12const sockaddr = linux.sockaddr;
13const timespec = linux.timespec;
1314
14pub fn syscall0(number: SYS) usize {15pub fn syscall0(number: SYS) usize {
15 return asm volatile ("svc #0"16 return asm volatile ("svc #0"
...@@ -703,11 +704,6 @@ pub const Stat = extern struct {...@@ -703,11 +704,6 @@ pub const Stat = extern struct {
703 }704 }
704};705};
705706
706pub const timespec = extern struct {
707 tv_sec: i32,
708 tv_nsec: i32,
709};
710
711pub const timeval = extern struct {707pub const timeval = extern struct {
712 tv_sec: i32,708 tv_sec: i32,
713 tv_usec: i32,709 tv_usec: i32,
lib/std/os/linux/arm64.zig+1-5
...@@ -10,6 +10,7 @@ const gid_t = linux.gid_t;...@@ -10,6 +10,7 @@ const gid_t = linux.gid_t;
10const pid_t = linux.pid_t;10const pid_t = linux.pid_t;
11const stack_t = linux.stack_t;11const stack_t = linux.stack_t;
12const sigset_t = linux.sigset_t;12const sigset_t = linux.sigset_t;
13const timespec = std.os.linux.timespec;
1314
14pub fn syscall0(number: SYS) usize {15pub fn syscall0(number: SYS) usize {
15 return asm volatile ("svc #0"16 return asm volatile ("svc #0"
...@@ -558,11 +559,6 @@ pub const Stat = extern struct {...@@ -558,11 +559,6 @@ pub const Stat = extern struct {
558 }559 }
559};560};
560561
561pub const timespec = extern struct {
562 tv_sec: time_t,
563 tv_nsec: isize,
564};
565
566pub const timeval = extern struct {562pub const timeval = extern struct {
567 tv_sec: isize,563 tv_sec: isize,
568 tv_usec: isize,564 tv_usec: isize,
lib/std/os/linux/i386.zig+1-5
...@@ -10,6 +10,7 @@ const pid_t = linux.pid_t;...@@ -10,6 +10,7 @@ const pid_t = linux.pid_t;
10const stack_t = linux.stack_t;10const stack_t = linux.stack_t;
11const sigset_t = linux.sigset_t;11const sigset_t = linux.sigset_t;
12const sockaddr = linux.sockaddr;12const sockaddr = linux.sockaddr;
13const timespec = linux.timespec;
1314
14pub fn syscall0(number: SYS) usize {15pub fn syscall0(number: SYS) usize {
15 return asm volatile ("int $0x80"16 return asm volatile ("int $0x80"
...@@ -710,11 +711,6 @@ pub const Stat = extern struct {...@@ -710,11 +711,6 @@ pub const Stat = extern struct {
710 }711 }
711};712};
712713
713pub const timespec = extern struct {
714 tv_sec: i32,
715 tv_nsec: i32,
716};
717
718pub const timeval = extern struct {714pub const timeval = extern struct {
719 tv_sec: i32,715 tv_sec: i32,
720 tv_usec: i32,716 tv_usec: i32,
lib/std/os/linux/io_uring.zig+5-5
...@@ -539,7 +539,7 @@ pub const IO_Uring = struct {...@@ -539,7 +539,7 @@ pub const IO_Uring = struct {
539 pub fn timeout(539 pub fn timeout(
540 self: *IO_Uring,540 self: *IO_Uring,
541 user_data: u64,541 user_data: u64,
542 ts: *const os.linux.timespec,542 ts: *const os.linux.kernel_timespec,
543 count: u32,543 count: u32,
544 flags: u32,544 flags: u32,
545 ) !*io_uring_sqe {545 ) !*io_uring_sqe {
...@@ -979,7 +979,7 @@ pub fn io_uring_prep_close(sqe: *io_uring_sqe, fd: os.fd_t) void {...@@ -979,7 +979,7 @@ pub fn io_uring_prep_close(sqe: *io_uring_sqe, fd: os.fd_t) void {
979979
980pub fn io_uring_prep_timeout(980pub fn io_uring_prep_timeout(
981 sqe: *io_uring_sqe,981 sqe: *io_uring_sqe,
982 ts: *const os.linux.timespec,982 ts: *const os.linux.kernel_timespec,
983 count: u32,983 count: u32,
984 flags: u32,984 flags: u32,
985) void {985) void {
...@@ -1450,7 +1450,7 @@ test "timeout (after a relative time)" {...@@ -1450,7 +1450,7 @@ test "timeout (after a relative time)" {
14501450
1451 const ms = 10;1451 const ms = 10;
1452 const margin = 5;1452 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
1455 const started = std.time.milliTimestamp();1455 const started = std.time.milliTimestamp();
1456 const sqe = try ring.timeout(0x55555555, &ts, 0, 0);1456 const sqe = try ring.timeout(0x55555555, &ts, 0, 0);
...@@ -1479,7 +1479,7 @@ test "timeout (after a number of completions)" {...@@ -1479,7 +1479,7 @@ test "timeout (after a number of completions)" {
1479 };1479 };
1480 defer ring.deinit();1480 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 };
1483 const count_completions: u64 = 1;1483 const count_completions: u64 = 1;
1484 const sqe_timeout = try ring.timeout(0x66666666, &ts, count_completions, 0);1484 const sqe_timeout = try ring.timeout(0x66666666, &ts, count_completions, 0);
1485 try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);1485 try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
...@@ -1512,7 +1512,7 @@ test "timeout_remove" {...@@ -1512,7 +1512,7 @@ test "timeout_remove" {
1512 };1512 };
1513 defer ring.deinit();1513 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 };
1516 const sqe_timeout = try ring.timeout(0x88888888, &ts, 0, 0);1516 const sqe_timeout = try ring.timeout(0x88888888, &ts, 0, 0);
1517 try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);1517 try testing.expectEqual(linux.IORING_OP.TIMEOUT, sqe_timeout.opcode);
1518 try testing.expectEqual(@as(u64, 0x88888888), sqe_timeout.user_data);1518 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;...@@ -7,6 +7,7 @@ const iovec_const = linux.iovec_const;
7const uid_t = linux.uid_t;7const uid_t = linux.uid_t;
8const gid_t = linux.gid_t;8const gid_t = linux.gid_t;
9const pid_t = linux.pid_t;9const pid_t = linux.pid_t;
10const timespec = linux.timespec;
1011
11pub fn syscall0(number: SYS) usize {12pub fn syscall0(number: SYS) usize {
12 return asm volatile (13 return asm volatile (
...@@ -753,11 +754,6 @@ pub const Stat = extern struct {...@@ -753,11 +754,6 @@ pub const Stat = extern struct {
753 }754 }
754};755};
755756
756pub const timespec = extern struct {
757 tv_sec: isize,
758 tv_nsec: isize,
759};
760
761pub const timeval = extern struct {757pub const timeval = extern struct {
762 tv_sec: isize,758 tv_sec: isize,
763 tv_usec: isize,759 tv_usec: isize,
lib/std/os/linux/powerpc.zig+1-5
...@@ -10,6 +10,7 @@ const pid_t = linux.pid_t;...@@ -10,6 +10,7 @@ const pid_t = linux.pid_t;
10const stack_t = linux.stack_t;10const stack_t = linux.stack_t;
11const sigset_t = linux.sigset_t;11const sigset_t = linux.sigset_t;
12const sockaddr = linux.sockaddr;12const sockaddr = linux.sockaddr;
13const timespec = linux.timespec;
1314
14pub fn syscall0(number: SYS) usize {15pub fn syscall0(number: SYS) usize {
15 return asm volatile (16 return asm volatile (
...@@ -704,11 +705,6 @@ pub const Stat = extern struct {...@@ -704,11 +705,6 @@ pub const Stat = extern struct {
704 }705 }
705};706};
706707
707pub const timespec = extern struct {
708 tv_sec: time_t,
709 tv_nsec: isize,
710};
711
712pub const timeval = extern struct {708pub const timeval = extern struct {
713 tv_sec: time_t,709 tv_sec: time_t,
714 tv_usec: isize,710 tv_usec: isize,
lib/std/os/linux/powerpc64.zig+1-5
...@@ -10,6 +10,7 @@ const pid_t = linux.pid_t;...@@ -10,6 +10,7 @@ const pid_t = linux.pid_t;
10const stack_t = linux.stack_t;10const stack_t = linux.stack_t;
11const sigset_t = linux.sigset_t;11const sigset_t = linux.sigset_t;
12const sockaddr = linux.sockaddr;12const sockaddr = linux.sockaddr;
13const timespec = linux.timespec;
1314
14pub fn syscall0(number: SYS) usize {15pub fn syscall0(number: SYS) usize {
15 return asm volatile (16 return asm volatile (
...@@ -679,11 +680,6 @@ pub const Stat = extern struct {...@@ -679,11 +680,6 @@ pub const Stat = extern struct {
679 }680 }
680};681};
681682
682pub const timespec = extern struct {
683 tv_sec: time_t,
684 tv_nsec: isize,
685};
686
687pub const timeval = extern struct {683pub const timeval = extern struct {
688 tv_sec: isize,684 tv_sec: isize,
689 tv_usec: isize,685 tv_usec: isize,
lib/std/os/linux/riscv64.zig+1-4
...@@ -2,6 +2,7 @@ const std = @import("../../std.zig");...@@ -2,6 +2,7 @@ const std = @import("../../std.zig");
2const uid_t = std.os.linux.uid_t;2const uid_t = std.os.linux.uid_t;
3const gid_t = std.os.linux.gid_t;3const gid_t = std.os.linux.gid_t;
4const pid_t = std.os.linux.pid_t;4const pid_t = std.os.linux.pid_t;
5const timespec = std.os.linux.timespec;
56
6pub fn syscall0(number: SYS) usize {7pub fn syscall0(number: SYS) usize {
7 return asm volatile ("ecall"8 return asm volatile ("ecall"
...@@ -468,10 +469,6 @@ pub const off_t = isize;...@@ -468,10 +469,6 @@ pub const off_t = isize;
468pub const ino_t = usize;469pub const ino_t = usize;
469pub const dev_t = usize;470pub const dev_t = usize;
470pub const blkcnt_t = isize;471pub const blkcnt_t = isize;
471pub const timespec = extern struct {
472 tv_sec: time_t,
473 tv_nsec: isize,
474};
475472
476pub const timeval = extern struct {473pub const timeval = extern struct {
477 tv_sec: time_t,474 tv_sec: time_t,
lib/std/os/linux/sparc64.zig+1-5
...@@ -11,6 +11,7 @@ const sockaddr = linux.sockaddr;...@@ -11,6 +11,7 @@ const sockaddr = linux.sockaddr;
11const socklen_t = linux.socklen_t;11const socklen_t = linux.socklen_t;
12const iovec = linux.iovec;12const iovec = linux.iovec;
13const iovec_const = linux.iovec_const;13const iovec_const = linux.iovec_const;
14const timespec = linux.timespec;
1415
15pub fn syscall_pipe(fd: *[2]i32) usize {16pub fn syscall_pipe(fd: *[2]i32) usize {
16 return asm volatile (17 return asm volatile (
...@@ -708,11 +709,6 @@ pub const Stat = extern struct {...@@ -708,11 +709,6 @@ pub const Stat = extern struct {
708 }709 }
709};710};
710711
711pub const timespec = extern struct {
712 tv_sec: isize,
713 tv_nsec: isize,
714};
715
716pub const timeval = extern struct {712pub const timeval = extern struct {
717 tv_sec: isize,713 tv_sec: isize,
718 tv_usec: isize,714 tv_usec: isize,
lib/std/os/linux/x86_64.zig+1-5
...@@ -12,6 +12,7 @@ const stack_t = linux.stack_t;...@@ -12,6 +12,7 @@ const stack_t = linux.stack_t;
12const sigset_t = linux.sigset_t;12const sigset_t = linux.sigset_t;
13const sockaddr = linux.sockaddr;13const sockaddr = linux.sockaddr;
14const socklen_t = linux.socklen_t;14const socklen_t = linux.socklen_t;
15const timespec = linux.timespec;
1516
16pub fn syscall0(number: SYS) usize {17pub fn syscall0(number: SYS) usize {
17 return asm volatile ("syscall"18 return asm volatile ("syscall"
...@@ -653,11 +654,6 @@ pub const Stat = extern struct {...@@ -653,11 +654,6 @@ pub const Stat = extern struct {
653 }654 }
654};655};
655656
656pub const timespec = extern struct {
657 tv_sec: isize,
658 tv_nsec: isize,
659};
660
661pub const timeval = extern struct {657pub const timeval = extern struct {
662 tv_sec: isize,658 tv_sec: isize,
663 tv_usec: isize,659 tv_usec: isize,