authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-17 13:01:52-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-06-17 13:01:52-07:00
log96acc204b2c6080f0169ca3721c3b95a433c185b
treea7dfe641c7ffcf9932d8b749b6d55c0b3a40ae37
parentd41111d7ef531f6f55a19c56205d6d2f1134c224
parent4054d001445098cdb72a02243e13180f1fba6d79
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #16052 from mikdusan/bsd-getdents

fix bad return types for BSDs getdents and debitrot openbsd

7 files changed, 57 insertions(+), 30 deletions(-)

lib/std/Thread.zig+1-1
......@@ -624,7 +624,7 @@ const PosixThreadImpl = struct {
624624 .openbsd => {
625625 var count: c_int = undefined;
626626 var count_size: usize = @sizeOf(c_int);
627 const mib = [_]c_int{ os.CTL.HW, os.system.HW_NCPUONLINE };
627 const mib = [_]c_int{ os.CTL.HW, os.system.HW.NCPUONLINE };
628628 os.sysctl(&mib, &count, &count_size, null, 0) catch |err| switch (err) {
629629 error.NameTooLong, error.UnknownName => unreachable,
630630 else => |e| return e,
lib/std/c/dragonfly.zig+1-1
......@@ -9,7 +9,7 @@ pub fn _errno() *c_int {
99 return &errno;
1010}
1111
12pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
12pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;
1313pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
1414pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
1515pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int;
lib/std/c/freebsd.zig+1-1
......@@ -75,7 +75,7 @@ pub const _errno = __error;
7575
7676pub extern "c" var malloc_options: [*:0]const u8;
7777
78pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
78pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) isize;
7979pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
8080pub extern "c" fn getrandom(buf_ptr: [*]u8, buf_len: usize, flags: c_uint) isize;
8181pub extern "c" fn getentropy(buf_ptr: [*]u8, buf_len: usize) c_int;
lib/std/c/openbsd.zig+29-26
......@@ -16,7 +16,7 @@ pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void;
1616pub extern "c" fn getthrid() pid_t;
1717pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int;
1818
19pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
19pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int;
2020pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int;
2121
2222pub const pthread_mutex_t = extern struct {
......@@ -1606,31 +1606,34 @@ pub const KERN = struct {
16061606 pub const PROC_NENV = 4;
16071607};
16081608
1609pub const HW_MACHINE = 1;
1610pub const HW_MODEL = 2;
1611pub const HW_NCPU = 3;
1612pub const HW_BYTEORDER = 4;
1613pub const HW_PHYSMEM = 5;
1614pub const HW_USERMEM = 6;
1615pub const HW_PAGESIZE = 7;
1616pub const HW_DISKNAMES = 8;
1617pub const HW_DISKSTATS = 9;
1618pub const HW_DISKCOUNT = 10;
1619pub const HW_SENSORS = 11;
1620pub const HW_CPUSPEED = 12;
1621pub const HW_SETPERF = 13;
1622pub const HW_VENDOR = 14;
1623pub const HW_PRODUCT = 15;
1624pub const HW_VERSION = 16;
1625pub const HW_SERIALNO = 17;
1626pub const HW_UUID = 18;
1627pub const HW_PHYSMEM64 = 19;
1628pub const HW_USERMEM64 = 20;
1629pub const HW_NCPUFOUND = 21;
1630pub const HW_ALLOWPOWERDOWN = 22;
1631pub const HW_PERFPOLICY = 23;
1632pub const HW_SMT = 24;
1633pub const HW_NCPUONLINE = 25;
1609pub const HW = struct {
1610 pub const MACHINE = 1;
1611 pub const MODEL = 2;
1612 pub const NCPU = 3;
1613 pub const BYTEORDER = 4;
1614 pub const PHYSMEM = 5;
1615 pub const USERMEM = 6;
1616 pub const PAGESIZE = 7;
1617 pub const DISKNAMES = 8;
1618 pub const DISKSTATS = 9;
1619 pub const DISKCOUNT = 10;
1620 pub const SENSORS = 11;
1621 pub const CPUSPEED = 12;
1622 pub const SETPERF = 13;
1623 pub const VENDOR = 14;
1624 pub const PRODUCT = 15;
1625 pub const VERSION = 16;
1626 pub const SERIALNO = 17;
1627 pub const UUID = 18;
1628 pub const PHYSMEM64 = 19;
1629 pub const USERMEM64 = 20;
1630 pub const NCPUFOUND = 21;
1631 pub const ALLOWPOWERDOWN = 22;
1632 pub const PERFPOLICY = 23;
1633 pub const SMT = 24;
1634 pub const NCPUONLINE = 25;
1635 pub const POWER = 26;
1636};
16341637
16351638/// TODO refines if necessary
16361639pub const PTHREAD_STACK_MIN = switch (builtin.cpu.arch) {
lib/std/fs.zig+3
......@@ -478,6 +478,9 @@ pub const IterableDir = struct {
478478 .FAULT => unreachable,
479479 .NOTDIR => unreachable,
480480 .INVAL => unreachable,
481 // Introduced in freebsd 13.2: directory unlinked but still open.
482 // To be consistent, iteration ends if the directory being iterated is deleted during iteration.
483 .NOENT => return null,
481484 else => |err| return os.unexpectedErrno(err),
482485 }
483486 if (rc == 0) return null;
lib/std/os.zig+4
......@@ -88,6 +88,10 @@ pub const F = system.F;
8888pub const FD_CLOEXEC = system.FD_CLOEXEC;
8989pub const Flock = system.Flock;
9090pub const HOST_NAME_MAX = system.HOST_NAME_MAX;
91pub const HW = switch (builtin.os.tag) {
92 .openbsd => system.HW,
93 else => .{},
94};
9195pub const IFNAMESIZE = system.IFNAMESIZE;
9296pub const IOV_MAX = system.IOV_MAX;
9397pub const IPPROTO = system.IPPROTO;
lib/std/process.zig+18-1
......@@ -1163,7 +1163,7 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize {
11631163 .linux => {
11641164 return totalSystemMemoryLinux() catch return error.UnknownTotalSystemMemory;
11651165 },
1166 .freebsd, .netbsd, .openbsd, .dragonfly, .macos => {
1166 .freebsd, .netbsd, .dragonfly, .macos => {
11671167 var physmem: c_ulong = undefined;
11681168 var len: usize = @sizeOf(c_ulong);
11691169 const name = switch (builtin.os.tag) {
......@@ -1177,6 +1177,23 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize {
11771177 };
11781178 return @intCast(usize, physmem);
11791179 },
1180 .openbsd => {
1181 const mib: [2]c_int = [_]c_int{
1182 std.os.CTL.HW,
1183 std.os.HW.PHYSMEM64,
1184 };
1185 var physmem: i64 = undefined;
1186 var len: usize = @sizeOf(@TypeOf(physmem));
1187 std.os.sysctl(&mib, &physmem, &len, null, 0) catch |err| switch (err) {
1188 error.NameTooLong => unreachable, // constant, known good value
1189 error.PermissionDenied => unreachable, // only when setting values,
1190 error.SystemResources => unreachable, // memory already on the stack
1191 error.UnknownName => unreachable, // constant, known good value
1192 else => return error.UnknownTotalSystemMemory,
1193 };
1194 assert(physmem >= 0);
1195 return @bitCast(usize, physmem);
1196 },
11801197 .windows => {
11811198 var sbi: std.os.windows.SYSTEM_BASIC_INFORMATION = undefined;
11821199 const rc = std.os.windows.ntdll.NtQuerySystemInformation(