Zig 0.17.0-dev (Split by item)

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 library itself.

clone

arc.clone
pub fn clone() callconv(.naked) u32

File

Code

pub fn clone() callconv(.naked) u32 {
    // __clone(func, stack, flags, arg, ptid, tls, ctid)
    //         r0,   r1,    r2,    r3,  r4,   r5,  r6
    //
    // syscall(SYS_clone, flags, stack, ptid, tls, ctid)
    //         r8         r0,    r1,    r2,   r3,  r4
    asm volatile (
        \\    // Align stack pointer
        \\    and r1, r1, -16
        \\    mov r10, r0
        \\    mov r11, r3
        \\    // Setup the arguments
        \\    mov r0, r2
        \\    mov r2, r4
        \\    mov r3, r5
        \\    mov r4, r6
        \\    mov r8, 220 // SYS_clone
        \\    trap_s 0
        \\    cmp r0, 0
        \\    beq 1f
        \\    j [blink]
        \\    // Child
        \\ 1: 
    );
    if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
        \\ .cfi_undefined blink
    );

    asm volatile (
        \\    mov fp, 0
        \\    mov blink, 0
        \\
        \\    mov r0, r11
        \\    jl [r10]
        \\
        \\    // Exit
        \\    mov r8, 93 // SYS_exit
        \\    trap_s 0
    );
}