authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-02-25 16:00:00-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-02-25 16:00:00-08:00
log7edb204edfa41e11776ac009da5a20fb1c907f5f
tree9c6eae297ebc492c0a1a94a4d3d25fc3bcd07bd9
parent297eabd4accbcae42bfe821078a79e4af06a2dde
parent37a1d08de2ce263439713180f57741d16fb27e23
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #7546 from hoanga/haiku-support

initial support for haiku

16 files changed, 1707 insertions(+), 43 deletions(-)

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