authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-03-25 15:33:51-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-03-25 15:33:51-07:00
log32b4d85605c9bdde13597a83116e5940be48a5be
tree53f6456ebb89e357b658eaafb83e3133d60b99f0
parentef31d8f48fa1b7ff5bd4cd57e812fd9c91fd1bd9
parent2dd74cd312ec21a18b05ff7576f0d584ec7a41a2
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #19406 from jacobly0/haiku

haiku: get a cross-compiled compiler working

19 files changed, 403 insertions(+), 101 deletions(-)

bootstrap.c+2
......@@ -64,6 +64,8 @@ static const char *get_host_os(void) {
6464 return "linux";
6565#elif defined(__FreeBSD__)
6666 return "freebsd";
67#elif defined(__HAIKU__)
68 return "haiku";
6769#else
6870 panic("unknown host os, specify with ZIG_HOST_TARGET_OS");
6971#endif
lib/std/c.zig+2-2
......@@ -1687,8 +1687,8 @@ pub extern "c" fn getpeername(sockfd: c.fd_t, noalias addr: *c.sockaddr, noalias
16871687pub extern "c" fn connect(sockfd: c.fd_t, sock_addr: *const c.sockaddr, addrlen: c.socklen_t) c_int;
16881688pub extern "c" fn accept(sockfd: c.fd_t, noalias addr: ?*c.sockaddr, noalias addrlen: ?*c.socklen_t) c_int;
16891689pub extern "c" fn accept4(sockfd: c.fd_t, noalias addr: ?*c.sockaddr, noalias addrlen: ?*c.socklen_t, flags: c_uint) c_int;
1690pub extern "c" fn getsockopt(sockfd: c.fd_t, level: u32, optname: u32, noalias optval: ?*anyopaque, noalias optlen: *c.socklen_t) c_int;
1691pub extern "c" fn setsockopt(sockfd: c.fd_t, level: u32, optname: u32, optval: ?*const anyopaque, optlen: c.socklen_t) c_int;
1690pub extern "c" fn getsockopt(sockfd: c.fd_t, level: i32, optname: u32, noalias optval: ?*anyopaque, noalias optlen: *c.socklen_t) c_int;
1691pub extern "c" fn setsockopt(sockfd: c.fd_t, level: i32, optname: u32, optval: ?*const anyopaque, optlen: c.socklen_t) c_int;
16921692pub extern "c" fn send(sockfd: c.fd_t, buf: *const anyopaque, len: usize, flags: u32) isize;
16931693pub extern "c" fn sendto(
16941694 sockfd: c.fd_t,
lib/std/c/darwin.zig+2-2
......@@ -1139,7 +1139,7 @@ pub const siginfo_t = extern struct {
11391139 pid: pid_t,
11401140 uid: uid_t,
11411141 status: c_int,
1142 addr: *anyopaque,
1142 addr: *allowzero anyopaque,
11431143 value: extern union {
11441144 int: c_int,
11451145 ptr: *anyopaque,
......@@ -1151,7 +1151,7 @@ pub const siginfo_t = extern struct {
11511151/// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name.
11521152pub const Sigaction = extern struct {
11531153 pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
1154 pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
1154 pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*anyopaque) callconv(.C) void;
11551155
11561156 handler: extern union {
11571157 handler: ?handler_fn,
lib/std/c/dragonfly.zig+2-2
......@@ -668,7 +668,7 @@ pub const siginfo_t = extern struct {
668668 pid: c_int,
669669 uid: uid_t,
670670 status: c_int,
671 addr: ?*anyopaque,
671 addr: *allowzero anyopaque,
672672 value: sigval,
673673 band: c_long,
674674 __spare__: [7]c_int,
......@@ -691,7 +691,7 @@ pub const sig_atomic_t = c_int;
691691
692692pub const Sigaction = extern struct {
693693 pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
694 pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
694 pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*anyopaque) callconv(.C) void;
695695
696696 /// signal handler
697697 handler: extern union {
lib/std/c/freebsd.zig+2-2
......@@ -1172,7 +1172,7 @@ const NSIG = 32;
11721172/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
11731173pub const Sigaction = extern struct {
11741174 pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
1175 pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
1175 pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*anyopaque) callconv(.C) void;
11761176
11771177 /// signal handler
11781178 handler: extern union {
......@@ -1206,7 +1206,7 @@ pub const siginfo_t = extern struct {
12061206 /// Exit value.
12071207 status: c_int,
12081208 /// Faulting instruction.
1209 addr: ?*anyopaque,
1209 addr: *allowzero anyopaque,
12101210 /// Signal value.
12111211 value: sigval,
12121212 reason: extern union {
lib/std/c/haiku.zig+352-48
......@@ -9,7 +9,7 @@ extern "c" fn _errnop() *c_int;
99
1010pub const _errno = _errnop;
1111
12pub extern "c" fn find_directory(which: c_int, volume: i32, createIt: bool, path_ptr: [*]u8, length: i32) u64;
12pub extern "c" fn find_directory(which: directory_which, volume: i32, createIt: bool, path_ptr: [*]u8, length: i32) u64;
1313
1414pub extern "c" fn find_thread(thread_name: ?*anyopaque) i32;
1515
......@@ -427,23 +427,18 @@ pub const W = struct {
427427 }
428428};
429429
430pub const SA = struct {
431 pub const ONSTACK = 0x20;
432 pub const RESTART = 0x10;
433 pub const RESETHAND = 0x04;
434 pub const NOCLDSTOP = 0x01;
435 pub const NODEFER = 0x08;
436 pub const NOCLDWAIT = 0x02;
437 pub const SIGINFO = 0x40;
438 pub const NOMASK = NODEFER;
439 pub const STACK = ONSTACK;
440 pub const ONESHOT = RESETHAND;
441};
430// posix/signal.h
431
432pub const sigset_t = u64;
433pub const empty_sigset: sigset_t = 0;
434pub const filled_sigset = ~@as(sigset_t, 0);
442435
443436pub const SIG = struct {
444 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
445437 pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
446438 pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
439 pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
440
441 pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(3);
447442
448443 pub const HUP = 1;
449444 pub const INT = 2;
......@@ -484,6 +479,340 @@ pub const SIG = struct {
484479 pub const SETMASK = 3;
485480};
486481
482pub const siginfo_t = extern struct {
483 signo: c_int,
484 code: c_int,
485 errno: c_int,
486
487 pid: pid_t,
488 uid: uid_t,
489 addr: *allowzero anyopaque,
490};
491
492/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
493pub const Sigaction = extern struct {
494 pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
495 pub const sigaction_fn = *const fn (c_int, *allowzero anyopaque, ?*anyopaque) callconv(.C) void;
496
497 /// signal handler
498 handler: extern union {
499 handler: handler_fn,
500 sigaction: sigaction_fn,
501 },
502
503 /// signal mask to apply
504 mask: sigset_t,
505
506 /// see signal options
507 flags: c_int,
508
509 /// will be passed to the signal handler, BeOS extension
510 userdata: *allowzero anyopaque = undefined,
511};
512
513pub const SA = struct {
514 pub const NOCLDSTOP = 0x01;
515 pub const NOCLDWAIT = 0x02;
516 pub const RESETHAND = 0x04;
517 pub const NODEFER = 0x08;
518 pub const RESTART = 0x10;
519 pub const ONSTACK = 0x20;
520 pub const SIGINFO = 0x40;
521 pub const NOMASK = NODEFER;
522 pub const STACK = ONSTACK;
523 pub const ONESHOT = RESETHAND;
524};
525
526pub const SS = struct {
527 pub const ONSTACK = 0x1;
528 pub const DISABLE = 0x2;
529};
530
531pub const MINSIGSTKSZ = 8192;
532pub const SIGSTKSZ = 16384;
533
534pub const stack_t = extern struct {
535 sp: [*]u8,
536 size: isize,
537 flags: i32,
538};
539
540pub const NSIG = 65;
541
542pub const mcontext_t = vregs;
543
544pub const ucontext_t = extern struct {
545 link: ?*ucontext_t,
546 sigmask: sigset_t,
547 stack: stack_t,
548 mcontext: mcontext_t,
549};
550
551// arch/*/signal.h
552
553pub const vregs = switch (builtin.cpu.arch) {
554 .arm, .thumb => extern struct {
555 r0: u32,
556 r1: u32,
557 r2: u32,
558 r3: u32,
559 r4: u32,
560 r5: u32,
561 r6: u32,
562 r7: u32,
563 r8: u32,
564 r9: u32,
565 r10: u32,
566 r11: u32,
567 r12: u32,
568 r13: u32,
569 r14: u32,
570 r15: u32,
571 cpsr: u32,
572 },
573 .aarch64 => extern struct {
574 x: [10]u64,
575 lr: u64,
576 sp: u64,
577 elr: u64,
578 spsr: u64,
579 fp_q: [32]u128,
580 fpsr: u32,
581 fpcr: u32,
582 },
583 .m68k => extern struct {
584 pc: u32,
585 d0: u32,
586 d1: u32,
587 d2: u32,
588 d3: u32,
589 d4: u32,
590 d5: u32,
591 d6: u32,
592 d7: u32,
593 a0: u32,
594 a1: u32,
595 a2: u32,
596 a3: u32,
597 a4: u32,
598 a5: u32,
599 a6: u32,
600 a7: u32,
601 ccr: u8,
602 f0: f64,
603 f1: f64,
604 f2: f64,
605 f3: f64,
606 f4: f64,
607 f5: f64,
608 f6: f64,
609 f7: f64,
610 f8: f64,
611 f9: f64,
612 f10: f64,
613 f11: f64,
614 f12: f64,
615 f13: f64,
616 },
617 .mipsel => extern struct {
618 r0: u32,
619 },
620 .powerpc => extern struct {
621 pc: u32,
622 r0: u32,
623 r1: u32,
624 r2: u32,
625 r3: u32,
626 r4: u32,
627 r5: u32,
628 r6: u32,
629 r7: u32,
630 r8: u32,
631 r9: u32,
632 r10: u32,
633 r11: u32,
634 r12: u32,
635 f0: f64,
636 f1: f64,
637 f2: f64,
638 f3: f64,
639 f4: f64,
640 f5: f64,
641 f6: f64,
642 f7: f64,
643 f8: f64,
644 f9: f64,
645 f10: f64,
646 f11: f64,
647 f12: f64,
648 f13: f64,
649 reserved: u32,
650 fpscr: u32,
651 ctr: u32,
652 xer: u32,
653 cr: u32,
654 msr: u32,
655 lr: u32,
656 },
657 .riscv64 => extern struct {
658 x: [31]u64,
659 pc: u64,
660 f: [32]f64,
661 fcsr: u64,
662 },
663 .sparc64 => extern struct {
664 g1: u64,
665 g2: u64,
666 g3: u64,
667 g4: u64,
668 g5: u64,
669 g6: u64,
670 g7: u64,
671 o0: u64,
672 o1: u64,
673 o2: u64,
674 o3: u64,
675 o4: u64,
676 o5: u64,
677 sp: u64,
678 o7: u64,
679 l0: u64,
680 l1: u64,
681 l2: u64,
682 l3: u64,
683 l4: u64,
684 l5: u64,
685 l6: u64,
686 l7: u64,
687 i0: u64,
688 i1: u64,
689 i2: u64,
690 i3: u64,
691 i4: u64,
692 i5: u64,
693 fp: u64,
694 i7: u64,
695 },
696 .x86 => extern struct {
697 pub const old_extended_regs = extern struct {
698 control: u16,
699 reserved1: u16,
700 status: u16,
701 reserved2: u16,
702 tag: u16,
703 reserved3: u16,
704 eip: u32,
705 cs: u16,
706 opcode: u16,
707 datap: u32,
708 ds: u16,
709 reserved4: u16,
710 fp_mmx: [8][10]u8,
711 };
712
713 pub const fp_register = extern struct { value: [10]u8, reserved: [6]u8 };
714
715 pub const xmm_register = extern struct { value: [16]u8 };
716
717 pub const new_extended_regs = extern struct {
718 control: u16,
719 status: u16,
720 tag: u16,
721 opcode: u16,
722 eip: u32,
723 cs: u16,
724 reserved1: u16,
725 datap: u32,
726 ds: u16,
727 reserved2: u16,
728 mxcsr: u32,
729 reserved3: u32,
730 fp_mmx: [8]fp_register,
731 xmmx: [8]xmm_register,
732 reserved4: [224]u8,
733 };
734
735 pub const extended_regs = extern struct {
736 state: extern union {
737 old_format: old_extended_regs,
738 new_format: new_extended_regs,
739 },
740 format: u32,
741 };
742
743 eip: u32,
744 eflags: u32,
745 eax: u32,
746 ecx: u32,
747 edx: u32,
748 esp: u32,
749 ebp: u32,
750 reserved: u32,
751 xregs: extended_regs,
752 edi: u32,
753 esi: u32,
754 ebx: u32,
755 },
756 .x86_64 => extern struct {
757 pub const fp_register = extern struct {
758 value: [10]u8,
759 reserved: [6]u8,
760 };
761
762 pub const xmm_register = extern struct {
763 value: [16]u8,
764 };
765
766 pub const fpu_state = extern struct {
767 control: u16,
768 status: u16,
769 tag: u16,
770 opcode: u16,
771 rip: u64,
772 rdp: u64,
773 mxcsr: u32,
774 mscsr_mask: u32,
775
776 fp_mmx: [8]fp_register,
777 xmm: [16]xmm_register,
778 reserved: [96]u8,
779 };
780
781 pub const xstate_hdr = extern struct {
782 bv: u64,
783 xcomp_bv: u64,
784 reserved: [48]u8,
785 };
786
787 pub const savefpu = extern struct {
788 fxsave: fpu_state,
789 xstate: xstate_hdr,
790 ymm: [16]xmm_register,
791 };
792
793 rax: u64,
794 rbx: u64,
795 rcx: u64,
796 rdx: u64,
797 rdi: u64,
798 rsi: u64,
799 rbp: u64,
800 r8: u64,
801 r9: u64,
802 r10: u64,
803 r11: u64,
804 r12: u64,
805 r13: u64,
806 r14: u64,
807 r15: u64,
808 rsp: u64,
809 rip: u64,
810 rflags: u64,
811 fpu: savefpu,
812 },
813 else => void,
814};
815
487816// access function
488817pub const F_OK = 0; // test for existence of file
489818pub const X_OK = 1; // test for execute or search permission
......@@ -527,6 +856,15 @@ pub const SOCK = struct {
527856 pub const DGRAM = 2;
528857 pub const RAW = 3;
529858 pub const SEQPACKET = 5;
859
860 /// WARNING: this flag is not supported by windows socket functions directly,
861 /// it is only supported by std.os.socket. Be sure that this value does
862 /// not share any bits with any of the `SOCK` values.
863 pub const CLOEXEC = 0x10000;
864 /// WARNING: this flag is not supported by windows socket functions directly,
865 /// it is only supported by std.os.socket. Be sure that this value does
866 /// not share any bits with any of the `SOCK` values.
867 pub const NONBLOCK = 0x20000;
530868};
531869
532870pub const SO = struct {
......@@ -686,28 +1024,6 @@ pub const winsize = extern struct {
6861024 ws_ypixel: u16,
6871025};
6881026
689const NSIG = 32;
690
691/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
692pub const Sigaction = extern struct {
693 pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
694
695 /// signal handler
696 __sigaction_u: extern union {
697 __sa_handler: handler_fn,
698 },
699
700 /// see signal options
701 sa_flags: u32,
702
703 /// signal mask to apply
704 sa_mask: sigset_t,
705};
706
707pub const sigset_t = extern struct {
708 __bits: [SIG.WORDS]u32,
709};
710
7111027const B_POSIX_ERROR_BASE = -2147454976;
7121028
7131029pub const E = enum(i32) {
......@@ -802,18 +1118,6 @@ pub const E = enum(i32) {
8021118 _,
8031119};
8041120
805pub const MINSIGSTKSZ = 8192;
806pub const SIGSTKSZ = 16384;
807
808pub const SS_ONSTACK = 0x1;
809pub const SS_DISABLE = 0x2;
810
811pub const stack_t = extern struct {
812 sp: [*]u8,
813 size: isize,
814 flags: i32,
815};
816
8171121pub const S = struct {
8181122 pub const IFMT = 0o170000;
8191123 pub const IFSOCK = 0o140000;
lib/std/c/netbsd.zig+2-2
......@@ -865,7 +865,7 @@ pub const SIG = struct {
865865/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
866866pub const Sigaction = extern struct {
867867 pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
868 pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
868 pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*anyopaque) callconv(.C) void;
869869
870870 /// signal handler
871871 handler: extern union {
......@@ -908,7 +908,7 @@ pub const _ksiginfo = extern struct {
908908 stime: clock_t,
909909 },
910910 fault: extern struct {
911 addr: ?*anyopaque,
911 addr: *allowzero anyopaque,
912912 trap: i32,
913913 trap2: i32,
914914 trap3: i32,
lib/std/c/openbsd.zig+2-2
......@@ -843,7 +843,7 @@ pub const SIG = struct {
843843/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
844844pub const Sigaction = extern struct {
845845 pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
846 pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
846 pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*anyopaque) callconv(.C) void;
847847
848848 /// signal handler
849849 handler: extern union {
......@@ -881,7 +881,7 @@ pub const siginfo_t = extern struct {
881881 },
882882 },
883883 fault: extern struct {
884 addr: ?*anyopaque,
884 addr: *allowzero anyopaque,
885885 trapno: c_int,
886886 },
887887 __pad: [128 - 3 * @sizeOf(c_int)]u8,
lib/std/c/solaris.zig+2-2
......@@ -875,7 +875,7 @@ pub const SIG = struct {
875875/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
876876pub const Sigaction = extern struct {
877877 pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
878 pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
878 pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*anyopaque) callconv(.C) void;
879879
880880 /// signal options
881881 flags: c_uint,
......@@ -917,7 +917,7 @@ pub const siginfo_t = extern struct {
917917 zone: zoneid_t,
918918 },
919919 fault: extern struct {
920 addr: ?*anyopaque,
920 addr: *allowzero anyopaque,
921921 trapno: c_int,
922922 pc: ?*anyopaque,
923923 },
lib/std/debug.zig+1-1
......@@ -229,7 +229,7 @@ pub fn relocateContext(context: *ThreadContext) void {
229229}
230230
231231pub const have_getcontext = @hasDecl(posix.system, "getcontext") and
232 native_os != .openbsd and
232 native_os != .openbsd and native_os != .haiku and
233233 (native_os != .linux or switch (builtin.cpu.arch) {
234234 .x86,
235235 .x86_64,
lib/std/fs/get_app_data_dir.zig+3-9
......@@ -42,15 +42,9 @@ pub fn getAppDataDir(allocator: mem.Allocator, appname: []const u8) GetAppDataDi
4242 return fs.path.join(allocator, &[_][]const u8{ home_dir, ".local", "share", appname });
4343 },
4444 .haiku => {
45 var dir_path_ptr: [*:0]u8 = undefined;
46 if (true) {
47 _ = &dir_path_ptr;
48 @compileError("TODO: init dir_path_ptr");
49 }
50 // TODO look into directory_which
51 const be_user_settings = 0xbbe;
52 const rc = std.c.find_directory(be_user_settings, -1, true, dir_path_ptr, 1);
53 const settings_dir = try allocator.dupeZ(u8, mem.sliceTo(dir_path_ptr, 0));
45 var dir_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
46 const rc = std.c.find_directory(.B_USER_SETTINGS_DIRECTORY, -1, true, &dir_path_buf, dir_path_buf.len);
47 const settings_dir = try allocator.dupeZ(u8, mem.sliceTo(&dir_path_buf, 0));
5448 defer allocator.free(settings_dir);
5549 switch (rc) {
5650 0 => return fs.path.join(allocator, &[_][]const u8{ settings_dir, appname }),
lib/std/heap/WasmAllocator.zig+8-10
......@@ -55,7 +55,7 @@ fn alloc(ctx: *anyopaque, len: usize, log2_align: u8, return_address: usize) ?[*
5555 const addr = a: {
5656 const top_free_ptr = frees[class];
5757 if (top_free_ptr != 0) {
58 const node = @as(*usize, @ptrFromInt(top_free_ptr + (slot_size - @sizeOf(usize))));
58 const node: *usize = @ptrFromInt(top_free_ptr + (slot_size - @sizeOf(usize)));
5959 frees[class] = node.*;
6060 break :a top_free_ptr;
6161 }
......@@ -74,11 +74,10 @@ fn alloc(ctx: *anyopaque, len: usize, log2_align: u8, return_address: usize) ?[*
7474 break :a next_addr;
7575 }
7676 };
77 return @as([*]u8, @ptrFromInt(addr));
77 return @ptrFromInt(addr);
7878 }
7979 const bigpages_needed = bigPagesNeeded(actual_len);
80 const addr = allocBigPages(bigpages_needed);
81 return @as([*]u8, @ptrFromInt(addr));
80 return @ptrFromInt(allocBigPages(bigpages_needed));
8281}
8382
8483fn resize(
......@@ -123,14 +122,14 @@ fn free(
123122 const class = math.log2(slot_size) - min_class;
124123 const addr = @intFromPtr(buf.ptr);
125124 if (class < size_class_count) {
126 const node = @as(*usize, @ptrFromInt(addr + (slot_size - @sizeOf(usize))));
125 const node: *usize = @ptrFromInt(addr + (slot_size - @sizeOf(usize)));
127126 node.* = frees[class];
128127 frees[class] = addr;
129128 } else {
130129 const bigpages_needed = bigPagesNeeded(actual_len);
131130 const pow2_pages = math.ceilPowerOfTwoAssert(usize, bigpages_needed);
132131 const big_slot_size_bytes = pow2_pages * bigpage_size;
133 const node = @as(*usize, @ptrFromInt(addr + (big_slot_size_bytes - @sizeOf(usize))));
132 const node: *usize = @ptrFromInt(addr + (big_slot_size_bytes - @sizeOf(usize)));
134133 const big_class = math.log2(pow2_pages);
135134 node.* = big_frees[big_class];
136135 big_frees[big_class] = addr;
......@@ -148,15 +147,14 @@ fn allocBigPages(n: usize) usize {
148147
149148 const top_free_ptr = big_frees[class];
150149 if (top_free_ptr != 0) {
151 const node = @as(*usize, @ptrFromInt(top_free_ptr + (slot_size_bytes - @sizeOf(usize))));
150 const node: *usize = @ptrFromInt(top_free_ptr + (slot_size_bytes - @sizeOf(usize)));
152151 big_frees[class] = node.*;
153152 return top_free_ptr;
154153 }
155154
156155 const page_index = @wasmMemoryGrow(0, pow2_pages * pages_per_bigpage);
157 if (page_index <= 0) return 0;
158 const addr = @as(u32, @intCast(page_index)) * wasm.page_size;
159 return addr;
156 if (page_index == -1) return 0;
157 return @as(usize, @intCast(page_index)) * wasm.page_size;
160158}
161159
162160const test_ally = Allocator{
lib/std/io.zig+4-1
......@@ -610,7 +610,10 @@ pub fn Poller(comptime StreamEnum: type) type {
610610 // allocate grows exponentially.
611611 const bump_amt = 512;
612612
613 const err_mask = posix.POLL.ERR | posix.POLL.NVAL | posix.POLL.HUP;
613 const err_mask = switch (builtin.target.os.tag) {
614 .haiku => posix.POLL.ERR | posix.POLL.HUP,
615 else => posix.POLL.ERR | posix.POLL.NVAL | posix.POLL.HUP,
616 };
614617
615618 const events_len = try posix.poll(&self.poll_fds, if (nanoseconds) |ns|
616619 std.math.cast(i32, ns / std.time.ns_per_ms) orelse std.math.maxInt(i32)
lib/std/os/emscripten.zig+2-2
......@@ -696,7 +696,7 @@ pub const SIG = struct {
696696
697697pub const Sigaction = extern struct {
698698 pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
699 pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
699 pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*anyopaque) callconv(.C) void;
700700
701701 handler: extern union {
702702 handler: ?handler_fn,
......@@ -738,7 +738,7 @@ const siginfo_fields_union = extern union {
738738 },
739739 },
740740 sigfault: extern struct {
741 addr: *anyopaque,
741 addr: *allowzero anyopaque,
742742 addr_lsb: i16,
743743 first: extern union {
744744 addr_bnd: extern struct {
lib/std/os/linux.zig+8-8
......@@ -1609,18 +1609,18 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {
16091609 return syscall3(.socket, domain, socket_type, protocol);
16101610}
16111611
1612pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize {
1612pub fn setsockopt(fd: i32, level: i32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize {
16131613 if (native_arch == .x86) {
1614 return socketcall(SC.setsockopt, &[5]usize{ @as(usize, @bitCast(@as(isize, fd))), level, optname, @intFromPtr(optval), @as(usize, @intCast(optlen)) });
1614 return socketcall(SC.setsockopt, &[5]usize{ @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(@as(isize, level))), optname, @intFromPtr(optval), @as(usize, @intCast(optlen)) });
16151615 }
1616 return syscall5(.setsockopt, @as(usize, @bitCast(@as(isize, fd))), level, optname, @intFromPtr(optval), @as(usize, @intCast(optlen)));
1616 return syscall5(.setsockopt, @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(@as(isize, level))), optname, @intFromPtr(optval), @as(usize, @intCast(optlen)));
16171617}
16181618
1619pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize {
1619pub fn getsockopt(fd: i32, level: i32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize {
16201620 if (native_arch == .x86) {
1621 return socketcall(SC.getsockopt, &[5]usize{ @as(usize, @bitCast(@as(isize, fd))), level, optname, @intFromPtr(optval), @intFromPtr(optlen) });
1621 return socketcall(SC.getsockopt, &[5]usize{ @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(@as(isize, level))), optname, @intFromPtr(optval), @intFromPtr(optlen) });
16221622 }
1623 return syscall5(.getsockopt, @as(usize, @bitCast(@as(isize, fd))), level, optname, @intFromPtr(optval), @intFromPtr(optlen));
1623 return syscall5(.getsockopt, @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(@as(isize, level))), optname, @intFromPtr(optval), @intFromPtr(optlen));
16241624}
16251625
16261626pub fn sendmsg(fd: i32, msg: *const msghdr_const, flags: u32) usize {
......@@ -4329,7 +4329,7 @@ pub const k_sigaction = switch (native_arch) {
43294329/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
43304330pub const Sigaction = extern struct {
43314331 pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
4332 pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
4332 pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*anyopaque) callconv(.C) void;
43334333
43344334 handler: extern union {
43354335 handler: ?handler_fn,
......@@ -4690,7 +4690,7 @@ const siginfo_fields_union = extern union {
46904690 },
46914691 },
46924692 sigfault: extern struct {
4693 addr: *anyopaque,
4693 addr: *allowzero anyopaque,
46944694 addr_lsb: i16,
46954695 first: extern union {
46964696 addr_bnd: extern struct {
lib/std/os/plan9.zig+1-1
......@@ -187,7 +187,7 @@ pub const siginfo_t = c_long;
187187// TODO plan9 doesn't have sigaction_fn. Sigaction is not a union, but we incude it here to be compatible.
188188pub const Sigaction = extern struct {
189189 pub const handler_fn = *const fn (c_int) callconv(.C) void;
190 pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
190 pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*anyopaque) callconv(.C) void;
191191
192192 handler: extern union {
193193 handler: ?handler_fn,
lib/std/posix.zig+4-4
......@@ -3493,7 +3493,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t
34933493 return rc;
34943494 }
34953495
3496 const have_sock_flags = !builtin.target.isDarwin();
3496 const have_sock_flags = !builtin.target.isDarwin() and native_os != .haiku;
34973497 const filtered_sock_type = if (!have_sock_flags)
34983498 socket_type & ~@as(u32, SOCK.NONBLOCK | SOCK.CLOEXEC)
34993499 else
......@@ -3789,7 +3789,7 @@ pub fn accept(
37893789 /// description of the `CLOEXEC` flag in `open` for reasons why this may be useful.
37903790 flags: u32,
37913791) AcceptError!socket_t {
3792 const have_accept4 = !(builtin.target.isDarwin() or native_os == .windows);
3792 const have_accept4 = !(builtin.target.isDarwin() or native_os == .windows or native_os == .haiku);
37933793 assert(0 == (flags & ~@as(u32, SOCK.NONBLOCK | SOCK.CLOEXEC))); // Unsupported flag(s)
37943794
37953795 const accepted_sock: socket_t = while (true) {
......@@ -6676,9 +6676,9 @@ pub const SetSockOptError = error{
66766676} || UnexpectedError;
66776677
66786678/// Set a socket's options.
6679pub fn setsockopt(fd: socket_t, level: u32, optname: u32, opt: []const u8) SetSockOptError!void {
6679pub fn setsockopt(fd: socket_t, level: i32, optname: u32, opt: []const u8) SetSockOptError!void {
66806680 if (native_os == .windows) {
6681 const rc = windows.ws2_32.setsockopt(fd, @intCast(level), @intCast(optname), opt.ptr, @intCast(opt.len));
6681 const rc = windows.ws2_32.setsockopt(fd, level, @intCast(optname), opt.ptr, @intCast(opt.len));
66826682 if (rc == windows.ws2_32.SOCKET_ERROR) {
66836683 switch (windows.ws2_32.WSAGetLastError()) {
66846684 .WSANOTINITIALISED => unreachable,
src/target.zig+1
......@@ -301,6 +301,7 @@ pub fn libcFullLinkFlags(target: std.Target) []const []const u8 {
301301 "-lroot",
302302 "-lpthread",
303303 "-lc",
304 "-lnetwork",
304305 },
305306 else => switch (target.abi) {
306307 .android => &[_][]const u8{
stage1/wasm2c.c+3-3
......@@ -261,13 +261,13 @@ int main(int argc, char **argv) {
261261 " uint8_t *new_m = *m;\n"
262262 " uint32_t r = *p;\n"
263263 " uint32_t new_p = r + n;\n"
264 " if (new_p > UINT32_C(0x10000)) return UINT32_C(0xFFFFFFF);\n"
264 " if (new_p > UINT32_C(0xFFFF)) return UINT32_C(0xFFFFFFFF);\n"
265265 " uint32_t new_c = *c;\n"
266266 " if (new_c < new_p) {\n"
267267 " do new_c += new_c / 2 + 8; while (new_c < new_p);\n"
268 " if (new_c > UINT32_C(0x10000)) new_c = UINT32_C(0x10000);\n"
268 " if (new_c > UINT32_C(0xFFFF)) new_c = UINT32_C(0xFFFF);\n"
269269 " new_m = realloc(new_m, new_c << 16);\n"
270 " if (new_m == NULL) return UINT32_C(0xFFFFFFF);\n"
270 " if (new_m == NULL) return UINT32_C(0xFFFFFFFF);\n"
271271 " *m = new_m;\n"
272272 " *c = new_c;\n"
273273 " }\n"