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

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

File

lib/std/os/linux/csky.zig:112

Code

pub fn clone() callconv(.naked) u32 {
    // __clone(func, stack, flags, arg, ptid, tls, ctid)
    //         r0,   r1,    r2,    r3,  +0,   +4,  +8
    //
    // syscall(SYS_clone, flags, stack, ptid, tls, ctid)
    //         r7         r0,    r1,    r2,   r3,  r4
    asm volatile (
        \\ // Preserve callee-saved registers.
        \\ mov t0, r4
        \\ mov t1, r7
        \\
        \\ andi r1, r1, -8
        \\
        \\ subi r1, 8
        \\ stw r0, (r1, 0)
        \\ stw r3, (r1, 4)
        \\
        \\ movi r7, 220 // SYS_clone
        \\ mov r0, r2
        \\ ldw r2, (sp, 0)
        \\ ldw r3, (sp, 8)
        \\ ldw r4, (sp, 4)
        \\ trap 0
        \\
        \\ cmpnei r0, 0
        \\ jbf 1f
        \\
        \\ // parent
        \\ mov r7, t1
        \\ mov r4, t0
        \\ rts
        \\
        \\ // child
        \\1:
    );
    if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
        \\ .cfi_undefined lr
    );
    asm volatile (
        \\ movi r8, 0
        \\ movi lr, 0
        \\
        \\ ldw r0, (sp, 4)
        \\ ldw r1, (sp, 0)
        \\ jsr r1
        \\
        \\ movi r7, 93 // SYS_exit
        \\ trap 0
    );
}