This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig standard library. Public Function
abort
Public Function
std.process.abort
pubfnabort() noreturn
Causes abnormal process termination.
If linking against libc, this calls std.c.abort. Otherwise it raises SIGABRT followed by SIGKILL.
Invokes the current signal handler for SIGABRT, if any.
pubfnabort() noreturn {
@branchHint(.cold);
// MSVCRT abort() sometimes opens a popup window which is undesirable, so// even when linking libc on Windows we use our own abort implementation.// See https://github.com/ziglang/zig/issues/2071 for more details.if (native_os == .windows) {
if (builtin.mode == .debugandwindows.peb().BeingDebugged.toBool()) {
@breakpoint();
}
windows.ntdll.RtlExitUserProcess(3);
}
if (!builtin.link_libcandnative_os == .linux) {
// The Linux man page says that the libc abort() function// "first unblocks the SIGABRT signal", but this is a footgun// for user-defined signal handlers that want to restore some state in// some program sections and crash in others.// So, the user-installed SIGABRT handler is run, if present.posix.raise(.ABRT) catch {};
// Disable all signal handlers.constfilledset = std.os.linux.sigfillset();
posix.sigprocmask(posix.SIG.BLOCK, &filledset, null);
// Only one thread may proceed to the rest of abort().if (!builtin.single_threaded) {
constglobal = struct {
varabort_entered: bool = false;
};
while (@cmpxchgWeak(bool, &global.abort_entered, false, true, .seq_cst, .seq_cst)) |_| {}
}
// Install default handler so that the tkill below will terminate.constsigact: posix.Sigaction = .{
.handler = .{ .handler = posix.SIG.DFL },
.mask = posix.sigemptyset(),
.flags = 0,
};
posix.sigaction(.ABRT, &sigact, null);
_ = std.os.linux.tkill(std.os.linux.gettid(), .ABRT);
varsigabrtmask = posix.sigemptyset();
posix.sigaddset(&sigabrtmask, .ABRT);
posix.sigprocmask(posix.SIG.UNBLOCK, &sigabrtmask, null);
// Beyond this point should be unreachable.@as(*allowzerovolatileu8, @ptrFromInt(0)).* = 0;
posix.raise(.KILL) catch {};
exit(127); // Pid 1 might not be signalled in some containers.
}
switch (native_os) {
.uefi, .wasi, .emscripten, .cuda, .amdhsa, .other, .freestanding => @trap(),
else => posix.system.abort(),
}
}
Causes abnormal process termination.
If linking against libc, this calls
std.c.abort. Otherwise it raises SIGABRT followed by SIGKILL.Invokes the current signal handler for SIGABRT, if any.