authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-07-21 11:03:53+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-07-29 09:50:41+02:00
log4e5068c35cef5e1b3366aa05de60023b9fcd98e6
treea662d1be3f716c8f6bae6ee65d67289eb5a8c481
parent6eb9cb6f285d31c673aa9c175b5848f5a476fb07
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std: Stop supporting Linux/glibc versions older than declared in std.Target.


6 files changed, 16 insertions(+), 71 deletions(-)

lib/std/debug.zig+2-1
......@@ -747,7 +747,8 @@ pub const StackIterator = struct {
747747 .SUCCESS => return bytes_read == buf.len,
748748 .FAULT => return false,
749749 .INVAL, .PERM, .SRCH => unreachable, // own pid is always valid
750 .NOMEM, .NOSYS => {},
750 .NOMEM => {},
751 .NOSYS => {}, // QEMU is known not to implement this syscall.
751752 else => unreachable, // unexpected
752753 }
753754 var path_buf: [
lib/std/fs/File.zig+1-20
......@@ -731,7 +731,7 @@ pub const Metadata = struct {
731731
732732 /// Returns the time the file was created in nanoseconds since UTC 1970-01-01
733733 /// On Windows, this cannot return null
734 /// On Linux, this returns null if the filesystem does not support creation times, or if the kernel is older than 4.11
734 /// On Linux, this returns null if the filesystem does not support creation times
735735 /// On Unices, this returns null if the filesystem or OS does not support creation times
736736 /// On MacOS, this returns the ctime if the filesystem does not support creation times; this is insanity, and yet another reason to hate on Apple
737737 pub fn created(self: Self) ?i128 {
......@@ -822,7 +822,6 @@ pub const MetadataUnix = struct {
822822};
823823
824824/// `MetadataUnix`, but using Linux's `statx` syscall.
825/// On Linux versions below 4.11, `statx` will be filled with data from stat.
826825pub const MetadataLinux = struct {
827826 statx: std.os.linux.Statx,
828827
......@@ -1017,24 +1016,6 @@ pub fn metadata(self: File) MetadataError!Metadata {
10171016
10181017 switch (posix.errno(rcx)) {
10191018 .SUCCESS => {},
1020 // NOSYS happens when `statx` is unsupported, which is the case on kernel versions before 4.11
1021 // Here, we call `fstat` and fill `stx` with the data we need
1022 .NOSYS => {
1023 const st = try posix.fstat(self.handle);
1024
1025 stx.mode = @as(u16, @intCast(st.mode));
1026
1027 // Hacky conversion from timespec to statx_timestamp
1028 stx.atime = std.mem.zeroes(l.statx_timestamp);
1029 stx.atime.sec = st.atim.sec;
1030 stx.atime.nsec = @as(u32, @intCast(st.atim.nsec)); // Guaranteed to succeed (nsec is always below 10^9)
1031
1032 stx.mtime = std.mem.zeroes(l.statx_timestamp);
1033 stx.mtime.sec = st.mtim.sec;
1034 stx.mtime.nsec = @as(u32, @intCast(st.mtim.nsec));
1035
1036 stx.mask = l.STATX_BASIC_STATS | l.STATX_MTIME;
1037 },
10381019 .BADF => unreachable,
10391020 .FAULT => unreachable,
10401021 .NOMEM => return error.SystemResources,
lib/std/os/linux.zig+8-11
......@@ -1890,17 +1890,14 @@ pub fn fstatat(dirfd: i32, path: [*:0]const u8, stat_buf: *Stat, flags: u32) usi
18901890}
18911891
18921892pub fn statx(dirfd: i32, path: [*:0]const u8, flags: u32, mask: u32, statx_buf: *Statx) usize {
1893 if (@hasField(SYS, "statx")) {
1894 return syscall5(
1895 .statx,
1896 @as(usize, @bitCast(@as(isize, dirfd))),
1897 @intFromPtr(path),
1898 flags,
1899 mask,
1900 @intFromPtr(statx_buf),
1901 );
1902 }
1903 return @as(usize, @bitCast(-@as(isize, @intFromEnum(E.NOSYS))));
1893 return syscall5(
1894 .statx,
1895 @as(usize, @bitCast(@as(isize, dirfd))),
1896 @intFromPtr(path),
1897 flags,
1898 mask,
1899 @intFromPtr(statx_buf),
1900 );
19041901}
19051902
19061903pub fn listxattr(path: [*:0]const u8, list: [*]u8, size: usize) usize {
lib/std/os/linux/test.zig-2
......@@ -79,8 +79,6 @@ test "statx" {
7979 var statx_buf: linux.Statx = undefined;
8080 switch (linux.E.init(linux.statx(file.handle, "", linux.AT.EMPTY_PATH, linux.STATX_BASIC_STATS, &statx_buf))) {
8181 .SUCCESS => {},
82 // The statx syscall was only introduced in linux 4.11
83 .NOSYS => return error.SkipZigTest,
8482 else => unreachable,
8583 }
8684
lib/std/posix.zig+4-32
......@@ -615,7 +615,6 @@ pub fn getrandom(buffer: []u8) GetRandomError!void {
615615 .INVAL => unreachable,
616616 .FAULT => unreachable,
617617 .INTR => continue,
618 .NOSYS => return getRandomBytesDevURandom(buf),
619618 else => return unexpectedErrno(err),
620619 }
621620 }
......@@ -4534,7 +4533,6 @@ pub const FanotifyInitError = error{
45344533 ProcessFdQuotaExceeded,
45354534 SystemFdQuotaExceeded,
45364535 SystemResources,
4537 OperationNotSupported,
45384536 PermissionDenied,
45394537} || UnexpectedError;
45404538
......@@ -4546,7 +4544,6 @@ pub fn fanotify_init(flags: std.os.linux.fanotify.InitFlags, event_f_flags: u32)
45464544 .MFILE => return error.ProcessFdQuotaExceeded,
45474545 .NFILE => return error.SystemFdQuotaExceeded,
45484546 .NOMEM => return error.SystemResources,
4549 .NOSYS => return error.OperationNotSupported,
45504547 .PERM => return error.PermissionDenied,
45514548 else => |err| return unexpectedErrno(err),
45524549 }
......@@ -4559,7 +4556,6 @@ pub const FanotifyMarkError = error{
45594556 FileNotFound,
45604557 SystemResources,
45614558 UserMarkQuotaExceeded,
4562 NotImplemented,
45634559 NotDir,
45644560 OperationNotSupported,
45654561 PermissionDenied,
......@@ -4600,7 +4596,6 @@ pub fn fanotify_markZ(
46004596 .NOENT => return error.FileNotFound,
46014597 .NOMEM => return error.SystemResources,
46024598 .NOSPC => return error.UserMarkQuotaExceeded,
4603 .NOSYS => return error.NotImplemented,
46044599 .NOTDIR => return error.NotDir,
46054600 .OPNOTSUPP => return error.OperationNotSupported,
46064601 .PERM => return error.PermissionDenied,
......@@ -6183,13 +6178,6 @@ pub fn sendfile(
61836178
61846179 switch (native_os) {
61856180 .linux => sf: {
6186 // sendfile() first appeared in Linux 2.2, glibc 2.1.
6187 const call_sf = comptime if (builtin.link_libc)
6188 std.c.versionCheck(.{ .major = 2, .minor = 1, .patch = 0 })
6189 else
6190 builtin.os.version_range.linux.range.max.order(.{ .major = 2, .minor = 2, .patch = 0 }) != .lt;
6191 if (!call_sf) break :sf;
6192
61936181 if (headers.len != 0) {
61946182 const amt = try writev(out_fd, headers);
61956183 total_written += amt;
......@@ -6223,14 +6211,14 @@ pub fn sendfile(
62236211 .OVERFLOW => unreachable, // We avoid passing too large of a `count`.
62246212 .NOTCONN => return error.BrokenPipe, // `out_fd` is an unconnected socket
62256213
6226 .INVAL, .NOSYS => {
6214 .INVAL => {
62276215 // EINVAL could be any of the following situations:
62286216 // * Descriptor is not valid or locked
62296217 // * an mmap(2)-like operation is not available for in_fd
62306218 // * count is negative
62316219 // * out_fd has the APPEND flag set
62326220 // Because of the "mmap(2)-like operation" possibility, we fall back to doing read/write
6233 // manually, the same as ENOSYS.
6221 // manually.
62346222 break :sf;
62356223 },
62366224 .AGAIN => return error.WouldBlock,
......@@ -6456,21 +6444,15 @@ pub const CopyFileRangeError = error{
64566444/// `flags` has different meanings per operating system; refer to the respective man pages.
64576445///
64586446/// These systems support in-kernel data copying:
6459/// * Linux 4.5 (cross-filesystem 5.3)
6447/// * Linux (cross-filesystem from version 5.3)
64606448/// * FreeBSD 13.0
64616449///
64626450/// Other systems fall back to calling `pread` / `pwrite`.
64636451///
64646452/// Maximum offsets on Linux and FreeBSD are `maxInt(i64)`.
64656453pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len: usize, flags: u32) CopyFileRangeError!usize {
6466 const global = struct {
6467 var has_copy_file_range = true;
6468 };
6469
64706454 if ((comptime builtin.os.isAtLeast(.freebsd, .{ .major = 13, .minor = 0, .patch = 0 }) orelse false) or
6471 ((comptime builtin.os.isAtLeast(.linux, .{ .major = 4, .minor = 5, .patch = 0 }) orelse false and
6472 std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 })) and
6473 @atomicLoad(bool, &global.has_copy_file_range, .monotonic)))
6455 (comptime builtin.os.tag == .linux and std.c.versionCheck(.{ .major = 2, .minor = 27, .patch = 0 })))
64746456 {
64756457 var off_in_copy: i64 = @bitCast(off_in);
64766458 var off_out_copy: i64 = @bitCast(off_out);
......@@ -6504,10 +6486,6 @@ pub fn copy_file_range(fd_in: fd_t, off_in: u64, fd_out: fd_t, off_out: u64, len
65046486 .PERM => return error.PermissionDenied,
65056487 .TXTBSY => return error.SwapFile,
65066488 .XDEV => break, // support for cross-filesystem copy added in Linux 5.3, use fallback
6507 .NOSYS => {
6508 @atomicStore(bool, &global.has_copy_file_range, false, .monotonic);
6509 break;
6510 },
65116489 else => |err| return unexpectedErrno(err),
65126490 }
65136491 }
......@@ -6775,10 +6753,6 @@ pub const MemFdCreateError = error{
67756753 OutOfMemory,
67766754 /// Either the name provided exceeded `NAME_MAX`, or invalid flags were passed.
67776755 NameTooLong,
6778
6779 /// memfd_create is available in Linux 3.17 and later. This error is returned
6780 /// for older kernel versions.
6781 SystemOutdated,
67826756} || UnexpectedError;
67836757
67846758pub fn memfd_createZ(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t {
......@@ -6795,7 +6769,6 @@ pub fn memfd_createZ(name: [*:0]const u8, flags: u32) MemFdCreateError!fd_t {
67956769 .NFILE => return error.SystemFdQuotaExceeded,
67966770 .MFILE => return error.ProcessFdQuotaExceeded,
67976771 .NOMEM => return error.OutOfMemory,
6798 .NOSYS => return error.SystemOutdated,
67996772 else => |err| return unexpectedErrno(err),
68006773 }
68016774 },
......@@ -6915,7 +6888,6 @@ pub fn signalfd(fd: fd_t, mask: *const sigset_t, flags: u32) !fd_t {
69156888 .NOMEM => return error.SystemResources,
69166889 .MFILE => return error.ProcessResources,
69176890 .NODEV => return error.InodeMountFail,
6918 .NOSYS => return error.SystemOutdated,
69196891 else => |err| return unexpectedErrno(err),
69206892 }
69216893}
lib/std/posix/test.zig+1-5
......@@ -580,11 +580,7 @@ test "memfd_create" {
580580 else => return error.SkipZigTest,
581581 }
582582
583 const fd = posix.memfd_create("test", 0) catch |err| switch (err) {
584 // Related: https://github.com/ziglang/zig/issues/4019
585 error.SystemOutdated => return error.SkipZigTest,
586 else => |e| return e,
587 };
583 const fd = try posix.memfd_create("test", 0);
588584 defer posix.close(fd);
589585 try expect((try posix.write(fd, "test")) == 4);
590586 try posix.lseek_SET(fd, 0);