authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-11-10 18:06:30-05:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2020-11-10 18:06:30-05:00
log8b9195282e99427964119431b6f4e535eeb4d9ba
treee15e615790822e0c925ae8eaaf686d9f808892f9
parent6904cd828edb34217cd4d54e8f6fe5bb91cb4858
parent678bd4fc8919d0683435712fbf256c3fbd4821f9
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #7044 from semarie/openbsd-simples

Simple sets of commits for OpenBSD support

3 files changed, 78 insertions(+), 4 deletions(-)

lib/std/os/bits/openbsd.zig+62-1
......@@ -32,6 +32,24 @@ pub const Kevent = extern struct {
3232 udata: usize,
3333};
3434
35// Modes and flags for dlopen()
36// include/dlfcn.h
37
38/// Bind function calls lazily.
39pub const RTLD_LAZY = 1;
40
41/// Bind function calls immediately.
42pub const RTLD_NOW = 2;
43
44/// Make symbols globally available.
45pub const RTLD_GLOBAL = 0x100;
46
47/// Opposite of RTLD_GLOBAL, and the default.
48pub const RTLD_LOCAL = 0x000;
49
50/// Trace loaded objects and exit.
51pub const RTLD_TRACE = 0x200;
52
3553pub const dl_phdr_info = extern struct {
3654 dlpi_addr: std.elf.Addr,
3755 dlpi_name: ?[*:0]const u8,
......@@ -185,7 +203,17 @@ pub const libc_stat = extern struct {
185203
186204pub const timespec = extern struct {
187205 tv_sec: time_t,
188 tv_nsec: isize,
206 tv_nsec: c_long,
207};
208
209pub const timeval = extern struct {
210 tv_sec: time_t,
211 tv_usec: c_long,
212};
213
214pub const timezone = extern struct {
215 tz_minuteswest: c_int,
216 tz_dsttime: c_int,
189217};
190218
191219pub const MAXNAMLEN = 255;
......@@ -264,10 +292,13 @@ pub const AI_ADDRCONFIG = 64;
264292
265293pub const CTL_KERN = 1;
266294pub const CTL_DEBUG = 5;
295pub const CTL_HW = 6;
267296
268297pub const KERN_PROC_ARGS = 55;
269298pub const KERN_PROC_ARGV = 1;
270299
300pub const HW_NCPUONLINE = 25;
301
271302pub const PATH_MAX = 1024;
272303
273304pub const STDIN_FILENO = 0;
......@@ -450,6 +481,36 @@ pub const SOCK_SEQPACKET = 5;
450481pub const SOCK_CLOEXEC = 0x8000;
451482pub const SOCK_NONBLOCK = 0x4000;
452483
484pub const SO_DEBUG = 0x0001;
485pub const SO_ACCEPTCONN = 0x0002;
486pub const SO_REUSEADDR = 0x0004;
487pub const SO_KEEPALIVE = 0x0008;
488pub const SO_DONTROUTE = 0x0010;
489pub const SO_BROADCAST = 0x0020;
490pub const SO_USELOOPBACK = 0x0040;
491pub const SO_LINGER = 0x0080;
492pub const SO_OOBINLINE = 0x0100;
493pub const SO_REUSEPORT = 0x0200;
494pub const SO_TIMESTAMP = 0x0800;
495pub const SO_BINDANY = 0x1000;
496pub const SO_ZEROIZE = 0x2000;
497pub const SO_SNDBUF = 0x1001;
498pub const SO_RCVBUF = 0x1002;
499pub const SO_SNDLOWAT = 0x1003;
500pub const SO_RCVLOWAT = 0x1004;
501pub const SO_SNDTIMEO = 0x1005;
502pub const SO_RCVTIMEO = 0x1006;
503pub const SO_ERROR = 0x1007;
504pub const SO_TYPE = 0x1008;
505pub const SO_NETPROC = 0x1020;
506pub const SO_RTABLE = 0x1021;
507pub const SO_PEERCRED = 0x1022;
508pub const SO_SPLICE = 0x1023;
509pub const SO_DOMAIN = 0x1024;
510pub const SO_PROTOCOL = 0x1025;
511
512pub const SOL_SOCKET = 0xffff;
513
453514pub const PF_UNSPEC = AF_UNSPEC;
454515pub const PF_LOCAL = AF_LOCAL;
455516pub const PF_UNIX = AF_UNIX;
lib/std/reset_event.zig+6-3
......@@ -109,9 +109,12 @@ const PosixEvent = struct {
109109 }
110110
111111 fn deinit(self: *PosixEvent) void {
112 // on dragonfly, *destroy() functions can return EINVAL
112 // on dragonfly or openbsd, *destroy() functions can return EINVAL
113113 // for statically initialized pthread structures
114 const err = if (builtin.os.tag == .dragonfly) os.EINVAL else 0;
114 const err = if (builtin.os.tag == .dragonfly or builtin.os.tag == .openbsd)
115 os.EINVAL
116 else
117 0;
115118
116119 const retm = c.pthread_mutex_destroy(&self.mutex);
117120 assert(retm == 0 or retm == err);
......@@ -447,7 +450,7 @@ test "ResetEvent" {
447450 fn timedWaiter(self: *Self) !void {
448451 self.in.wait();
449452 testing.expectError(error.TimedOut, self.out.timedWait(time.ns_per_us));
450 try self.out.timedWait(time.ns_per_ms * 10);
453 try self.out.timedWait(time.ns_per_ms * 100);
451454 testing.expect(self.value == 5);
452455 }
453456 };
lib/std/thread.zig+10
......@@ -491,6 +491,16 @@ pub const Thread = struct {
491491 if (std.Target.current.os.tag == .windows) {
492492 return os.windows.peb().NumberOfProcessors;
493493 }
494 if (std.Target.current.os.tag == .openbsd) {
495 var count: c_int = undefined;
496 var count_size: usize = @sizeOf(c_int);
497 const mib = [_]c_int{ os.CTL_HW, os.HW_NCPUONLINE };
498 os.sysctl(&mib, &count, &count_size, null, 0) catch |err| switch (err) {
499 error.NameTooLong, error.UnknownName => unreachable,
500 else => |e| return e,
501 };
502 return @intCast(usize, count);
503 }
494504 var count: c_int = undefined;
495505 var count_len: usize = @sizeOf(c_int);
496506 const name = if (comptime std.Target.current.isDarwin()) "hw.logicalcpu" else "hw.ncpu";