authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-04-26 16:12:23-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-04-26 16:12:23-04:00
log95b42f9e6b901435b6ff7841a6b180553761070b
tree6fcb88dd6b8c59503931d3858699274e3f75c633
parent0de962fdd95c2770c8442e97c416b4bd42566a65
parent762d4a959cc4e61fb88f68ba067ec97c5e2fe869
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #8604 from hoanga/haiku-support-sysdefs

further haiku support system definitions

4 files changed, 186 insertions(+), 209 deletions(-)

lib/std/c/haiku.zig+48
......@@ -69,3 +69,51 @@ pub const pthread_rwlock_t = extern struct {
6969 writer_count: i32 = 0,
7070 waiters: [2]?*c_void = [_]?*c_void{ null, null },
7171};
72
73pub const EAI = extern enum(c_int) {
74 /// address family for hostname not supported
75 ADDRFAMILY = 1,
76
77 /// name could not be resolved at this time
78 AGAIN = 2,
79
80 /// flags parameter had an invalid value
81 BADFLAGS = 3,
82
83 /// non-recoverable failure in name resolution
84 FAIL = 4,
85
86 /// address family not recognized
87 FAMILY = 5,
88
89 /// memory allocation failure
90 MEMORY = 6,
91
92 /// no address associated with hostname
93 NODATA = 7,
94
95 /// name does not resolve
96 NONAME = 8,
97
98 /// service not recognized for socket type
99 SERVICE = 9,
100
101 /// intended socket type was not recognized
102 SOCKTYPE = 10,
103
104 /// system error returned in errno
105 SYSTEM = 11,
106
107 /// invalid value for hints
108 BADHINTS = 12,
109
110 /// resolved protocol is unknown
111 PROTOCOL = 13,
112
113 /// argument buffer overflow
114 OVERFLOW = 14,
115
116 _,
117};
118
119pub const EAI_MAX = 15;
lib/std/child_process.zig+1-1
......@@ -264,7 +264,7 @@ pub const ChildProcess = struct {
264264
265265 // TODO collect output in a deadlock-avoiding way on Windows.
266266 // https://github.com/ziglang/zig/issues/6343
267 if (builtin.os.tag == .windows) {
267 if (builtin.os.tag == .windows or builtin.os.tag == .haiku) {
268268 const stdout_in = child.stdout.?.reader();
269269 const stderr_in = child.stderr.?.reader();
270270
lib/std/os/bits/haiku.zig+128-206
......@@ -279,20 +279,10 @@ pub const PROT_READ = 1;
279279pub const PROT_WRITE = 2;
280280pub const PROT_EXEC = 4;
281281
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;
282pub const CLOCK_MONOTONIC = 0;
283pub const CLOCK_REALTIME = -1;
284pub const CLOCK_PROCESS_CPUTIME_ID = -2;
285pub const CLOCK_THREAD_CPUTIME_ID = -3;
296286
297287pub const MAP_FAILED = @intToPtr(*c_void, maxInt(usize));
298288pub const MAP_SHARED = 0x0001;
......@@ -310,58 +300,59 @@ pub const MAP_NOCORE = 0x00020000;
310300pub const MAP_PREFAULT_READ = 0x00040000;
311301pub const MAP_32BIT = 0x00080000;
312302
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;
303pub const WNOHANG = 0x1;
304pub const WUNTRACED = 0x2;
305pub const WSTOPPED = 0x10;
306pub const WCONTINUED = 0x4;
307pub const WNOWAIT = 0x20;
308pub const WEXITED = 0x08;
309
310pub const SA_ONSTACK = 0x20;
311pub const SA_RESTART = 0x10;
312pub const SA_RESETHAND = 0x04;
313pub const SA_NOCLDSTOP = 0x01;
314pub const SA_NODEFER = 0x08;
315pub const SA_NOCLDWAIT = 0x02;
316pub const SA_SIGINFO = 0x40;
317pub const SA_NOMASK = SA_NODEFER;
318pub const SA_STACK = SA_ONSTACK;
319pub const SA_ONESHOT = SA_RESETHAND;
328320
329321pub const SIGHUP = 1;
330322pub const SIGINT = 2;
331323pub const SIGQUIT = 3;
332324pub const SIGILL = 4;
333pub const SIGTRAP = 5;
325pub const SIGCHLD = 5;
334326pub const SIGABRT = 6;
335327pub const SIGIOT = SIGABRT;
336pub const SIGEMT = 7;
328pub const SIGPIPE = 7;
337329pub const SIGFPE = 8;
338330pub const SIGKILL = 9;
339pub const SIGBUS = 10;
331pub const SIGSTOP = 10;
340332pub const SIGSEGV = 11;
341pub const SIGSYS = 12;
342pub const SIGPIPE = 13;
333pub const SIGCONT = 12;
334pub const SIGTSTP = 13;
343335pub const SIGALRM = 14;
344336pub 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
337pub const SIGTTIN = 16;
338pub const SIGTTOU = 17;
339pub const SIGUSR1 = 18;
340pub const SIGUSR2 = 19;
341pub const SIGWINCH = 20;
342pub const SIGKILLTHR = 21;
343pub const SIGTRAP = 22;
344pub const SIGPOLL = 23;
345pub const SIGPROF = 24;
346pub const SIGSYS = 25;
347pub const SIGURG = 26;
348pub const SIGVTALRM = 27;
349pub const SIGXCPU = 28;
350pub const SIGXFSZ = 29;
351pub const SIGBUS = 30;
352pub const SIGRESERVED1 = 31;
353pub const SIGRESERVED2 = 32;
354
355// TODO: check
365356pub const SIGRTMIN = 65;
366357pub const SIGRTMAX = 126;
367358
......@@ -645,135 +636,51 @@ pub const EVFILT_SENDFILE = -12;
645636
646637pub const EVFILT_EMPTY = -13;
647638
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;
639pub const TCGETA = 0x8000;
640pub const TCSETA = 0x8001;
641pub const TCSETAW = 0x8004;
642pub const TCSETAF = 0x8003;
643pub const TCSBRK = 08005;
644pub const TCXONC = 0x8007;
645pub const TCFLSH = 0x8006;
646
647pub const TIOCSCTTY = 0x8017;
648pub const TIOCGPGRP = 0x8015;
649pub const TIOCSPGRP = 0x8016;
650pub const TIOCGWINSZ = 0x8012;
651pub const TIOCSWINSZ = 0x8013;
652pub const TIOCMGET = 0x8018;
653pub const TIOCMBIS = 0x8022;
654pub const TIOCMBIC = 0x8023;
655pub const TIOCMSET = 0x8019;
656pub const FIONREAD = 0xbe000001;
657pub const FIONBIO = 0xbe000000;
658pub const TIOCSBRK = 0x8020;
659pub const TIOCCBRK = 0x8021;
660pub const TIOCGSID = 0x8024;
759661
760662pub fn WEXITSTATUS(s: u32) u32 {
761 return (s & 0xff00) >> 8;
663 return (s & 0xff);
762664}
665
763666pub fn WTERMSIG(s: u32) u32 {
764 return s & 0x7f;
667 return (s >> 8) & 0xff;
765668}
669
766670pub fn WSTOPSIG(s: u32) u32 {
767671 return WEXITSTATUS(s);
768672}
673
769674pub fn WIFEXITED(s: u32) bool {
770675 return WTERMSIG(s) == 0;
771676}
677
772678pub fn WIFSTOPPED(s: u32) bool {
773 return @intCast(u16, (((s & 0xffff) *% 0x10001) >> 8)) > 0x7f00;
679 return ((s >> 16) & 0xff) != 0;
774680}
681
775682pub fn WIFSIGNALED(s: u32) bool {
776 return (s & 0xffff) -% 1 < 0xff;
683 return ((s >> 8) & 0xff) != 0;
777684}
778685
779686pub const winsize = extern struct {
......@@ -823,49 +730,47 @@ pub const sigset_t = extern struct {
823730 __bits: [_SIG_WORDS]u32,
824731};
825732
826pub const EPERM = 1; // Operation not permitted
827pub const ENOENT = 2; // No such file or directory
828pub const ESRCH = 3; // No such process
829pub const EINTR = 4; // Interrupted system call
830pub const EIO = 5; // Input/output error
831pub const ENXIO = 6; // Device not configured
832pub const E2BIG = 7; // Argument list too long
833pub const ENOEXEC = 8; // Exec format error
834pub const EBADF = 9; // Bad file descriptor
835pub const ECHILD = 10; // No child processes
836pub const EDEADLK = 11; // Resource deadlock avoided
837// 11 was EAGAIN
838pub const ENOMEM = 12; // Cannot allocate memory
839pub const EACCES = 13; // Permission denied
840pub const EFAULT = 14; // Bad address
841pub const ENOTBLK = 15; // Block device required
842pub const EBUSY = 16; // Device busy
843pub const EEXIST = 17; // File exists
844pub const EXDEV = 18; // Cross-device link
845pub const ENODEV = 19; // Operation not supported by device
846pub const ENOTDIR = 20; // Not a directory
847pub const EISDIR = 21; // Is a directory
848pub const EINVAL = 22; // Invalid argument
849pub const ENFILE = 23; // Too many open files in system
850pub const EMFILE = 24; // Too many open files
851pub const ENOTTY = 25; // Inappropriate ioctl for device
852pub const ETXTBSY = 26; // Text file busy
853pub const EFBIG = 27; // File too large
854pub const ENOSPC = 28; // No space left on device
855pub const ESPIPE = 29; // Illegal seek
856pub const EROFS = 30; // Read-only filesystem
857pub const EMLINK = 31; // Too many links
858pub const EPIPE = 32; // Broken pipe
733pub const EPERM = -0x7ffffff1; // Operation not permitted
734pub const ENOENT = -0x7fff9ffd; // No such file or directory
735pub const ESRCH = -0x7fff8ff3; // No such process
736pub const EINTR = -0x7ffffff6; // Interrupted system call
737pub const EIO = -0x7fffffff; // Input/output error
738pub const ENXIO = -0x7fff8ff5; // Device not configured
739pub const E2BIG = -0x7fff8fff; // Argument list too long
740pub const ENOEXEC = -0x7fffecfe; // Exec format error
741pub const ECHILD = -0x7fff8ffe; // No child processes
742pub const EDEADLK = -0x7fff8ffd; // Resource deadlock avoided
743pub const ENOMEM = -0x80000000; // Cannot allocate memory
744pub const EACCES = -0x7ffffffe; // Permission denied
745pub const EFAULT = -0x7fffecff; // Bad address
746pub const EBUSY = -0x7ffffff2; // Device busy
747pub const EEXIST = -0x7fff9ffe; // File exists
748pub const EXDEV = -0x7fff9ff5; // Cross-device link
749pub const ENODEV = -0x7fff8ff9; // Operation not supported by device
750pub const ENOTDIR = -0x7fff9ffb; // Not a directory
751pub const EISDIR = -0x7fff9ff7; // Is a directory
752pub const EINVAL = -0x7ffffffb; // Invalid argument
753pub const ENFILE = -0x7fff8ffa; // Too many open files in system
754pub const EMFILE = -0x7fff9ff6; // Too many open files
755pub const ENOTTY = -0x7fff8ff6; // Inappropriate ioctl for device
756pub const ETXTBSY = -0x7fff8fc5; // Text file busy
757pub const EFBIG = -0x7fff8ffc; // File too large
758pub const ENOSPC = -0x7fff9ff9; // No space left on device
759pub const ESPIPE = -0x7fff8ff4; // Illegal seek
760pub const EROFS = -0x7fff9ff8; // Read-only filesystem
761pub const EMLINK = -0x7fff8ffb; // Too many links
762pub const EPIPE = -0x7fff9ff3; // Broken pipe
763pub const EBADF = -0x7fffa000; // Bad file descriptor
859764
860765// math software
861766pub const EDOM = 33; // Numerical argument out of domain
862767pub const ERANGE = 34; // Result too large
863768
864769// non-blocking and interrupt i/o
865pub const EAGAIN = 35; // Resource temporarily unavailable
866pub const EWOULDBLOCK = EAGAIN; // Operation would block
867pub const EINPROGRESS = 36; // Operation now in progress
868pub const EALREADY = 37; // Operation already in progress
770pub const EAGAIN = -0x7ffffff5;
771pub const EWOULDBLOCK = -0x7ffffff5;
772pub const EINPROGRESS = -0x7fff8fdc;
773pub const EALREADY = -0x7fff8fdb;
869774
870775// ipc/network software -- argument errors
871776pub const ENOTSOCK = 38; // Socket operation on non-socket
......@@ -1447,3 +1352,20 @@ pub const directory_which = extern enum(c_int) {
14471352
14481353 _,
14491354};
1355
1356pub const cc_t = u8;
1357pub const speed_t = u8;
1358pub const tcflag_t = u32;
1359
1360pub const NCCS = 32;
1361
1362pub const termios = extern struct {
1363 c_iflag: tcflag_t,
1364 c_oflag: tcflag_t,
1365 c_cflag: tcflag_t,
1366 c_lflag: tcflag_t,
1367 c_line: cc_t,
1368 c_ispeed: speed_t,
1369 c_ospeed: speed_t,
1370 cc_t: [NCCS]cc_t,
1371};
src/libc_installation.zig+9-2
......@@ -9,6 +9,7 @@ const build_options = @import("build_options");
99const is_darwin = Target.current.isDarwin();
1010const is_windows = Target.current.os.tag == .windows;
1111const is_gnu = Target.current.isGnu();
12const is_haiku = Target.current.os.tag == .haiku;
1213
1314const log = std.log.scoped(.libc_installation);
1415
......@@ -279,8 +280,14 @@ pub const LibCInstallation = struct {
279280 return error.CCompilerCannotFindHeaders;
280281 }
281282
282 const include_dir_example_file = "stdlib.h";
283 const sys_include_dir_example_file = if (is_windows) "sys\\types.h" else "sys/errno.h";
283 const include_dir_example_file = if (is_haiku) "posix/stdlib.h" else "stdlib.h";
284 const sys_include_dir_example_file = if (is_windows)
285 "sys\\types.h"
286 else if (is_haiku)
287 "posix/errno.h"
288 else
289 "sys/errno.h"
290 ;
284291
285292 var path_i: usize = 0;
286293 while (path_i < search_paths.items.len) : (path_i += 1) {