feature. See also
. The project being documented here (as the example) is the Zig library itself.
alpha.clone
pub fn clone() callconv(.naked) u64
File
Code
pub fn clone() callconv(.naked) u64 {
// a0, a1, a2, a3, a4, a5, +0
//
// syscall(SYS_clone, flags, stack, ptid, ctid, tls)
// v0 a0, a1, a2, a3, a4
asm volatile (
// a4 = $20, a5 = $21, sp = $30, v0 = $0
\\ # Save function pointer and argument pointer on new thread stack
\\ ldi $1, -8
\\ and $17, $17, $1
\\ lda $17, -16($17)
\\ stq $16, 0($17)
\\ stq $19, 8($17)
\\
\\ # Shuffle (fn,sp,fl,arg,ptid,tls,ctid) to (fl,sp,ptid,ctid,tls)
\\ mov $18, $16
\\ mov $20, $18
\\ ldq $19, 0($30)
\\ mov $21, $20
\\
\\ # Actual syscall
\\ ldi $0, 312 # SYS_clone
\\ callsys
\\ beq $19, 1f
\\ negq $0, $0
\\ ret
\\1:
\\ beq $0, 2f
\\ ret
\\2:
);
if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
\\ .cfi_undefined $26
);
asm volatile (
\\ mov 0, $15
\\
\\ ldq $23, 0($30)
\\ ldq $16, 8($30)
\\ lda $30, 16($30)
\\ jsr $26, ($23)
\\
\\ mov $0, $16
\\ ldi $0, 1 # SYS_EXIT
\\ callsys
);
}