srctree

Andrew Kelley parent ef31d8f4 2dd74cd3 32b4d856
Merge pull request #19406 from jacobly0/haiku

haiku: get a cross-compiled compiler working
bootstrap.c added: 422, removed: 120, total 302
@@ -64,6 +64,8 @@ static const char *get_host_os(void) {
return "linux";
#elif defined(__FreeBSD__)
return "freebsd";
#elif defined(__HAIKU__)
return "haiku";
#else
panic("unknown host os, specify with ZIG_HOST_TARGET_OS");
#endif
 
lib/std/c.zig added: 422, removed: 120, total 302
@@ -1687,8 +1687,8 @@ pub extern "c" fn getpeername(sockfd: c.fd_t, noalias addr: *c.sockaddr, noalias
pub extern "c" fn connect(sockfd: c.fd_t, sock_addr: *const c.sockaddr, addrlen: c.socklen_t) c_int;
pub extern "c" fn accept(sockfd: c.fd_t, noalias addr: ?*c.sockaddr, noalias addrlen: ?*c.socklen_t) c_int;
pub extern "c" fn accept4(sockfd: c.fd_t, noalias addr: ?*c.sockaddr, noalias addrlen: ?*c.socklen_t, flags: c_uint) c_int;
pub extern "c" fn getsockopt(sockfd: c.fd_t, level: u32, optname: u32, noalias optval: ?*anyopaque, noalias optlen: *c.socklen_t) c_int;
pub extern "c" fn setsockopt(sockfd: c.fd_t, level: u32, optname: u32, optval: ?*const anyopaque, optlen: c.socklen_t) c_int;
pub extern "c" fn getsockopt(sockfd: c.fd_t, level: i32, optname: u32, noalias optval: ?*anyopaque, noalias optlen: *c.socklen_t) c_int;
pub extern "c" fn setsockopt(sockfd: c.fd_t, level: i32, optname: u32, optval: ?*const anyopaque, optlen: c.socklen_t) c_int;
pub extern "c" fn send(sockfd: c.fd_t, buf: *const anyopaque, len: usize, flags: u32) isize;
pub extern "c" fn sendto(
sockfd: c.fd_t,
 
lib/std/c/darwin.zig added: 422, removed: 120, total 302
@@ -1139,7 +1139,7 @@ pub const siginfo_t = extern struct {
pid: pid_t,
uid: uid_t,
status: c_int,
addr: *anyopaque,
addr: *allowzero anyopaque,
value: extern union {
int: c_int,
ptr: *anyopaque,
@@ -1151,7 +1151,7 @@ pub const siginfo_t = extern struct {
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with function name.
pub const Sigaction = extern struct {
pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*anyopaque) callconv(.C) void;
 
handler: extern union {
handler: ?handler_fn,
 
lib/std/c/dragonfly.zig added: 422, removed: 120, total 302
@@ -668,7 +668,7 @@ pub const siginfo_t = extern struct {
pid: c_int,
uid: uid_t,
status: c_int,
addr: ?*anyopaque,
addr: *allowzero anyopaque,
value: sigval,
band: c_long,
__spare__: [7]c_int,
@@ -691,7 +691,7 @@ pub const sig_atomic_t = c_int;
 
pub const Sigaction = extern struct {
pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*anyopaque) callconv(.C) void;
 
/// signal handler
handler: extern union {
 
lib/std/c/freebsd.zig added: 422, removed: 120, total 302
@@ -1172,7 +1172,7 @@ const NSIG = 32;
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
pub const Sigaction = extern struct {
pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*anyopaque) callconv(.C) void;
 
/// signal handler
handler: extern union {
@@ -1206,7 +1206,7 @@ pub const siginfo_t = extern struct {
/// Exit value.
status: c_int,
/// Faulting instruction.
addr: ?*anyopaque,
addr: *allowzero anyopaque,
/// Signal value.
value: sigval,
reason: extern union {
 
lib/std/c/haiku.zig added: 422, removed: 120, total 302
@@ -9,7 +9,7 @@ extern "c" fn _errnop() *c_int;
 
pub const _errno = _errnop;
 
pub extern "c" fn find_directory(which: c_int, volume: i32, createIt: bool, path_ptr: [*]u8, length: i32) u64;
pub extern "c" fn find_directory(which: directory_which, volume: i32, createIt: bool, path_ptr: [*]u8, length: i32) u64;
 
pub extern "c" fn find_thread(thread_name: ?*anyopaque) i32;
 
@@ -427,23 +427,18 @@ pub const W = struct {
}
};
 
pub const SA = struct {
pub const ONSTACK = 0x20;
pub const RESTART = 0x10;
pub const RESETHAND = 0x04;
pub const NOCLDSTOP = 0x01;
pub const NODEFER = 0x08;
pub const NOCLDWAIT = 0x02;
pub const SIGINFO = 0x40;
pub const NOMASK = NODEFER;
pub const STACK = ONSTACK;
pub const ONESHOT = RESETHAND;
};
// posix/signal.h
 
pub const sigset_t = u64;
pub const empty_sigset: sigset_t = 0;
pub const filled_sigset = ~@as(sigset_t, 0);
 
pub const SIG = struct {
pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
pub const DFL: ?Sigaction.handler_fn = @ptrFromInt(0);
pub const IGN: ?Sigaction.handler_fn = @ptrFromInt(1);
pub const ERR: ?Sigaction.handler_fn = @ptrFromInt(maxInt(usize));
 
pub const HOLD: ?Sigaction.handler_fn = @ptrFromInt(3);
 
pub const HUP = 1;
pub const INT = 2;
@@ -484,6 +479,340 @@ pub const SIG = struct {
pub const SETMASK = 3;
};
 
pub const siginfo_t = extern struct {
signo: c_int,
code: c_int,
errno: c_int,
 
pid: pid_t,
uid: uid_t,
addr: *allowzero anyopaque,
};
 
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
pub const Sigaction = extern struct {
pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *allowzero anyopaque, ?*anyopaque) callconv(.C) void;
 
/// signal handler
handler: extern union {
handler: handler_fn,
sigaction: sigaction_fn,
},
 
/// signal mask to apply
mask: sigset_t,
 
/// see signal options
flags: c_int,
 
/// will be passed to the signal handler, BeOS extension
userdata: *allowzero anyopaque = undefined,
};
 
pub const SA = struct {
pub const NOCLDSTOP = 0x01;
pub const NOCLDWAIT = 0x02;
pub const RESETHAND = 0x04;
pub const NODEFER = 0x08;
pub const RESTART = 0x10;
pub const ONSTACK = 0x20;
pub const SIGINFO = 0x40;
pub const NOMASK = NODEFER;
pub const STACK = ONSTACK;
pub const ONESHOT = RESETHAND;
};
 
pub const SS = struct {
pub const ONSTACK = 0x1;
pub const DISABLE = 0x2;
};
 
pub const MINSIGSTKSZ = 8192;
pub const SIGSTKSZ = 16384;
 
pub const stack_t = extern struct {
sp: [*]u8,
size: isize,
flags: i32,
};
 
pub const NSIG = 65;
 
pub const mcontext_t = vregs;
 
pub const ucontext_t = extern struct {
link: ?*ucontext_t,
sigmask: sigset_t,
stack: stack_t,
mcontext: mcontext_t,
};
 
// arch/*/signal.h
 
pub const vregs = switch (builtin.cpu.arch) {
.arm, .thumb => extern struct {
r0: u32,
r1: u32,
r2: u32,
r3: u32,
r4: u32,
r5: u32,
r6: u32,
r7: u32,
r8: u32,
r9: u32,
r10: u32,
r11: u32,
r12: u32,
r13: u32,
r14: u32,
r15: u32,
cpsr: u32,
},
.aarch64 => extern struct {
x: [10]u64,
lr: u64,
sp: u64,
elr: u64,
spsr: u64,
fp_q: [32]u128,
fpsr: u32,
fpcr: u32,
},
.m68k => extern struct {
pc: u32,
d0: u32,
d1: u32,
d2: u32,
d3: u32,
d4: u32,
d5: u32,
d6: u32,
d7: u32,
a0: u32,
a1: u32,
a2: u32,
a3: u32,
a4: u32,
a5: u32,
a6: u32,
a7: u32,
ccr: u8,
f0: f64,
f1: f64,
f2: f64,
f3: f64,
f4: f64,
f5: f64,
f6: f64,
f7: f64,
f8: f64,
f9: f64,
f10: f64,
f11: f64,
f12: f64,
f13: f64,
},
.mipsel => extern struct {
r0: u32,
},
.powerpc => extern struct {
pc: u32,
r0: u32,
r1: u32,
r2: u32,
r3: u32,
r4: u32,
r5: u32,
r6: u32,
r7: u32,
r8: u32,
r9: u32,
r10: u32,
r11: u32,
r12: u32,
f0: f64,
f1: f64,
f2: f64,
f3: f64,
f4: f64,
f5: f64,
f6: f64,
f7: f64,
f8: f64,
f9: f64,
f10: f64,
f11: f64,
f12: f64,
f13: f64,
reserved: u32,
fpscr: u32,
ctr: u32,
xer: u32,
cr: u32,
msr: u32,
lr: u32,
},
.riscv64 => extern struct {
x: [31]u64,
pc: u64,
f: [32]f64,
fcsr: u64,
},
.sparc64 => extern struct {
g1: u64,
g2: u64,
g3: u64,
g4: u64,
g5: u64,
g6: u64,
g7: u64,
o0: u64,
o1: u64,
o2: u64,
o3: u64,
o4: u64,
o5: u64,
sp: u64,
o7: u64,
l0: u64,
l1: u64,
l2: u64,
l3: u64,
l4: u64,
l5: u64,
l6: u64,
l7: u64,
i0: u64,
i1: u64,
i2: u64,
i3: u64,
i4: u64,
i5: u64,
fp: u64,
i7: u64,
},
.x86 => extern struct {
pub const old_extended_regs = extern struct {
control: u16,
reserved1: u16,
status: u16,
reserved2: u16,
tag: u16,
reserved3: u16,
eip: u32,
cs: u16,
opcode: u16,
datap: u32,
ds: u16,
reserved4: u16,
fp_mmx: [8][10]u8,
};
 
pub const fp_register = extern struct { value: [10]u8, reserved: [6]u8 };
 
pub const xmm_register = extern struct { value: [16]u8 };
 
pub const new_extended_regs = extern struct {
control: u16,
status: u16,
tag: u16,
opcode: u16,
eip: u32,
cs: u16,
reserved1: u16,
datap: u32,
ds: u16,
reserved2: u16,
mxcsr: u32,
reserved3: u32,
fp_mmx: [8]fp_register,
xmmx: [8]xmm_register,
reserved4: [224]u8,
};
 
pub const extended_regs = extern struct {
state: extern union {
old_format: old_extended_regs,
new_format: new_extended_regs,
},
format: u32,
};
 
eip: u32,
eflags: u32,
eax: u32,
ecx: u32,
edx: u32,
esp: u32,
ebp: u32,
reserved: u32,
xregs: extended_regs,
edi: u32,
esi: u32,
ebx: u32,
},
.x86_64 => extern struct {
pub const fp_register = extern struct {
value: [10]u8,
reserved: [6]u8,
};
 
pub const xmm_register = extern struct {
value: [16]u8,
};
 
pub const fpu_state = extern struct {
control: u16,
status: u16,
tag: u16,
opcode: u16,
rip: u64,
rdp: u64,
mxcsr: u32,
mscsr_mask: u32,
 
fp_mmx: [8]fp_register,
xmm: [16]xmm_register,
reserved: [96]u8,
};
 
pub const xstate_hdr = extern struct {
bv: u64,
xcomp_bv: u64,
reserved: [48]u8,
};
 
pub const savefpu = extern struct {
fxsave: fpu_state,
xstate: xstate_hdr,
ymm: [16]xmm_register,
};
 
rax: u64,
rbx: u64,
rcx: u64,
rdx: u64,
rdi: u64,
rsi: u64,
rbp: u64,
r8: u64,
r9: u64,
r10: u64,
r11: u64,
r12: u64,
r13: u64,
r14: u64,
r15: u64,
rsp: u64,
rip: u64,
rflags: u64,
fpu: savefpu,
},
else => void,
};
 
// access function
pub const F_OK = 0; // test for existence of file
pub const X_OK = 1; // test for execute or search permission
@@ -527,6 +856,15 @@ pub const SOCK = struct {
pub const DGRAM = 2;
pub const RAW = 3;
pub const SEQPACKET = 5;
 
/// WARNING: this flag is not supported by windows socket functions directly,
/// it is only supported by std.os.socket. Be sure that this value does
/// not share any bits with any of the `SOCK` values.
pub const CLOEXEC = 0x10000;
/// WARNING: this flag is not supported by windows socket functions directly,
/// it is only supported by std.os.socket. Be sure that this value does
/// not share any bits with any of the `SOCK` values.
pub const NONBLOCK = 0x20000;
};
 
pub const SO = struct {
@@ -686,28 +1024,6 @@ pub const winsize = extern struct {
ws_ypixel: u16,
};
 
const NSIG = 32;
 
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
pub const Sigaction = extern struct {
pub const handler_fn = *align(1) const fn (i32) callconv(.C) void;
 
/// signal handler
__sigaction_u: extern union {
__sa_handler: handler_fn,
},
 
/// see signal options
sa_flags: u32,
 
/// signal mask to apply
sa_mask: sigset_t,
};
 
pub const sigset_t = extern struct {
__bits: [SIG.WORDS]u32,
};
 
const B_POSIX_ERROR_BASE = -2147454976;
 
pub const E = enum(i32) {
@@ -802,18 +1118,6 @@ pub const E = enum(i32) {
_,
};
 
pub const MINSIGSTKSZ = 8192;
pub const SIGSTKSZ = 16384;
 
pub const SS_ONSTACK = 0x1;
pub const SS_DISABLE = 0x2;
 
pub const stack_t = extern struct {
sp: [*]u8,
size: isize,
flags: i32,
};
 
pub const S = struct {
pub const IFMT = 0o170000;
pub const IFSOCK = 0o140000;
 
lib/std/c/netbsd.zig added: 422, removed: 120, total 302
@@ -865,7 +865,7 @@ pub const SIG = struct {
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
pub const Sigaction = extern struct {
pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*anyopaque) callconv(.C) void;
 
/// signal handler
handler: extern union {
@@ -908,7 +908,7 @@ pub const _ksiginfo = extern struct {
stime: clock_t,
},
fault: extern struct {
addr: ?*anyopaque,
addr: *allowzero anyopaque,
trap: i32,
trap2: i32,
trap3: i32,
 
lib/std/c/openbsd.zig added: 422, removed: 120, total 302
@@ -843,7 +843,7 @@ pub const SIG = struct {
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
pub const Sigaction = extern struct {
pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*anyopaque) callconv(.C) void;
 
/// signal handler
handler: extern union {
@@ -881,7 +881,7 @@ pub const siginfo_t = extern struct {
},
},
fault: extern struct {
addr: ?*anyopaque,
addr: *allowzero anyopaque,
trapno: c_int,
},
__pad: [128 - 3 * @sizeOf(c_int)]u8,
 
lib/std/c/solaris.zig added: 422, removed: 120, total 302
@@ -875,7 +875,7 @@ pub const SIG = struct {
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
pub const Sigaction = extern struct {
pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*anyopaque) callconv(.C) void;
 
/// signal options
flags: c_uint,
@@ -917,7 +917,7 @@ pub const siginfo_t = extern struct {
zone: zoneid_t,
},
fault: extern struct {
addr: ?*anyopaque,
addr: *allowzero anyopaque,
trapno: c_int,
pc: ?*anyopaque,
},
 
lib/std/debug.zig added: 422, removed: 120, total 302
@@ -229,7 +229,7 @@ pub fn relocateContext(context: *ThreadContext) void {
}
 
pub const have_getcontext = @hasDecl(posix.system, "getcontext") and
native_os != .openbsd and
native_os != .openbsd and native_os != .haiku and
(native_os != .linux or switch (builtin.cpu.arch) {
.x86,
.x86_64,
 
lib/std/fs/get_app_data_dir.zig added: 422, removed: 120, total 302
@@ -42,15 +42,9 @@ pub fn getAppDataDir(allocator: mem.Allocator, appname: []const u8) GetAppDataDi
return fs.path.join(allocator, &[_][]const u8{ home_dir, ".local", "share", appname });
},
.haiku => {
var dir_path_ptr: [*:0]u8 = undefined;
if (true) {
_ = &dir_path_ptr;
@compileError("TODO: init dir_path_ptr");
}
// TODO look into directory_which
const be_user_settings = 0xbbe;
const rc = std.c.find_directory(be_user_settings, -1, true, dir_path_ptr, 1);
const settings_dir = try allocator.dupeZ(u8, mem.sliceTo(dir_path_ptr, 0));
var dir_path_buf: [std.fs.MAX_PATH_BYTES]u8 = undefined;
const rc = std.c.find_directory(.B_USER_SETTINGS_DIRECTORY, -1, true, &dir_path_buf, dir_path_buf.len);
const settings_dir = try allocator.dupeZ(u8, mem.sliceTo(&dir_path_buf, 0));
defer allocator.free(settings_dir);
switch (rc) {
0 => return fs.path.join(allocator, &[_][]const u8{ settings_dir, appname }),
 
lib/std/heap/WasmAllocator.zig added: 422, removed: 120, total 302
@@ -55,7 +55,7 @@ fn alloc(ctx: *anyopaque, len: usize, log2_align: u8, return_address: usize) ?[*
const addr = a: {
const top_free_ptr = frees[class];
if (top_free_ptr != 0) {
const node = @as(*usize, @ptrFromInt(top_free_ptr + (slot_size - @sizeOf(usize))));
const node: *usize = @ptrFromInt(top_free_ptr + (slot_size - @sizeOf(usize)));
frees[class] = node.*;
break :a top_free_ptr;
}
@@ -74,11 +74,10 @@ fn alloc(ctx: *anyopaque, len: usize, log2_align: u8, return_address: usize) ?[*
break :a next_addr;
}
};
return @as([*]u8, @ptrFromInt(addr));
return @ptrFromInt(addr);
}
const bigpages_needed = bigPagesNeeded(actual_len);
const addr = allocBigPages(bigpages_needed);
return @as([*]u8, @ptrFromInt(addr));
return @ptrFromInt(allocBigPages(bigpages_needed));
}
 
fn resize(
@@ -123,14 +122,14 @@ fn free(
const class = math.log2(slot_size) - min_class;
const addr = @intFromPtr(buf.ptr);
if (class < size_class_count) {
const node = @as(*usize, @ptrFromInt(addr + (slot_size - @sizeOf(usize))));
const node: *usize = @ptrFromInt(addr + (slot_size - @sizeOf(usize)));
node.* = frees[class];
frees[class] = addr;
} else {
const bigpages_needed = bigPagesNeeded(actual_len);
const pow2_pages = math.ceilPowerOfTwoAssert(usize, bigpages_needed);
const big_slot_size_bytes = pow2_pages * bigpage_size;
const node = @as(*usize, @ptrFromInt(addr + (big_slot_size_bytes - @sizeOf(usize))));
const node: *usize = @ptrFromInt(addr + (big_slot_size_bytes - @sizeOf(usize)));
const big_class = math.log2(pow2_pages);
node.* = big_frees[big_class];
big_frees[big_class] = addr;
@@ -148,15 +147,14 @@ fn allocBigPages(n: usize) usize {
 
const top_free_ptr = big_frees[class];
if (top_free_ptr != 0) {
const node = @as(*usize, @ptrFromInt(top_free_ptr + (slot_size_bytes - @sizeOf(usize))));
const node: *usize = @ptrFromInt(top_free_ptr + (slot_size_bytes - @sizeOf(usize)));
big_frees[class] = node.*;
return top_free_ptr;
}
 
const page_index = @wasmMemoryGrow(0, pow2_pages * pages_per_bigpage);
if (page_index <= 0) return 0;
const addr = @as(u32, @intCast(page_index)) * wasm.page_size;
return addr;
if (page_index == -1) return 0;
return @as(usize, @intCast(page_index)) * wasm.page_size;
}
 
const test_ally = Allocator{
 
lib/std/io.zig added: 422, removed: 120, total 302
@@ -610,7 +610,10 @@ pub fn Poller(comptime StreamEnum: type) type {
// allocate grows exponentially.
const bump_amt = 512;
 
const err_mask = posix.POLL.ERR | posix.POLL.NVAL | posix.POLL.HUP;
const err_mask = switch (builtin.target.os.tag) {
.haiku => posix.POLL.ERR | posix.POLL.HUP,
else => posix.POLL.ERR | posix.POLL.NVAL | posix.POLL.HUP,
};
 
const events_len = try posix.poll(&self.poll_fds, if (nanoseconds) |ns|
std.math.cast(i32, ns / std.time.ns_per_ms) orelse std.math.maxInt(i32)
 
lib/std/os/emscripten.zig added: 422, removed: 120, total 302
@@ -696,7 +696,7 @@ pub const SIG = struct {
 
pub const Sigaction = extern struct {
pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*anyopaque) callconv(.C) void;
 
handler: extern union {
handler: ?handler_fn,
@@ -738,7 +738,7 @@ const siginfo_fields_union = extern union {
},
},
sigfault: extern struct {
addr: *anyopaque,
addr: *allowzero anyopaque,
addr_lsb: i16,
first: extern union {
addr_bnd: extern struct {
 
lib/std/os/linux.zig added: 422, removed: 120, total 302
@@ -1609,18 +1609,18 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {
return syscall3(.socket, domain, socket_type, protocol);
}
 
pub fn setsockopt(fd: i32, level: u32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize {
pub fn setsockopt(fd: i32, level: i32, optname: u32, optval: [*]const u8, optlen: socklen_t) usize {
if (native_arch == .x86) {
return socketcall(SC.setsockopt, &[5]usize{ @as(usize, @bitCast(@as(isize, fd))), level, optname, @intFromPtr(optval), @as(usize, @intCast(optlen)) });
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)) });
}
return syscall5(.setsockopt, @as(usize, @bitCast(@as(isize, fd))), level, optname, @intFromPtr(optval), @as(usize, @intCast(optlen)));
return syscall5(.setsockopt, @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(@as(isize, level))), optname, @intFromPtr(optval), @as(usize, @intCast(optlen)));
}
 
pub fn getsockopt(fd: i32, level: u32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize {
pub fn getsockopt(fd: i32, level: i32, optname: u32, noalias optval: [*]u8, noalias optlen: *socklen_t) usize {
if (native_arch == .x86) {
return socketcall(SC.getsockopt, &[5]usize{ @as(usize, @bitCast(@as(isize, fd))), level, optname, @intFromPtr(optval), @intFromPtr(optlen) });
return socketcall(SC.getsockopt, &[5]usize{ @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(@as(isize, level))), optname, @intFromPtr(optval), @intFromPtr(optlen) });
}
return syscall5(.getsockopt, @as(usize, @bitCast(@as(isize, fd))), level, optname, @intFromPtr(optval), @intFromPtr(optlen));
return syscall5(.getsockopt, @as(usize, @bitCast(@as(isize, fd))), @as(usize, @bitCast(@as(isize, level))), optname, @intFromPtr(optval), @intFromPtr(optlen));
}
 
pub fn sendmsg(fd: i32, msg: *const msghdr_const, flags: u32) usize {
@@ -4329,7 +4329,7 @@ pub const k_sigaction = switch (native_arch) {
/// Renamed from `sigaction` to `Sigaction` to avoid conflict with the syscall.
pub const Sigaction = extern struct {
pub const handler_fn = *align(1) const fn (c_int) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*anyopaque) callconv(.C) void;
 
handler: extern union {
handler: ?handler_fn,
@@ -4690,7 +4690,7 @@ const siginfo_fields_union = extern union {
},
},
sigfault: extern struct {
addr: *anyopaque,
addr: *allowzero anyopaque,
addr_lsb: i16,
first: extern union {
addr_bnd: extern struct {
 
lib/std/os/plan9.zig added: 422, removed: 120, total 302
@@ -187,7 +187,7 @@ pub const siginfo_t = c_long;
// TODO plan9 doesn't have sigaction_fn. Sigaction is not a union, but we incude it here to be compatible.
pub const Sigaction = extern struct {
pub const handler_fn = *const fn (c_int) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*const anyopaque) callconv(.C) void;
pub const sigaction_fn = *const fn (c_int, *const siginfo_t, ?*anyopaque) callconv(.C) void;
 
handler: extern union {
handler: ?handler_fn,
 
lib/std/posix.zig added: 422, removed: 120, total 302
@@ -3493,7 +3493,7 @@ pub fn socket(domain: u32, socket_type: u32, protocol: u32) SocketError!socket_t
return rc;
}
 
const have_sock_flags = !builtin.target.isDarwin();
const have_sock_flags = !builtin.target.isDarwin() and native_os != .haiku;
const filtered_sock_type = if (!have_sock_flags)
socket_type & ~@as(u32, SOCK.NONBLOCK | SOCK.CLOEXEC)
else
@@ -3789,7 +3789,7 @@ pub fn accept(
/// description of the `CLOEXEC` flag in `open` for reasons why this may be useful.
flags: u32,
) AcceptError!socket_t {
const have_accept4 = !(builtin.target.isDarwin() or native_os == .windows);
const have_accept4 = !(builtin.target.isDarwin() or native_os == .windows or native_os == .haiku);
assert(0 == (flags & ~@as(u32, SOCK.NONBLOCK | SOCK.CLOEXEC))); // Unsupported flag(s)
 
const accepted_sock: socket_t = while (true) {
@@ -6676,9 +6676,9 @@ pub const SetSockOptError = error{
} || UnexpectedError;
 
/// Set a socket's options.
pub fn setsockopt(fd: socket_t, level: u32, optname: u32, opt: []const u8) SetSockOptError!void {
pub fn setsockopt(fd: socket_t, level: i32, optname: u32, opt: []const u8) SetSockOptError!void {
if (native_os == .windows) {
const rc = windows.ws2_32.setsockopt(fd, @intCast(level), @intCast(optname), opt.ptr, @intCast(opt.len));
const rc = windows.ws2_32.setsockopt(fd, level, @intCast(optname), opt.ptr, @intCast(opt.len));
if (rc == windows.ws2_32.SOCKET_ERROR) {
switch (windows.ws2_32.WSAGetLastError()) {
.WSANOTINITIALISED => unreachable,
 
src/target.zig added: 422, removed: 120, total 302
@@ -301,6 +301,7 @@ pub fn libcFullLinkFlags(target: std.Target) []const []const u8 {
"-lroot",
"-lpthread",
"-lc",
"-lnetwork",
},
else => switch (target.abi) {
.android => &[_][]const u8{
 
stage1/wasm2c.c added: 422, removed: 120, total 302
@@ -261,13 +261,13 @@ int main(int argc, char **argv) {
" uint8_t *new_m = *m;\n"
" uint32_t r = *p;\n"
" uint32_t new_p = r + n;\n"
" if (new_p > UINT32_C(0x10000)) return UINT32_C(0xFFFFFFF);\n"
" if (new_p > UINT32_C(0xFFFF)) return UINT32_C(0xFFFFFFFF);\n"
" uint32_t new_c = *c;\n"
" if (new_c < new_p) {\n"
" do new_c += new_c / 2 + 8; while (new_c < new_p);\n"
" if (new_c > UINT32_C(0x10000)) new_c = UINT32_C(0x10000);\n"
" if (new_c > UINT32_C(0xFFFF)) new_c = UINT32_C(0xFFFF);\n"
" new_m = realloc(new_m, new_c << 16);\n"
" if (new_m == NULL) return UINT32_C(0xFFFFFFF);\n"
" if (new_m == NULL) return UINT32_C(0xFFFFFFFF);\n"
" *m = new_m;\n"
" *c = new_c;\n"
" }\n"