| author | |
| committer | |
| log | 40fc71bf710ae3704c85c718636a190a5106c0cf |
| tree | 96d348047db31367e1bcb86a754546ab0398f252 |
| parent | 64ddba955a1f98ab77cfb39844a09f472ebc4609 |
| signature |
- fix getdents return type usize → c_int
- special-case process.zig to use sysctl instead of sysctlbyname
- use struct/field pattern for sysctl HW_* constants4 files changed, 52 insertions(+), 28 deletions(-)
lib/std/Thread.zig+1-1| ... | @@ -624,7 +624,7 @@ const PosixThreadImpl = struct { | ... | @@ -624,7 +624,7 @@ const PosixThreadImpl = struct { |
| 624 | .openbsd => { | 624 | .openbsd => { |
| 625 | var count: c_int = undefined; | 625 | var count: c_int = undefined; |
| 626 | var count_size: usize = @sizeOf(c_int); | 626 | 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 }; |
| 628 | os.sysctl(&mib, &count, &count_size, null, 0) catch |err| switch (err) { | 628 | os.sysctl(&mib, &count, &count_size, null, 0) catch |err| switch (err) { |
| 629 | error.NameTooLong, error.UnknownName => unreachable, | 629 | error.NameTooLong, error.UnknownName => unreachable, |
| 630 | else => |e| return e, | 630 | else => |e| return e, |
lib/std/c/openbsd.zig+29-26| ... | @@ -16,7 +16,7 @@ pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void; | ... | @@ -16,7 +16,7 @@ pub extern "c" fn arc4random_buf(buf: [*]u8, len: usize) void; |
| 16 | pub extern "c" fn getthrid() pid_t; | 16 | pub extern "c" fn getthrid() pid_t; |
| 17 | pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int; | 17 | pub extern "c" fn pipe2(fds: *[2]fd_t, flags: u32) c_int; |
| 18 | 18 | ||
| 19 | pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize; | 19 | pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) c_int; |
| 20 | pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int; | 20 | pub extern "c" fn sigaltstack(ss: ?*stack_t, old_ss: ?*stack_t) c_int; |
| 21 | 21 | ||
| 22 | pub const pthread_mutex_t = extern struct { | 22 | pub const pthread_mutex_t = extern struct { |
| ... | @@ -1606,31 +1606,34 @@ pub const KERN = struct { | ... | @@ -1606,31 +1606,34 @@ pub const KERN = struct { |
| 1606 | pub const PROC_NENV = 4; | 1606 | pub const PROC_NENV = 4; |
| 1607 | }; | 1607 | }; |
| 1608 | 1608 | ||
| 1609 | pub const HW_MACHINE = 1; | 1609 | pub const HW = struct { |
| 1610 | pub const HW_MODEL = 2; | 1610 | pub const MACHINE = 1; |
| 1611 | pub const HW_NCPU = 3; | 1611 | pub const MODEL = 2; |
| 1612 | pub const HW_BYTEORDER = 4; | 1612 | pub const NCPU = 3; |
| 1613 | pub const HW_PHYSMEM = 5; | 1613 | pub const BYTEORDER = 4; |
| 1614 | pub const HW_USERMEM = 6; | 1614 | pub const PHYSMEM = 5; |
| 1615 | pub const HW_PAGESIZE = 7; | 1615 | pub const USERMEM = 6; |
| 1616 | pub const HW_DISKNAMES = 8; | 1616 | pub const PAGESIZE = 7; |
| 1617 | pub const HW_DISKSTATS = 9; | 1617 | pub const DISKNAMES = 8; |
| 1618 | pub const HW_DISKCOUNT = 10; | 1618 | pub const DISKSTATS = 9; |
| 1619 | pub const HW_SENSORS = 11; | 1619 | pub const DISKCOUNT = 10; |
| 1620 | pub const HW_CPUSPEED = 12; | 1620 | pub const SENSORS = 11; |
| 1621 | pub const HW_SETPERF = 13; | 1621 | pub const CPUSPEED = 12; |
| 1622 | pub const HW_VENDOR = 14; | 1622 | pub const SETPERF = 13; |
| 1623 | pub const HW_PRODUCT = 15; | 1623 | pub const VENDOR = 14; |
| 1624 | pub const HW_VERSION = 16; | 1624 | pub const PRODUCT = 15; |
| 1625 | pub const HW_SERIALNO = 17; | 1625 | pub const VERSION = 16; |
| 1626 | pub const HW_UUID = 18; | 1626 | pub const SERIALNO = 17; |
| 1627 | pub const HW_PHYSMEM64 = 19; | 1627 | pub const UUID = 18; |
| 1628 | pub const HW_USERMEM64 = 20; | 1628 | pub const PHYSMEM64 = 19; |
| 1629 | pub const HW_NCPUFOUND = 21; | 1629 | pub const USERMEM64 = 20; |
| 1630 | pub const HW_ALLOWPOWERDOWN = 22; | 1630 | pub const NCPUFOUND = 21; |
| 1631 | pub const HW_PERFPOLICY = 23; | 1631 | pub const ALLOWPOWERDOWN = 22; |
| 1632 | pub const HW_SMT = 24; | 1632 | pub const PERFPOLICY = 23; |
| 1633 | pub const HW_NCPUONLINE = 25; | 1633 | pub const SMT = 24; |
| 1634 | pub const NCPUONLINE = 25; | ||
| 1635 | pub const POWER = 26; | ||
| 1636 | }; | ||
| 1634 | 1637 | ||
| 1635 | /// TODO refines if necessary | 1638 | /// TODO refines if necessary |
| 1636 | pub const PTHREAD_STACK_MIN = switch (builtin.cpu.arch) { | 1639 | pub const PTHREAD_STACK_MIN = switch (builtin.cpu.arch) { |
lib/std/os.zig+4| ... | @@ -87,6 +87,10 @@ pub const F = system.F; | ... | @@ -87,6 +87,10 @@ pub const F = system.F; |
| 87 | pub const FD_CLOEXEC = system.FD_CLOEXEC; | 87 | pub const FD_CLOEXEC = system.FD_CLOEXEC; |
| 88 | pub const Flock = system.Flock; | 88 | pub const Flock = system.Flock; |
| 89 | pub const HOST_NAME_MAX = system.HOST_NAME_MAX; | 89 | pub const HOST_NAME_MAX = system.HOST_NAME_MAX; |
| 90 | pub const HW = switch (builtin.os.tag) { | ||
| 91 | .openbsd => system.HW, | ||
| 92 | else => .{}, | ||
| 93 | }; | ||
| 90 | pub const IFNAMESIZE = system.IFNAMESIZE; | 94 | pub const IFNAMESIZE = system.IFNAMESIZE; |
| 91 | pub const IOV_MAX = system.IOV_MAX; | 95 | pub const IOV_MAX = system.IOV_MAX; |
| 92 | pub const IPPROTO = system.IPPROTO; | 96 | pub const IPPROTO = system.IPPROTO; |
lib/std/process.zig+18-1| ... | @@ -1163,7 +1163,7 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize { | ... | @@ -1163,7 +1163,7 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize { |
| 1163 | .linux => { | 1163 | .linux => { |
| 1164 | return totalSystemMemoryLinux() catch return error.UnknownTotalSystemMemory; | 1164 | return totalSystemMemoryLinux() catch return error.UnknownTotalSystemMemory; |
| 1165 | }, | 1165 | }, |
| 1166 | .freebsd, .netbsd, .openbsd, .dragonfly, .macos => { | 1166 | .freebsd, .netbsd, .dragonfly, .macos => { |
| 1167 | var physmem: c_ulong = undefined; | 1167 | var physmem: c_ulong = undefined; |
| 1168 | var len: usize = @sizeOf(c_ulong); | 1168 | var len: usize = @sizeOf(c_ulong); |
| 1169 | const name = switch (builtin.os.tag) { | 1169 | const name = switch (builtin.os.tag) { |
| ... | @@ -1177,6 +1177,23 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize { | ... | @@ -1177,6 +1177,23 @@ pub fn totalSystemMemory() TotalSystemMemoryError!usize { |
| 1177 | }; | 1177 | }; |
| 1178 | return @intCast(usize, physmem); | 1178 | return @intCast(usize, physmem); |
| 1179 | }, | 1179 | }, |
| 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 | }, | ||
| 1180 | .windows => { | 1197 | .windows => { |
| 1181 | var sbi: std.os.windows.SYSTEM_BASIC_INFORMATION = undefined; | 1198 | var sbi: std.os.windows.SYSTEM_BASIC_INFORMATION = undefined; |
| 1182 | const rc = std.os.windows.ntdll.NtQuerySystemInformation( | 1199 | const rc = std.os.windows.ntdll.NtQuerySystemInformation( |