aboutsummaryrefslogtreecommitdiff
path: root/lib/std/start.zig
diff options
context:
space:
mode:
Diffstat (limited to 'lib/std/start.zig')
-rw-r--r--lib/std/start.zig45
1 files changed, 40 insertions, 5 deletions
diff --git a/lib/std/start.zig b/lib/std/start.zig
index 49695a3a25..3a2b0714f7 100644
--- a/lib/std/start.zig
+++ b/lib/std/start.zig
@@ -407,7 +407,7 @@ fn posixCallMainAndExit() callconv(.C) noreturn {
// FIXME: Make __aeabi_read_tp call the kernel helper kuser_get_tls
// For the time being use a simple abort instead of a @panic call to
// keep the binary bloat under control.
- std.os.abort();
+ std.posix.abort();
}
}
@@ -422,7 +422,7 @@ fn posixCallMainAndExit() callconv(.C) noreturn {
expandStackSize(phdrs);
}
- std.os.exit(callMainWithArgs(argc, argv, envp));
+ std.posix.exit(callMainWithArgs(argc, argv, envp));
}
fn expandStackSize(phdrs: []elf.Phdr) void {
@@ -432,13 +432,13 @@ fn expandStackSize(phdrs: []elf.Phdr) void {
assert(phdr.p_memsz % std.mem.page_size == 0);
// Silently fail if we are unable to get limits.
- const limits = std.os.getrlimit(.STACK) catch break;
+ const limits = std.posix.getrlimit(.STACK) catch break;
// Clamp to limits.max .
const wanted_stack_size = @min(phdr.p_memsz, limits.max);
if (wanted_stack_size > limits.cur) {
- std.os.setrlimit(.STACK, .{
+ std.posix.setrlimit(.STACK, .{
.cur = wanted_stack_size,
.max = limits.max,
}) catch {
@@ -464,7 +464,7 @@ inline fn callMainWithArgs(argc: usize, argv: [*][*:0]u8, envp: [][*:0]u8) u8 {
std.os.environ = envp;
std.debug.maybeEnableSegfaultHandler();
- std.os.maybeIgnoreSigpipe();
+ maybeIgnoreSigpipe();
return callMain();
}
@@ -563,3 +563,38 @@ pub fn call_wWinMain() std.os.windows.INT {
// second parameter hPrevInstance, MSDN: "This parameter is always NULL"
return root.wWinMain(hInstance, null, lpCmdLine, nCmdShow);
}
+
+fn maybeIgnoreSigpipe() void {
+ const have_sigpipe_support = switch (builtin.os.tag) {
+ .linux,
+ .plan9,
+ .solaris,
+ .netbsd,
+ .openbsd,
+ .haiku,
+ .macos,
+ .ios,
+ .watchos,
+ .tvos,
+ .dragonfly,
+ .freebsd,
+ => true,
+
+ else => false,
+ };
+
+ if (have_sigpipe_support and !std.options.keep_sigpipe) {
+ const posix = std.posix;
+ const act: posix.Sigaction = .{
+ // Set handler to a noop function instead of `SIG.IGN` to prevent
+ // leaking signal disposition to a child process.
+ .handler = .{ .handler = noopSigHandler },
+ .mask = posix.empty_sigset,
+ .flags = 0,
+ };
+ posix.sigaction(posix.SIG.PIPE, &act, null) catch |err|
+ std.debug.panic("failed to set noop SIGPIPE handler: {s}", .{@errorName(err)});
+ }
+}
+
+fn noopSigHandler(_: c_int) callconv(.C) void {}