authorgravatar for 3811822-hoanga@users.noreply.gitlab.comAl Hoang <3811822-hoanga@users.noreply.gitlab.com> 2020-12-25 07:48:04-06:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-25 16:41:42-07:00
log025635c3f80912f0f967b57e6d22fe42e94b64f0
tree69a4dafe3e0909e3155642ed23d2b94ebb5595dd
parent297eabd4accbcae42bfe821078a79e4af06a2dde

initial support for haiku past stage0


13 files changed, 1527 insertions(+), 14 deletions(-)

lib/std/c/haiku.zig+27
......@@ -3,6 +3,32 @@
33// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
44// The MIT license requires this copyright notice to be included in all copies
55// and substantial portions of the software.
6
7//
8const std = @import("../std.zig");
9const builtin = std.builtin;
10
11usingnamespace std.c;
12
13extern "c" fn _errnop() *c_int;
14pub const _errno = _errnop;
15
16// not supported in haiku
17pub extern "c" fn getdents(fd: c_int, buf_ptr: [*]u8, nbytes: usize) usize;
18
19pub const dl_iterate_phdr_callback = fn (info: *dl_phdr_info, size: usize, data: ?*c_void) callconv(.C) c_int;
20//pub extern "c" fn dl_iterate_phdr(callback: dl_iterate_phdr_callback, data: ?*c_void) c_int;
21
22//
23pub const sem_t = extern struct {
24 _magic: u32,
25 _kern: extern struct {
26 _count: u32,
27 _flags: u32,
28 },
29 _padding: u32,
30};
31
632pub const pthread_mutex_t = extern struct {
733 flags: u32 = 0,
834 lock: i32 = 0,
......@@ -10,6 +36,7 @@ pub const pthread_mutex_t = extern struct {
1036 owner: i32 = -1,
1137 owner_count: i32 = 0,
1238};
39
1340pub const pthread_cond_t = extern struct {
1441 flags: u32 = 0,
1542 unused: i32 = -42,
lib/std/debug.zig+32-6
......@@ -1125,12 +1125,15 @@ pub const DebugInfo = struct {
11251125 }
11261126
11271127 pub fn getModuleForAddress(self: *DebugInfo, address: usize) !*ModuleDebugInfo {
1128 if (comptime std.Target.current.isDarwin())
1129 return self.lookupModuleDyld(address)
1130 else if (builtin.os.tag == .windows)
1131 return self.lookupModuleWin32(address)
1132 else
1128 if (comptime std.Target.current.isDarwin()) {
1129 return self.lookupModuleDyld(address);
1130 } else if (builtin.os.tag == .windows) {
1131 return self.lookupModuleWin32(address);
1132 } else if (builtin.os.tag == .haiku) {
1133 return self.lookupModuleHaiku(address);
1134 } else {
11331135 return self.lookupModuleDl(address);
1136 }
11341137 }
11351138
11361139 fn lookupModuleDyld(self: *DebugInfo, address: usize) !*ModuleDebugInfo {
......@@ -1336,6 +1339,18 @@ pub const DebugInfo = struct {
13361339
13371340 return obj_di;
13381341 }
1342
1343 fn lookupModuleHaiku(self: *DebugInfo, address: usize) !*ModuleDebugInfo {
1344 // TODO: implement me
1345 var di = ModuleDebugInfo{
1346 .base_address = undefined,
1347 .dwarf = undefined,
1348 .mapped_memory = undefined,
1349 };
1350
1351 return &di;
1352 }
1353
13391354};
13401355
13411356const SymbolInfo = struct {
......@@ -1702,6 +1717,17 @@ pub const ModuleDebugInfo = switch (builtin.os.tag) {
17021717 unreachable;
17031718 }
17041719 },
1720 .haiku => struct {
1721 // Haiku should implement dl_iterat_phdr (https://dev.haiku-os.org/ticket/15743)
1722 base_address: usize,
1723 dwarf: DW.DwarfInfo,
1724 mapped_memory: []const u8,
1725
1726 pub fn getSymbolAtAddress(self: *@This(), address: usize) !SymbolInfo {
1727 // TODO: implement me
1728 return SymbolInfo{};
1729 }
1730 },
17051731 else => DW.DwarfInfo,
17061732};
17071733
......@@ -1720,7 +1746,7 @@ fn getDebugInfoAllocator() *mem.Allocator {
17201746pub const have_segfault_handling_support = switch (builtin.os.tag) {
17211747 .linux, .netbsd => true,
17221748 .windows => true,
1723 .freebsd, .openbsd => @hasDecl(os, "ucontext_t"),
1749 .freebsd, .openbsd, .haiku => @hasDecl(os, "ucontext_t"),
17241750 else => false,
17251751};
17261752pub const enable_segfault_handler: bool = if (@hasDecl(root, "enable_segfault_handler"))
lib/std/fs.zig+15-4
......@@ -39,7 +39,7 @@ pub const Watch = @import("fs/watch.zig").Watch;
3939/// fit into a UTF-8 encoded array of this length.
4040/// The byte count includes room for a null sentinel byte.
4141pub const MAX_PATH_BYTES = switch (builtin.os.tag) {
42 .linux, .macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd => os.PATH_MAX,
42 .linux, .macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd, .haiku => os.PATH_MAX,
4343 // Each UTF-16LE character may be expanded to 3 UTF-8 bytes.
4444 // If it would require 4 UTF-8 bytes, then there would be a surrogate
4545 // pair in the UTF-16LE, and we (over)account 3 bytes for it that way.
......@@ -302,7 +302,7 @@ pub const Dir = struct {
302302 const IteratorError = error{AccessDenied} || os.UnexpectedError;
303303
304304 pub const Iterator = switch (builtin.os.tag) {
305 .macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd => struct {
305 .macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd, .haiku => struct {
306306 dir: Dir,
307307 seek: i64,
308308 buf: [8192]u8, // TODO align(@alignOf(os.dirent)),
......@@ -319,6 +319,7 @@ pub const Dir = struct {
319319 switch (builtin.os.tag) {
320320 .macos, .ios => return self.nextDarwin(),
321321 .freebsd, .netbsd, .dragonfly, .openbsd => return self.nextBsd(),
322 .haiku => return self.nextHaiku(),
322323 else => @compileError("unimplemented"),
323324 }
324325 }
......@@ -426,6 +427,16 @@ pub const Dir = struct {
426427 };
427428 }
428429 }
430
431 fn nextHaiku(self: *Self) !?Entry {
432 //const name = @ptrCast([*]u8, "placeholder-please-implement-me");
433 //const name = "placeholder-please-implement-me";
434 return Entry{
435 .name = base64_alphabet,
436 .kind = Entry.Kind.File,
437 };
438 }
439
429440 },
430441 .linux => struct {
431442 dir: Dir,
......@@ -621,7 +632,7 @@ pub const Dir = struct {
621632
622633 pub fn iterate(self: Dir) Iterator {
623634 switch (builtin.os.tag) {
624 .macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd => return Iterator{
635 .macos, .ios, .freebsd, .netbsd, .dragonfly, .openbsd, .haiku => return Iterator{
625636 .dir = self,
626637 .seek = 0,
627638 .index = 0,
......@@ -2339,7 +2350,7 @@ pub fn selfExePath(out_buffer: []u8) SelfExePathError![]u8 {
23392350 // TODO could this slice from 0 to out_len instead?
23402351 return mem.spanZ(std.meta.assumeSentinel(out_buffer.ptr, 0));
23412352 },
2342 .openbsd => {
2353 .openbsd, .haiku => {
23432354 // OpenBSD doesn't support getting the path of a running process, so try to guess it
23442355 if (os.argv.len == 0)
23452356 return error.FileNotFound;
lib/std/fs/get_app_data_dir.zig+7
......@@ -56,6 +56,13 @@ pub fn getAppDataDir(allocator: *mem.Allocator, appname: []const u8) GetAppDataD
5656 };
5757 return fs.path.join(allocator, &[_][]const u8{ home_dir, ".local", "share", appname });
5858 },
59 .haiku => {
60 const home_dir = os.getenv("HOME") orelse {
61 // TODO look in /etc/passwd
62 return error.AppDataDirUnavailable;
63 };
64 return fs.path.join(allocator, &[_][]const u8{ home_dir, "config", "settings", appname });
65 },
5966 else => @compileError("Unsupported OS"),
6067 }
6168}
lib/std/os.zig+18-1
......@@ -32,6 +32,7 @@ const MAX_PATH_BYTES = std.fs.MAX_PATH_BYTES;
3232pub const darwin = @import("os/darwin.zig");
3333pub const dragonfly = @import("os/dragonfly.zig");
3434pub const freebsd = @import("os/freebsd.zig");
35pub const haiku = @import("os/haiku.zig");
3536pub const netbsd = @import("os/netbsd.zig");
3637pub const openbsd = @import("os/openbsd.zig");
3738pub const linux = @import("os/linux.zig");
......@@ -66,6 +67,7 @@ else if (builtin.link_libc)
6667else switch (builtin.os.tag) {
6768 .macos, .ios, .watchos, .tvos => darwin,
6869 .freebsd => freebsd,
70 .haiku => haiku,
6971 .linux => linux,
7072 .netbsd => netbsd,
7173 .openbsd => openbsd,
......@@ -932,7 +934,7 @@ pub fn pwrite(fd: fd_t, bytes: []const u8, offset: u64) PWriteError!usize {
932934/// If `iov.len` is larger than will fit in a `u31`, a partial write will occur.
933935pub fn pwritev(fd: fd_t, iov: []const iovec_const, offset: u64) PWriteError!usize {
934936 const have_pwrite_but_not_pwritev = switch (std.Target.current.os.tag) {
935 .windows, .macos, .ios, .watchos, .tvos => true,
937 .windows, .macos, .ios, .watchos, .tvos, .haiku => true,
936938 else => false,
937939 };
938940
......@@ -3889,6 +3891,21 @@ pub fn pipe2(flags: u32) PipeError![2]fd_t {
38893891 }
38903892 }
38913893 }
3894 if (comptime std.Target.current.isHaiku()) {
3895 var fds: [2]fd_t = try pipe();
3896 if (flags == 0) return fds;
3897 errdefer {
3898 close(fds[0]);
3899 close(fds[1]);
3900 }
3901 for (fds) |fd| switch (errno(system.fcntl(fd, F_SETFL, flags))) {
3902 0 => {},
3903 EINVAL => unreachable, // Invalid flags
3904 EBADF => unreachable, // Always a race condition
3905 else => |err| return unexpectedErrno(err),
3906 };
3907 return fds;
3908 }
38923909
38933910 const new_flags = flags & ~@as(u32, O_CLOEXEC);
38943911 // Set every other flag affecting the file status using F_SETFL.
lib/std/os/bits.zig+1
......@@ -15,6 +15,7 @@ pub usingnamespace switch (std.Target.current.os.tag) {
1515 .macos, .ios, .tvos, .watchos => @import("bits/darwin.zig"),
1616 .dragonfly => @import("bits/dragonfly.zig"),
1717 .freebsd => @import("bits/freebsd.zig"),
18 .haiku => @import("bits/haiku.zig"),
1819 .linux => @import("bits/linux.zig"),
1920 .netbsd => @import("bits/netbsd.zig"),
2021 .openbsd => @import("bits/openbsd.zig"),
lib/std/os/bits/haiku.zig created+1394
......@@ -0,0 +1,1394 @@
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2015-2020 Zig Contributors
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.
6const std = @import("../../std.zig");
7const maxInt = std.math.maxInt;
8
9// See https://svnweb.freebsd.org/base/head/sys/sys/_types.h?view=co
10// TODO: audit pid_t/mode_t. They should likely be i32 and u16, respectively
11pub const fd_t = c_int;
12pub const pid_t = c_int;
13pub const uid_t = u32;
14pub const gid_t = u32;
15pub const mode_t = c_uint;
16
17pub const socklen_t = u32;
18
19/// Renamed from `kevent` to `Kevent` to avoid conflict with function name.
20pub const Kevent = extern struct {
21 ident: usize,
22 filter: i16,
23 flags: u16,
24 fflags: u32,
25 data: i64,
26 udata: usize,
27 // TODO ext
28};
29
30// Modes and flags for dlopen()
31// include/dlfcn.h
32
33/// Bind function calls lazily.
34pub const RTLD_LAZY = 1;
35
36/// Bind function calls immediately.
37pub const RTLD_NOW = 2;
38
39pub const RTLD_MODEMASK = 0x3;
40
41/// Make symbols globally available.
42pub const RTLD_GLOBAL = 0x100;
43
44/// Opposite of RTLD_GLOBAL, and the default.
45pub const RTLD_LOCAL = 0;
46
47/// Trace loaded objects and exit.
48pub const RTLD_TRACE = 0x200;
49
50/// Do not remove members.
51pub const RTLD_NODELETE = 0x01000;
52
53/// Do not load if not already loaded.
54pub const RTLD_NOLOAD = 0x02000;
55
56pub const dl_phdr_info = extern struct {
57 dlpi_addr: usize,
58 dlpi_name: ?[*:0]const u8,
59 dlpi_phdr: [*]std.elf.Phdr,
60 dlpi_phnum: u16,
61};
62
63pub const Flock = extern struct {
64 l_start: off_t,
65 l_len: off_t,
66 l_pid: pid_t,
67 l_type: i16,
68 l_whence: i16,
69 l_sysid: i32,
70 __unused: [4]u8,
71};
72
73pub const msghdr = extern struct {
74 /// optional address
75 msg_name: ?*sockaddr,
76
77 /// size of address
78 msg_namelen: socklen_t,
79
80 /// scatter/gather array
81 msg_iov: [*]iovec,
82
83 /// # elements in msg_iov
84 msg_iovlen: i32,
85
86 /// ancillary data
87 msg_control: ?*c_void,
88
89 /// ancillary data buffer len
90 msg_controllen: socklen_t,
91
92 /// flags on received message
93 msg_flags: i32,
94};
95
96pub const msghdr_const = extern struct {
97 /// optional address
98 msg_name: ?*const sockaddr,
99
100 /// size of address
101 msg_namelen: socklen_t,
102
103 /// scatter/gather array
104 msg_iov: [*]iovec_const,
105
106 /// # elements in msg_iov
107 msg_iovlen: i32,
108
109 /// ancillary data
110 msg_control: ?*c_void,
111
112 /// ancillary data buffer len
113 msg_controllen: socklen_t,
114
115 /// flags on received message
116 msg_flags: i32,
117};
118
119pub const off_t = i64;
120pub const ino_t = u64;
121
122pub const libc_stat = extern struct {
123 dev: u64,
124 ino: ino_t,
125 nlink: usize,
126
127 mode: u16,
128 __pad0: u16,
129 uid: uid_t,
130 gid: gid_t,
131 __pad1: u32,
132 rdev: u64,
133
134 atim: timespec,
135 mtim: timespec,
136 ctim: timespec,
137 birthtim: timespec,
138
139 size: off_t,
140 blocks: i64,
141 blksize: isize,
142 flags: u32,
143 gen: u64,
144 __spare: [10]u64,
145
146 pub fn atime(self: @This()) timespec {
147 return self.atim;
148 }
149
150 pub fn mtime(self: @This()) timespec {
151 return self.mtim;
152 }
153
154 pub fn ctime(self: @This()) timespec {
155 return self.ctim;
156 }
157};
158
159pub const timespec = extern struct {
160 tv_sec: isize,
161 tv_nsec: isize,
162};
163
164pub const dirent = extern struct {
165 d_fileno: usize,
166 d_off: i64,
167 d_reclen: u16,
168 d_type: u8,
169 d_pad0: u8,
170 d_namlen: u16,
171 d_pad1: u16,
172 d_name: [256]u8,
173
174 pub fn reclen(self: dirent) u16 {
175 return self.d_reclen;
176 }
177};
178
179pub const in_port_t = u16;
180pub const sa_family_t = u8;
181
182pub const sockaddr = extern struct {
183 /// total length
184 len: u8,
185
186 /// address family
187 family: sa_family_t,
188
189 /// actually longer; address value
190 data: [14]u8,
191};
192
193pub const sockaddr_in = extern struct {
194 len: u8 = @sizeOf(sockaddr_in),
195 family: sa_family_t = AF_INET,
196 port: in_port_t,
197 addr: u32,
198 zero: [8]u8 = [8]u8{ 0, 0, 0, 0, 0, 0, 0, 0 },
199};
200
201pub const sockaddr_in6 = extern struct {
202 len: u8 = @sizeOf(sockaddr_in6),
203 family: sa_family_t = AF_INET6,
204 port: in_port_t,
205 flowinfo: u32,
206 addr: [16]u8,
207 scope_id: u32,
208};
209
210pub const sockaddr_un = extern struct {
211 len: u8 = @sizeOf(sockaddr_un),
212 family: sa_family_t = AF_UNIX,
213 path: [104]u8,
214};
215
216pub const CTL_KERN = 1;
217pub const CTL_DEBUG = 5;
218
219pub const KERN_PROC = 14; // struct: process entries
220pub const KERN_PROC_PATHNAME = 12; // path to executable
221
222pub const PATH_MAX = 1024;
223
224pub const STDIN_FILENO = 0;
225pub const STDOUT_FILENO = 1;
226pub const STDERR_FILENO = 2;
227
228pub const PROT_NONE = 0;
229pub const PROT_READ = 1;
230pub const PROT_WRITE = 2;
231pub const PROT_EXEC = 4;
232
233pub const CLOCK_REALTIME = 0;
234pub const CLOCK_VIRTUAL = 1;
235pub const CLOCK_PROF = 2;
236pub const CLOCK_MONOTONIC = 4;
237pub const CLOCK_UPTIME = 5;
238pub const CLOCK_UPTIME_PRECISE = 7;
239pub const CLOCK_UPTIME_FAST = 8;
240pub const CLOCK_REALTIME_PRECISE = 9;
241pub const CLOCK_REALTIME_FAST = 10;
242pub const CLOCK_MONOTONIC_PRECISE = 11;
243pub const CLOCK_MONOTONIC_FAST = 12;
244pub const CLOCK_SECOND = 13;
245pub const CLOCK_THREAD_CPUTIME_ID = 14;
246pub const CLOCK_PROCESS_CPUTIME_ID = 15;
247
248pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
249pub const MAP_SHARED = 0x0001;
250pub const MAP_PRIVATE = 0x0002;
251pub const MAP_FIXED = 0x0010;
252pub const MAP_STACK = 0x0400;
253pub const MAP_NOSYNC = 0x0800;
254pub const MAP_ANON = 0x1000;
255pub const MAP_ANONYMOUS = MAP_ANON;
256pub const MAP_FILE = 0;
257
258pub const MAP_GUARD = 0x00002000;
259pub const MAP_EXCL = 0x00004000;
260pub const MAP_NOCORE = 0x00020000;
261pub const MAP_PREFAULT_READ = 0x00040000;
262pub const MAP_32BIT = 0x00080000;
263
264pub const WNOHANG = 1;
265pub const WUNTRACED = 2;
266pub const WSTOPPED = WUNTRACED;
267pub const WCONTINUED = 4;
268pub const WNOWAIT = 8;
269pub const WEXITED = 16;
270pub const WTRAPPED = 32;
271
272pub const SA_ONSTACK = 0x0001;
273pub const SA_RESTART = 0x0002;
274pub const SA_RESETHAND = 0x0004;
275pub const SA_NOCLDSTOP = 0x0008;
276pub const SA_NODEFER = 0x0010;
277pub const SA_NOCLDWAIT = 0x0020;
278pub const SA_SIGINFO = 0x0040;
279
280pub const SIGHUP = 1;
281pub const SIGINT = 2;
282pub const SIGQUIT = 3;
283pub const SIGILL = 4;
284pub const SIGTRAP = 5;
285pub const SIGABRT = 6;
286pub const SIGIOT = SIGABRT;
287pub const SIGEMT = 7;
288pub const SIGFPE = 8;
289pub const SIGKILL = 9;
290pub const SIGBUS = 10;
291pub const SIGSEGV = 11;
292pub const SIGSYS = 12;
293pub const SIGPIPE = 13;
294pub const SIGALRM = 14;
295pub const SIGTERM = 15;
296pub const SIGURG = 16;
297pub const SIGSTOP = 17;
298pub const SIGTSTP = 18;
299pub const SIGCONT = 19;
300pub const SIGCHLD = 20;
301pub const SIGTTIN = 21;
302pub const SIGTTOU = 22;
303pub const SIGIO = 23;
304pub const SIGXCPU = 24;
305pub const SIGXFSZ = 25;
306pub const SIGVTALRM = 26;
307pub const SIGPROF = 27;
308pub const SIGWINCH = 28;
309pub const SIGINFO = 29;
310pub const SIGUSR1 = 30;
311pub const SIGUSR2 = 31;
312pub const SIGTHR = 32;
313pub const SIGLWP = SIGTHR;
314pub const SIGLIBRT = 33;
315
316pub const SIGRTMIN = 65;
317pub const SIGRTMAX = 126;
318
319// access function
320pub const F_OK = 0; // test for existence of file
321pub const X_OK = 1; // test for execute or search permission
322pub const W_OK = 2; // test for write permission
323pub const R_OK = 4; // test for read permission
324
325pub const O_RDONLY = 0x0000;
326pub const O_WRONLY = 0x0001;
327pub const O_RDWR = 0x0002;
328pub const O_ACCMODE = 0x0003;
329
330pub const O_SHLOCK = 0x0010;
331pub const O_EXLOCK = 0x0020;
332
333pub const O_CREAT = 0x0200;
334pub const O_EXCL = 0x0800;
335pub const O_NOCTTY = 0x8000;
336pub const O_TRUNC = 0x0400;
337pub const O_APPEND = 0x0008;
338pub const O_NONBLOCK = 0x0004;
339pub const O_DSYNC = 0o10000;
340pub const O_SYNC = 0x0080;
341pub const O_RSYNC = 0o4010000;
342pub const O_DIRECTORY = 0x20000;
343pub const O_NOFOLLOW = 0x0100;
344pub const O_CLOEXEC = 0x00100000;
345
346pub const O_ASYNC = 0x0040;
347pub const O_DIRECT = 0x00010000;
348pub const O_NOATIME = 0o1000000;
349pub const O_PATH = 0o10000000;
350pub const O_TMPFILE = 0o20200000;
351pub const O_NDELAY = O_NONBLOCK;
352
353pub const F_DUPFD = 0;
354pub const F_GETFD = 1;
355pub const F_SETFD = 2;
356pub const F_GETFL = 3;
357pub const F_SETFL = 4;
358
359pub const F_GETOWN = 5;
360pub const F_SETOWN = 6;
361
362pub const F_GETLK = 11;
363pub const F_SETLK = 12;
364pub const F_SETLKW = 13;
365
366pub const F_RDLCK = 1;
367pub const F_WRLCK = 3;
368pub const F_UNLCK = 2;
369
370pub const LOCK_SH = 1;
371pub const LOCK_EX = 2;
372pub const LOCK_UN = 8;
373pub const LOCK_NB = 4;
374
375pub const F_SETOWN_EX = 15;
376pub const F_GETOWN_EX = 16;
377
378pub const F_GETOWNER_UIDS = 17;
379
380pub const FD_CLOEXEC = 1;
381
382pub const SEEK_SET = 0;
383pub const SEEK_CUR = 1;
384pub const SEEK_END = 2;
385
386pub const SIG_BLOCK = 1;
387pub const SIG_UNBLOCK = 2;
388pub const SIG_SETMASK = 3;
389
390pub const SOCK_STREAM = 1;
391pub const SOCK_DGRAM = 2;
392pub const SOCK_RAW = 3;
393pub const SOCK_RDM = 4;
394pub const SOCK_SEQPACKET = 5;
395
396pub const SOCK_CLOEXEC = 0x10000000;
397pub const SOCK_NONBLOCK = 0x20000000;
398
399pub const SO_DEBUG = 0x00000001;
400pub const SO_ACCEPTCONN = 0x00000002;
401pub const SO_REUSEADDR = 0x00000004;
402pub const SO_KEEPALIVE = 0x00000008;
403pub const SO_DONTROUTE = 0x00000010;
404pub const SO_BROADCAST = 0x00000020;
405pub const SO_USELOOPBACK = 0x00000040;
406pub const SO_LINGER = 0x00000080;
407pub const SO_OOBINLINE = 0x00000100;
408pub const SO_REUSEPORT = 0x00000200;
409pub const SO_TIMESTAMP = 0x00000400;
410pub const SO_NOSIGPIPE = 0x00000800;
411pub const SO_ACCEPTFILTER = 0x00001000;
412pub const SO_BINTIME = 0x00002000;
413pub const SO_NO_OFFLOAD = 0x00004000;
414pub const SO_NO_DDP = 0x00008000;
415pub const SO_REUSEPORT_LB = 0x00010000;
416
417pub const SO_SNDBUF = 0x1001;
418pub const SO_RCVBUF = 0x1002;
419pub const SO_SNDLOWAT = 0x1003;
420pub const SO_RCVLOWAT = 0x1004;
421pub const SO_SNDTIMEO = 0x1005;
422pub const SO_RCVTIMEO = 0x1006;
423pub const SO_ERROR = 0x1007;
424pub const SO_TYPE = 0x1008;
425pub const SO_LABEL = 0x1009;
426pub const SO_PEERLABEL = 0x1010;
427pub const SO_LISTENQLIMIT = 0x1011;
428pub const SO_LISTENQLEN = 0x1012;
429pub const SO_LISTENINCQLEN = 0x1013;
430pub const SO_SETFIB = 0x1014;
431pub const SO_USER_COOKIE = 0x1015;
432pub const SO_PROTOCOL = 0x1016;
433pub const SO_PROTOTYPE = SO_PROTOCOL;
434pub const SO_TS_CLOCK = 0x1017;
435pub const SO_MAX_PACING_RATE = 0x1018;
436pub const SO_DOMAIN = 0x1019;
437
438pub const SOL_SOCKET = 0xffff;
439
440pub const PF_UNSPEC = AF_UNSPEC;
441pub const PF_LOCAL = AF_LOCAL;
442pub const PF_UNIX = PF_LOCAL;
443pub const PF_INET = AF_INET;
444pub const PF_IMPLINK = AF_IMPLINK;
445pub const PF_PUP = AF_PUP;
446pub const PF_CHAOS = AF_CHAOS;
447pub const PF_NETBIOS = AF_NETBIOS;
448pub const PF_ISO = AF_ISO;
449pub const PF_OSI = AF_ISO;
450pub const PF_ECMA = AF_ECMA;
451pub const PF_DATAKIT = AF_DATAKIT;
452pub const PF_CCITT = AF_CCITT;
453pub const PF_DECnet = AF_DECnet;
454pub const PF_DLI = AF_DLI;
455pub const PF_LAT = AF_LAT;
456pub const PF_HYLINK = AF_HYLINK;
457pub const PF_APPLETALK = AF_APPLETALK;
458pub const PF_ROUTE = AF_ROUTE;
459pub const PF_LINK = AF_LINK;
460pub const PF_XTP = pseudo_AF_XTP;
461pub const PF_COIP = AF_COIP;
462pub const PF_CNT = AF_CNT;
463pub const PF_SIP = AF_SIP;
464pub const PF_IPX = AF_IPX;
465pub const PF_RTIP = pseudo_AF_RTIP;
466pub const PF_PIP = psuedo_AF_PIP;
467pub const PF_ISDN = AF_ISDN;
468pub const PF_KEY = pseudo_AF_KEY;
469pub const PF_INET6 = pseudo_AF_INET6;
470pub const PF_NATM = AF_NATM;
471pub const PF_ATM = AF_ATM;
472pub const PF_NETGRAPH = AF_NETGRAPH;
473pub const PF_SLOW = AF_SLOW;
474pub const PF_SCLUSTER = AF_SCLUSTER;
475pub const PF_ARP = AF_ARP;
476pub const PF_BLUETOOTH = AF_BLUETOOTH;
477pub const PF_IEEE80211 = AF_IEEE80211;
478pub const PF_INET_SDP = AF_INET_SDP;
479pub const PF_INET6_SDP = AF_INET6_SDP;
480pub const PF_MAX = AF_MAX;
481
482pub const AF_UNSPEC = 0;
483pub const AF_UNIX = 1;
484pub const AF_LOCAL = AF_UNIX;
485pub const AF_FILE = AF_LOCAL;
486pub const AF_INET = 2;
487pub const AF_IMPLINK = 3;
488pub const AF_PUP = 4;
489pub const AF_CHAOS = 5;
490pub const AF_NETBIOS = 6;
491pub const AF_ISO = 7;
492pub const AF_OSI = AF_ISO;
493pub const AF_ECMA = 8;
494pub const AF_DATAKIT = 9;
495pub const AF_CCITT = 10;
496pub const AF_SNA = 11;
497pub const AF_DECnet = 12;
498pub const AF_DLI = 13;
499pub const AF_LAT = 14;
500pub const AF_HYLINK = 15;
501pub const AF_APPLETALK = 16;
502pub const AF_ROUTE = 17;
503pub const AF_LINK = 18;
504pub const pseudo_AF_XTP = 19;
505pub const AF_COIP = 20;
506pub const AF_CNT = 21;
507pub const pseudo_AF_RTIP = 22;
508pub const AF_IPX = 23;
509pub const AF_SIP = 24;
510pub const pseudo_AF_PIP = 25;
511pub const AF_ISDN = 26;
512pub const AF_E164 = AF_ISDN;
513pub const pseudo_AF_KEY = 27;
514pub const AF_INET6 = 28;
515pub const AF_NATM = 29;
516pub const AF_ATM = 30;
517pub const pseudo_AF_HDRCMPLT = 31;
518pub const AF_NETGRAPH = 32;
519pub const AF_SLOW = 33;
520pub const AF_SCLUSTER = 34;
521pub const AF_ARP = 35;
522pub const AF_BLUETOOTH = 36;
523pub const AF_IEEE80211 = 37;
524pub const AF_INET_SDP = 40;
525pub const AF_INET6_SDP = 42;
526pub const AF_MAX = 42;
527
528pub const DT_UNKNOWN = 0;
529pub const DT_FIFO = 1;
530pub const DT_CHR = 2;
531pub const DT_DIR = 4;
532pub const DT_BLK = 6;
533pub const DT_REG = 8;
534pub const DT_LNK = 10;
535pub const DT_SOCK = 12;
536pub const DT_WHT = 14;
537
538/// add event to kq (implies enable)
539pub const EV_ADD = 0x0001;
540
541/// delete event from kq
542pub const EV_DELETE = 0x0002;
543
544/// enable event
545pub const EV_ENABLE = 0x0004;
546
547/// disable event (not reported)
548pub const EV_DISABLE = 0x0008;
549
550/// only report one occurrence
551pub const EV_ONESHOT = 0x0010;
552
553/// clear event state after reporting
554pub const EV_CLEAR = 0x0020;
555
556/// force immediate event output
557/// ... with or without EV_ERROR
558/// ... use KEVENT_FLAG_ERROR_EVENTS
559/// on syscalls supporting flags
560pub const EV_RECEIPT = 0x0040;
561
562/// disable event after reporting
563pub const EV_DISPATCH = 0x0080;
564
565pub const EVFILT_READ = -1;
566pub const EVFILT_WRITE = -2;
567
568/// attached to aio requests
569pub const EVFILT_AIO = -3;
570
571/// attached to vnodes
572pub const EVFILT_VNODE = -4;
573
574/// attached to struct proc
575pub const EVFILT_PROC = -5;
576
577/// attached to struct proc
578pub const EVFILT_SIGNAL = -6;
579
580/// timers
581pub const EVFILT_TIMER = -7;
582
583/// Process descriptors
584pub const EVFILT_PROCDESC = -8;
585
586/// Filesystem events
587pub const EVFILT_FS = -9;
588
589pub const EVFILT_LIO = -10;
590
591/// User events
592pub const EVFILT_USER = -11;
593
594/// Sendfile events
595pub const EVFILT_SENDFILE = -12;
596
597pub const EVFILT_EMPTY = -13;
598
599/// On input, NOTE_TRIGGER causes the event to be triggered for output.
600pub const NOTE_TRIGGER = 0x01000000;
601
602/// ignore input fflags
603pub const NOTE_FFNOP = 0x00000000;
604
605/// and fflags
606pub const NOTE_FFAND = 0x40000000;
607
608/// or fflags
609pub const NOTE_FFOR = 0x80000000;
610
611/// copy fflags
612pub const NOTE_FFCOPY = 0xc0000000;
613
614/// mask for operations
615pub const NOTE_FFCTRLMASK = 0xc0000000;
616pub const NOTE_FFLAGSMASK = 0x00ffffff;
617
618/// low water mark
619pub const NOTE_LOWAT = 0x00000001;
620
621/// behave like poll()
622pub const NOTE_FILE_POLL = 0x00000002;
623
624/// vnode was removed
625pub const NOTE_DELETE = 0x00000001;
626
627/// data contents changed
628pub const NOTE_WRITE = 0x00000002;
629
630/// size increased
631pub const NOTE_EXTEND = 0x00000004;
632
633/// attributes changed
634pub const NOTE_ATTRIB = 0x00000008;
635
636/// link count changed
637pub const NOTE_LINK = 0x00000010;
638
639/// vnode was renamed
640pub const NOTE_RENAME = 0x00000020;
641
642/// vnode access was revoked
643pub const NOTE_REVOKE = 0x00000040;
644
645/// vnode was opened
646pub const NOTE_OPEN = 0x00000080;
647
648/// file closed, fd did not allow write
649pub const NOTE_CLOSE = 0x00000100;
650
651/// file closed, fd did allow write
652pub const NOTE_CLOSE_WRITE = 0x00000200;
653
654/// file was read
655pub const NOTE_READ = 0x00000400;
656
657/// process exited
658pub const NOTE_EXIT = 0x80000000;
659
660/// process forked
661pub const NOTE_FORK = 0x40000000;
662
663/// process exec'd
664pub const NOTE_EXEC = 0x20000000;
665
666/// mask for signal & exit status
667pub const NOTE_PDATAMASK = 0x000fffff;
668pub const NOTE_PCTRLMASK = (~NOTE_PDATAMASK);
669
670/// data is seconds
671pub const NOTE_SECONDS = 0x00000001;
672
673/// data is milliseconds
674pub const NOTE_MSECONDS = 0x00000002;
675
676/// data is microseconds
677pub const NOTE_USECONDS = 0x00000004;
678
679/// data is nanoseconds
680pub const NOTE_NSECONDS = 0x00000008;
681
682/// timeout is absolute
683pub const NOTE_ABSTIME = 0x00000010;
684
685pub const TIOCEXCL = 0x2000740d;
686pub const TIOCNXCL = 0x2000740e;
687pub const TIOCSCTTY = 0x20007461;
688pub const TIOCGPGRP = 0x40047477;
689pub const TIOCSPGRP = 0x80047476;
690pub const TIOCOUTQ = 0x40047473;
691pub const TIOCSTI = 0x80017472;
692pub const TIOCGWINSZ = 0x40087468;
693pub const TIOCSWINSZ = 0x80087467;
694pub const TIOCMGET = 0x4004746a;
695pub const TIOCMBIS = 0x8004746c;
696pub const TIOCMBIC = 0x8004746b;
697pub const TIOCMSET = 0x8004746d;
698pub const FIONREAD = 0x4004667f;
699pub const TIOCCONS = 0x80047462;
700pub const TIOCPKT = 0x80047470;
701pub const FIONBIO = 0x8004667e;
702pub const TIOCNOTTY = 0x20007471;
703pub const TIOCSETD = 0x8004741b;
704pub const TIOCGETD = 0x4004741a;
705pub const TIOCSBRK = 0x2000747b;
706pub const TIOCCBRK = 0x2000747a;
707pub const TIOCGSID = 0x40047463;
708pub const TIOCGPTN = 0x4004740f;
709pub const TIOCSIG = 0x2004745f;
710
711pub fn WEXITSTATUS(s: u32) u32 {
712 return (s & 0xff00) >> 8;
713}
714pub fn WTERMSIG(s: u32) u32 {
715 return s & 0x7f;
716}
717pub fn WSTOPSIG(s: u32) u32 {
718 return WEXITSTATUS(s);
719}
720pub fn WIFEXITED(s: u32) bool {
721 return WTERMSIG(s) == 0;
722}
723pub fn WIFSTOPPED(s: u32) bool {
724 return @intCast(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
725}
726pub fn WIFSIGNALED(s: u32) bool {
727 return (s & 0xffff) -% 1 < 0xff;
728}
729
730pub const winsize = extern struct {
731 ws_row: u16,
732 ws_col: u16,
733 ws_xpixel: u16,
734 ws_ypixel: u16,
735};
736
737const NSIG = 32;
738
739pub const SIG_ERR = @intToPtr(fn (i32) callconv(.C) void, maxInt(usize));
740pub const SIG_DFL = @intToPtr(fn (i32) callconv(.C) void, 0);
741pub const SIG_IGN = @intToPtr(fn (i32) callconv(.C) void, 1);
742
743/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
744pub const Sigaction = extern struct {
745 /// signal handler
746 __sigaction_u: extern union {
747 __sa_handler: fn (i32) callconv(.C) void,
748 __sa_sigaction: fn (i32, *__siginfo, usize) callconv(.C) void,
749 },
750
751 /// see signal options
752 sa_flags: u32,
753
754 /// signal mask to apply
755 sa_mask: sigset_t,
756};
757
758pub const _SIG_WORDS = 4;
759pub const _SIG_MAXSIG = 128;
760
761pub inline fn _SIG_IDX(sig: usize) usize {
762 return sig - 1;
763}
764pub inline fn _SIG_WORD(sig: usize) usize {
765 return_SIG_IDX(sig) >> 5;
766}
767pub inline fn _SIG_BIT(sig: usize) usize {
768 return 1 << (_SIG_IDX(sig) & 31);
769}
770pub inline fn _SIG_VALID(sig: usize) usize {
771 return sig <= _SIG_MAXSIG and sig > 0;
772}
773
774pub const sigset_t = extern struct {
775 __bits: [_SIG_WORDS]u32,
776};
777
778pub const EPERM = 1; // Operation not permitted
779pub const ENOENT = 2; // No such file or directory
780pub const ESRCH = 3; // No such process
781pub const EINTR = 4; // Interrupted system call
782pub const EIO = 5; // Input/output error
783pub const ENXIO = 6; // Device not configured
784pub const E2BIG = 7; // Argument list too long
785pub const ENOEXEC = 8; // Exec format error
786pub const EBADF = 9; // Bad file descriptor
787pub const ECHILD = 10; // No child processes
788pub const EDEADLK = 11; // Resource deadlock avoided
789// 11 was EAGAIN
790pub const ENOMEM = 12; // Cannot allocate memory
791pub const EACCES = 13; // Permission denied
792pub const EFAULT = 14; // Bad address
793pub const ENOTBLK = 15; // Block device required
794pub const EBUSY = 16; // Device busy
795pub const EEXIST = 17; // File exists
796pub const EXDEV = 18; // Cross-device link
797pub const ENODEV = 19; // Operation not supported by device
798pub const ENOTDIR = 20; // Not a directory
799pub const EISDIR = 21; // Is a directory
800pub const EINVAL = 22; // Invalid argument
801pub const ENFILE = 23; // Too many open files in system
802pub const EMFILE = 24; // Too many open files
803pub const ENOTTY = 25; // Inappropriate ioctl for device
804pub const ETXTBSY = 26; // Text file busy
805pub const EFBIG = 27; // File too large
806pub const ENOSPC = 28; // No space left on device
807pub const ESPIPE = 29; // Illegal seek
808pub const EROFS = 30; // Read-only filesystem
809pub const EMLINK = 31; // Too many links
810pub const EPIPE = 32; // Broken pipe
811
812// math software
813pub const EDOM = 33; // Numerical argument out of domain
814pub const ERANGE = 34; // Result too large
815
816// non-blocking and interrupt i/o
817pub const EAGAIN = 35; // Resource temporarily unavailable
818pub const EWOULDBLOCK = EAGAIN; // Operation would block
819pub const EINPROGRESS = 36; // Operation now in progress
820pub const EALREADY = 37; // Operation already in progress
821
822// ipc/network software -- argument errors
823pub const ENOTSOCK = 38; // Socket operation on non-socket
824pub const EDESTADDRREQ = 39; // Destination address required
825pub const EMSGSIZE = 40; // Message too long
826pub const EPROTOTYPE = 41; // Protocol wrong type for socket
827pub const ENOPROTOOPT = 42; // Protocol not available
828pub const EPROTONOSUPPORT = 43; // Protocol not supported
829pub const ESOCKTNOSUPPORT = 44; // Socket type not supported
830pub const EOPNOTSUPP = 45; // Operation not supported
831pub const ENOTSUP = EOPNOTSUPP; // Operation not supported
832pub const EPFNOSUPPORT = 46; // Protocol family not supported
833pub const EAFNOSUPPORT = 47; // Address family not supported by protocol family
834pub const EADDRINUSE = 48; // Address already in use
835pub const EADDRNOTAVAIL = 49; // Can't assign requested address
836
837// ipc/network software -- operational errors
838pub const ENETDOWN = 50; // Network is down
839pub const ENETUNREACH = 51; // Network is unreachable
840pub const ENETRESET = 52; // Network dropped connection on reset
841pub const ECONNABORTED = 53; // Software caused connection abort
842pub const ECONNRESET = 54; // Connection reset by peer
843pub const ENOBUFS = 55; // No buffer space available
844pub const EISCONN = 56; // Socket is already connected
845pub const ENOTCONN = 57; // Socket is not connected
846pub const ESHUTDOWN = 58; // Can't send after socket shutdown
847pub const ETOOMANYREFS = 59; // Too many references: can't splice
848pub const ETIMEDOUT = 60; // Operation timed out
849pub const ECONNREFUSED = 61; // Connection refused
850
851pub const ELOOP = 62; // Too many levels of symbolic links
852pub const ENAMETOOLONG = 63; // File name too long
853
854// should be rearranged
855pub const EHOSTDOWN = 64; // Host is down
856pub const EHOSTUNREACH = 65; // No route to host
857pub const ENOTEMPTY = 66; // Directory not empty
858
859// quotas & mush
860pub const EPROCLIM = 67; // Too many processes
861pub const EUSERS = 68; // Too many users
862pub const EDQUOT = 69; // Disc quota exceeded
863
864// Network File System
865pub const ESTALE = 70; // Stale NFS file handle
866pub const EREMOTE = 71; // Too many levels of remote in path
867pub const EBADRPC = 72; // RPC struct is bad
868pub const ERPCMISMATCH = 73; // RPC version wrong
869pub const EPROGUNAVAIL = 74; // RPC prog. not avail
870pub const EPROGMISMATCH = 75; // Program version wrong
871pub const EPROCUNAVAIL = 76; // Bad procedure for program
872
873pub const ENOLCK = 77; // No locks available
874pub const ENOSYS = 78; // Function not implemented
875
876pub const EFTYPE = 79; // Inappropriate file type or format
877pub const EAUTH = 80; // Authentication error
878pub const ENEEDAUTH = 81; // Need authenticator
879pub const EIDRM = 82; // Identifier removed
880pub const ENOMSG = 83; // No message of desired type
881pub const EOVERFLOW = 84; // Value too large to be stored in data type
882pub const ECANCELED = 85; // Operation canceled
883pub const EILSEQ = 86; // Illegal byte sequence
884pub const ENOATTR = 87; // Attribute not found
885
886pub const EDOOFUS = 88; // Programming error
887
888pub const EBADMSG = 89; // Bad message
889pub const EMULTIHOP = 90; // Multihop attempted
890pub const ENOLINK = 91; // Link has been severed
891pub const EPROTO = 92; // Protocol error
892
893pub const ENOTCAPABLE = 93; // Capabilities insufficient
894pub const ECAPMODE = 94; // Not permitted in capability mode
895pub const ENOTRECOVERABLE = 95; // State not recoverable
896pub const EOWNERDEAD = 96; // Previous owner died
897
898pub const ELAST = 96; // Must be equal largest errno
899
900pub const MINSIGSTKSZ = switch (builtin.arch) {
901 .i386, .x86_64 => 2048,
902 .arm, .aarch64 => 4096,
903 else => @compileError("MINSIGSTKSZ not defined for this architecture"),
904};
905pub const SIGSTKSZ = MINSIGSTKSZ + 32768;
906
907pub const SS_ONSTACK = 1;
908pub const SS_DISABLE = 4;
909
910pub const stack_t = extern struct {
911 ss_sp: [*]u8,
912 ss_size: isize,
913 ss_flags: i32,
914};
915
916pub const S_IFMT = 0o170000;
917
918pub const S_IFIFO = 0o010000;
919pub const S_IFCHR = 0o020000;
920pub const S_IFDIR = 0o040000;
921pub const S_IFBLK = 0o060000;
922pub const S_IFREG = 0o100000;
923pub const S_IFLNK = 0o120000;
924pub const S_IFSOCK = 0o140000;
925pub const S_IFWHT = 0o160000;
926
927pub const S_ISUID = 0o4000;
928pub const S_ISGID = 0o2000;
929pub const S_ISVTX = 0o1000;
930pub const S_IRWXU = 0o700;
931pub const S_IRUSR = 0o400;
932pub const S_IWUSR = 0o200;
933pub const S_IXUSR = 0o100;
934pub const S_IRWXG = 0o070;
935pub const S_IRGRP = 0o040;
936pub const S_IWGRP = 0o020;
937pub const S_IXGRP = 0o010;
938pub const S_IRWXO = 0o007;
939pub const S_IROTH = 0o004;
940pub const S_IWOTH = 0o002;
941pub const S_IXOTH = 0o001;
942
943pub fn S_ISFIFO(m: u32) bool {
944 return m & S_IFMT == S_IFIFO;
945}
946
947pub fn S_ISCHR(m: u32) bool {
948 return m & S_IFMT == S_IFCHR;
949}
950
951pub fn S_ISDIR(m: u32) bool {
952 return m & S_IFMT == S_IFDIR;
953}
954
955pub fn S_ISBLK(m: u32) bool {
956 return m & S_IFMT == S_IFBLK;
957}
958
959pub fn S_ISREG(m: u32) bool {
960 return m & S_IFMT == S_IFREG;
961}
962
963pub fn S_ISLNK(m: u32) bool {
964 return m & S_IFMT == S_IFLNK;
965}
966
967pub fn S_ISSOCK(m: u32) bool {
968 return m & S_IFMT == S_IFSOCK;
969}
970
971pub fn S_IWHT(m: u32) bool {
972 return m & S_IFMT == S_IFWHT;
973}
974
975pub const HOST_NAME_MAX = 255;
976
977/// Magic value that specify the use of the current working directory
978/// to determine the target of relative file paths in the openat() and
979/// similar syscalls.
980pub const AT_FDCWD = -100;
981
982/// Check access using effective user and group ID
983pub const AT_EACCESS = 0x0100;
984
985/// Do not follow symbolic links
986pub const AT_SYMLINK_NOFOLLOW = 0x0200;
987
988/// Follow symbolic link
989pub const AT_SYMLINK_FOLLOW = 0x0400;
990
991/// Remove directory instead of file
992pub const AT_REMOVEDIR = 0x0800;
993
994pub const addrinfo = extern struct {
995 flags: i32,
996 family: i32,
997 socktype: i32,
998 protocol: i32,
999 addrlen: socklen_t,
1000 canonname: ?[*:0]u8,
1001 addr: ?*sockaddr,
1002 next: ?*addrinfo,
1003};
1004
1005/// Fail if not under dirfd
1006pub const AT_BENEATH = 0x1000;
1007
1008/// dummy for IP
1009pub const IPPROTO_IP = 0;
1010
1011/// control message protocol
1012pub const IPPROTO_ICMP = 1;
1013
1014/// tcp
1015pub const IPPROTO_TCP = 6;
1016
1017/// user datagram protocol
1018pub const IPPROTO_UDP = 17;
1019
1020/// IP6 header
1021pub const IPPROTO_IPV6 = 41;
1022
1023/// raw IP packet
1024pub const IPPROTO_RAW = 255;
1025
1026/// IP6 hop-by-hop options
1027pub const IPPROTO_HOPOPTS = 0;
1028
1029/// group mgmt protocol
1030pub const IPPROTO_IGMP = 2;
1031
1032/// gateway^2 (deprecated)
1033pub const IPPROTO_GGP = 3;
1034
1035/// IPv4 encapsulation
1036pub const IPPROTO_IPV4 = 4;
1037
1038/// for compatibility
1039pub const IPPROTO_IPIP = IPPROTO_IPV4;
1040
1041/// Stream protocol II
1042pub const IPPROTO_ST = 7;
1043
1044/// exterior gateway protocol
1045pub const IPPROTO_EGP = 8;
1046
1047/// private interior gateway
1048pub const IPPROTO_PIGP = 9;
1049
1050/// BBN RCC Monitoring
1051pub const IPPROTO_RCCMON = 10;
1052
1053/// network voice protocol
1054pub const IPPROTO_NVPII = 11;
1055
1056/// pup
1057pub const IPPROTO_PUP = 12;
1058
1059/// Argus
1060pub const IPPROTO_ARGUS = 13;
1061
1062/// EMCON
1063pub const IPPROTO_EMCON = 14;
1064
1065/// Cross Net Debugger
1066pub const IPPROTO_XNET = 15;
1067
1068/// Chaos
1069pub const IPPROTO_CHAOS = 16;
1070
1071/// Multiplexing
1072pub const IPPROTO_MUX = 18;
1073
1074/// DCN Measurement Subsystems
1075pub const IPPROTO_MEAS = 19;
1076
1077/// Host Monitoring
1078pub const IPPROTO_HMP = 20;
1079
1080/// Packet Radio Measurement
1081pub const IPPROTO_PRM = 21;
1082
1083/// xns idp
1084pub const IPPROTO_IDP = 22;
1085
1086/// Trunk-1
1087pub const IPPROTO_TRUNK1 = 23;
1088
1089/// Trunk-2
1090pub const IPPROTO_TRUNK2 = 24;
1091
1092/// Leaf-1
1093pub const IPPROTO_LEAF1 = 25;
1094
1095/// Leaf-2
1096pub const IPPROTO_LEAF2 = 26;
1097
1098/// Reliable Data
1099pub const IPPROTO_RDP = 27;
1100
1101/// Reliable Transaction
1102pub const IPPROTO_IRTP = 28;
1103
1104/// tp-4 w/ class negotiation
1105pub const IPPROTO_TP = 29;
1106
1107/// Bulk Data Transfer
1108pub const IPPROTO_BLT = 30;
1109
1110/// Network Services
1111pub const IPPROTO_NSP = 31;
1112
1113/// Merit Internodal
1114pub const IPPROTO_INP = 32;
1115
1116/// Datagram Congestion Control Protocol
1117pub const IPPROTO_DCCP = 33;
1118
1119/// Third Party Connect
1120pub const IPPROTO_3PC = 34;
1121
1122/// InterDomain Policy Routing
1123pub const IPPROTO_IDPR = 35;
1124
1125/// XTP
1126pub const IPPROTO_XTP = 36;
1127
1128/// Datagram Delivery
1129pub const IPPROTO_DDP = 37;
1130
1131/// Control Message Transport
1132pub const IPPROTO_CMTP = 38;
1133
1134/// TP++ Transport
1135pub const IPPROTO_TPXX = 39;
1136
1137/// IL transport protocol
1138pub const IPPROTO_IL = 40;
1139
1140/// Source Demand Routing
1141pub const IPPROTO_SDRP = 42;
1142
1143/// IP6 routing header
1144pub const IPPROTO_ROUTING = 43;
1145
1146/// IP6 fragmentation header
1147pub const IPPROTO_FRAGMENT = 44;
1148
1149/// InterDomain Routing
1150pub const IPPROTO_IDRP = 45;
1151
1152/// resource reservation
1153pub const IPPROTO_RSVP = 46;
1154
1155/// General Routing Encap.
1156pub const IPPROTO_GRE = 47;
1157
1158/// Mobile Host Routing
1159pub const IPPROTO_MHRP = 48;
1160
1161/// BHA
1162pub const IPPROTO_BHA = 49;
1163
1164/// IP6 Encap Sec. Payload
1165pub const IPPROTO_ESP = 50;
1166
1167/// IP6 Auth Header
1168pub const IPPROTO_AH = 51;
1169
1170/// Integ. Net Layer Security
1171pub const IPPROTO_INLSP = 52;
1172
1173/// IP with encryption
1174pub const IPPROTO_SWIPE = 53;
1175
1176/// Next Hop Resolution
1177pub const IPPROTO_NHRP = 54;
1178
1179/// IP Mobility
1180pub const IPPROTO_MOBILE = 55;
1181
1182/// Transport Layer Security
1183pub const IPPROTO_TLSP = 56;
1184
1185/// SKIP
1186pub const IPPROTO_SKIP = 57;
1187
1188/// ICMP6
1189pub const IPPROTO_ICMPV6 = 58;
1190
1191/// IP6 no next header
1192pub const IPPROTO_NONE = 59;
1193
1194/// IP6 destination option
1195pub const IPPROTO_DSTOPTS = 60;
1196
1197/// any host internal protocol
1198pub const IPPROTO_AHIP = 61;
1199
1200/// CFTP
1201pub const IPPROTO_CFTP = 62;
1202
1203/// "hello" routing protocol
1204pub const IPPROTO_HELLO = 63;
1205
1206/// SATNET/Backroom EXPAK
1207pub const IPPROTO_SATEXPAK = 64;
1208
1209/// Kryptolan
1210pub const IPPROTO_KRYPTOLAN = 65;
1211
1212/// Remote Virtual Disk
1213pub const IPPROTO_RVD = 66;
1214
1215/// Pluribus Packet Core
1216pub const IPPROTO_IPPC = 67;
1217
1218/// Any distributed FS
1219pub const IPPROTO_ADFS = 68;
1220
1221/// Satnet Monitoring
1222pub const IPPROTO_SATMON = 69;
1223
1224/// VISA Protocol
1225pub const IPPROTO_VISA = 70;
1226
1227/// Packet Core Utility
1228pub const IPPROTO_IPCV = 71;
1229
1230/// Comp. Prot. Net. Executive
1231pub const IPPROTO_CPNX = 72;
1232
1233/// Comp. Prot. HeartBeat
1234pub const IPPROTO_CPHB = 73;
1235
1236/// Wang Span Network
1237pub const IPPROTO_WSN = 74;
1238
1239/// Packet Video Protocol
1240pub const IPPROTO_PVP = 75;
1241
1242/// BackRoom SATNET Monitoring
1243pub const IPPROTO_BRSATMON = 76;
1244
1245/// Sun net disk proto (temp.)
1246pub const IPPROTO_ND = 77;
1247
1248/// WIDEBAND Monitoring
1249pub const IPPROTO_WBMON = 78;
1250
1251/// WIDEBAND EXPAK
1252pub const IPPROTO_WBEXPAK = 79;
1253
1254/// ISO cnlp
1255pub const IPPROTO_EON = 80;
1256
1257/// VMTP
1258pub const IPPROTO_VMTP = 81;
1259
1260/// Secure VMTP
1261pub const IPPROTO_SVMTP = 82;
1262
1263/// Banyon VINES
1264pub const IPPROTO_VINES = 83;
1265
1266/// TTP
1267pub const IPPROTO_TTP = 84;
1268
1269/// NSFNET-IGP
1270pub const IPPROTO_IGP = 85;
1271
1272/// dissimilar gateway prot.
1273pub const IPPROTO_DGP = 86;
1274
1275/// TCF
1276pub const IPPROTO_TCF = 87;
1277
1278/// Cisco/GXS IGRP
1279pub const IPPROTO_IGRP = 88;
1280
1281/// OSPFIGP
1282pub const IPPROTO_OSPFIGP = 89;
1283
1284/// Strite RPC protocol
1285pub const IPPROTO_SRPC = 90;
1286
1287/// Locus Address Resoloution
1288pub const IPPROTO_LARP = 91;
1289
1290/// Multicast Transport
1291pub const IPPROTO_MTP = 92;
1292
1293/// AX.25 Frames
1294pub const IPPROTO_AX25 = 93;
1295
1296/// IP encapsulated in IP
1297pub const IPPROTO_IPEIP = 94;
1298
1299/// Mobile Int.ing control
1300pub const IPPROTO_MICP = 95;
1301
1302/// Semaphore Comm. security
1303pub const IPPROTO_SCCSP = 96;
1304
1305/// Ethernet IP encapsulation
1306pub const IPPROTO_ETHERIP = 97;
1307
1308/// encapsulation header
1309pub const IPPROTO_ENCAP = 98;
1310
1311/// any private encr. scheme
1312pub const IPPROTO_APES = 99;
1313
1314/// GMTP
1315pub const IPPROTO_GMTP = 100;
1316
1317/// payload compression (IPComp)
1318pub const IPPROTO_IPCOMP = 108;
1319
1320/// SCTP
1321pub const IPPROTO_SCTP = 132;
1322
1323/// IPv6 Mobility Header
1324pub const IPPROTO_MH = 135;
1325
1326/// UDP-Lite
1327pub const IPPROTO_UDPLITE = 136;
1328
1329/// IP6 Host Identity Protocol
1330pub const IPPROTO_HIP = 139;
1331
1332/// IP6 Shim6 Protocol
1333pub const IPPROTO_SHIM6 = 140;
1334
1335/// Protocol Independent Mcast
1336pub const IPPROTO_PIM = 103;
1337
1338/// CARP
1339pub const IPPROTO_CARP = 112;
1340
1341/// PGM
1342pub const IPPROTO_PGM = 113;
1343
1344/// MPLS-in-IP
1345pub const IPPROTO_MPLS = 137;
1346
1347/// PFSYNC
1348pub const IPPROTO_PFSYNC = 240;
1349
1350/// Reserved
1351pub const IPPROTO_RESERVED_253 = 253;
1352
1353/// Reserved
1354pub const IPPROTO_RESERVED_254 = 254;
1355
1356pub const rlimit_resource = extern enum(c_int) {
1357 CPU = 0,
1358 FSIZE = 1,
1359 DATA = 2,
1360 STACK = 3,
1361 CORE = 4,
1362 RSS = 5,
1363 MEMLOCK = 6,
1364 NPROC = 7,
1365 NOFILE = 8,
1366 SBSIZE = 9,
1367 VMEM = 10,
1368 AS = 10,
1369 NPTS = 11,
1370 SWAP = 12,
1371 KQUEUES = 13,
1372 UMTXP = 14,
1373
1374 _,
1375};
1376
1377pub const rlim_t = i64;
1378
1379/// No limit
1380pub const RLIM_INFINITY: rlim_t = (1 << 63) - 1;
1381
1382pub const RLIM_SAVED_MAX = RLIM_INFINITY;
1383pub const RLIM_SAVED_CUR = RLIM_INFINITY;
1384
1385pub const rlimit = extern struct {
1386 /// Soft limit
1387 cur: rlim_t,
1388 /// Hard limit
1389 max: rlim_t,
1390};
1391
1392pub const SHUT_RD = 0;
1393pub const SHUT_WR = 1;
1394pub const SHUT_RDWR = 2;
lib/std/os/haiku.zig created+8
......@@ -0,0 +1,8 @@
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2015-2020 Zig Contributors
3// This file is part of [zig](https://ziglang.org/), which is MIT licensed.
4// The MIT license requires this copyright notice to be included in all copies
5// and substantial portions of the software.
6const std = @import("../std.zig");
7pub usingnamespace std.c;
8pub usingnamespace @import("bits.zig");
lib/std/process.zig+14-1
......@@ -609,7 +609,7 @@ pub const UserInfo = struct {
609609/// POSIX function which gets a uid from username.
610610pub fn getUserInfo(name: []const u8) !UserInfo {
611611 return switch (builtin.os.tag) {
612 .linux, .macos, .watchos, .tvos, .ios, .freebsd, .netbsd, .openbsd => posixGetUserInfo(name),
612 .linux, .macos, .watchos, .tvos, .ios, .freebsd, .netbsd, .openbsd, .haiku => posixGetUserInfo(name),
613613 else => @compileError("Unsupported OS"),
614614 };
615615}
......@@ -777,6 +777,19 @@ pub fn getSelfExeSharedLibPaths(allocator: *Allocator) error{OutOfMemory}![][:0]
777777 }
778778 return paths.toOwnedSlice();
779779 },
780 // Haiku should implement dl_iterat_phdr (https://dev.haiku-os.org/ticket/15743)
781 .haiku => {
782 var paths = List.init(allocator);
783 errdefer {
784 const slice = paths.toOwnedSlice();
785 for (slice) |item| {
786 allocator.free(item);
787 }
788 allocator.free(slice);
789 }
790 //TODO: fill out placeholder
791 return paths.toOwnedSlice();
792 },
780793 else => @compileError("getSelfExeSharedLibPaths unimplemented for this target"),
781794 }
782795}
lib/std/target.zig+4
......@@ -1339,6 +1339,10 @@ pub const Target = struct {
13391339 return self.os.tag.isDarwin();
13401340 }
13411341
1342 pub fn isHaiku(self: Target) bool {
1343 return self.os.tag == .haiku;
1344 }
1345
13421346 pub fn isGnuLibC_os_tag_abi(os_tag: Os.Tag, abi: Abi) bool {
13431347 return os_tag == .linux and abi.isGnu();
13441348 }
src/stage1/os.cpp+1-1
......@@ -61,7 +61,7 @@ typedef SSIZE_T ssize_t;
6161
6262#endif
6363
64#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) || defined(ZIG_OS_DRAGONFLY) || defined(ZIG_OS_OPENBSD)
64#if defined(ZIG_OS_LINUX) || defined(ZIG_OS_FREEBSD) || defined(ZIG_OS_NETBSD) || defined(ZIG_OS_DRAGONFLY) || defined(ZIG_OS_OPENBSD) || defined(ZIG_OS_HAIKU)
6565#include <link.h>
6666#endif
6767
src/stage1/os.hpp+2
......@@ -31,6 +31,8 @@
3131#define ZIG_OS_DRAGONFLY
3232#elif defined(__OpenBSD__)
3333#define ZIG_OS_OPENBSD
34#elif defined(__HAIKU__)
35#define ZIG_OS_HAIKU
3436#else
3537#define ZIG_OS_UNKNOWN
3638#endif
src/stage1/target.cpp+4-1
......@@ -379,6 +379,9 @@ Error target_parse_os(Os *out_os, const char *os_ptr, size_t os_len) {
379379#elif defined(ZIG_OS_OPENBSD)
380380 *out_os = OsOpenBSD;
381381 return ErrorNone;
382#elif defined(ZIG_OS_HAIKU)
383 *out_os = OsHaiku;
384 return ErrorNone;
382385#else
383386 zig_panic("stage1 is unable to detect native target for this OS");
384387#endif
......@@ -645,6 +648,7 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
645648 case OsDragonFly:
646649 case OsOpenBSD:
647650 case OsWASI:
651 case OsHaiku:
648652 case OsEmscripten:
649653 switch (id) {
650654 case CIntTypeShort:
......@@ -703,7 +707,6 @@ uint32_t target_c_type_size_in_bits(const ZigTarget *target, CIntType id) {
703707 case OsKFreeBSD:
704708 case OsLv2:
705709 case OsSolaris:
706 case OsHaiku:
707710 case OsMinix:
708711 case OsRTEMS:
709712 case OsNaCl: