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

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

File

Code

pub fn clone() callconv(.naked) u32 {
    // __clone(func, stack, flags, arg, ptid, tls, ctid)
    //         r4,   r5,    r6,    r7,  +0,   +4,  +8
    //
    // syscall(SYS_clone, flags, stack, ptid, ctid, tls)
    //         r3         r4,    r5,    r6,   r7,   r0
    asm volatile (
        \\ mov #-4, r0
        \\ and r0, r5
        \\
        \\ mov r4, r1
        \\ mov r7, r2
        \\
        \\ mov #120, r3 ! SYS_clone
        \\ mov r6, r4
        \\ mov.l @r15, r6
        \\ mov.l @(r15, 8), r7
        \\ mov.l @(r15, 4), r0
        \\ trapa #31
        \\ or r0, r0
        \\ or r0, r0
        \\ or r0, r0
        \\ or r0, r0
        \\ or r0, r0
        \\
        \\ cmp/eq #0, r0
        \\ bt 1f
        \\
        \\ // parent
        \\ rts
        \\  nop
        \\
        \\ // child
        \\1:
    );
    if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
        \\ .cfi_undefined pr
    );
    asm volatile (
        \\ mov #0, r0
        \\ lds r0, pr
        \\ mov r0, r14
        \\
        \\ mov r2, r4
        \\ jsr @r1
        \\  nop
        \\
        \\ mov #1, r3 ! SYS_exit
        \\ trapa #31
        \\ or r0, r0
        \\ or r0, r0
        \\ or r0, r0
        \\ or r0, r0
        \\ or r0, r0
    );
}