diff --git a/lib/std/os/linux/aarch64.zig b/lib/std/os/linux/aarch64.zig index db304a3a33b4..cb9f93465e3b 100644 --- a/lib/std/os/linux/aarch64.zig +++ b/lib/std/os/linux/aarch64.zig @@ -133,6 +133,25 @@ pub fn clone() callconv(.Naked) usize { ); } +pub fn clone3() callconv(.Naked) usize { + asm volatile ( + \\ mov x8,#435 // SYS_clone3 + \\ svc #0 + \\ + \\ cbz x0,1f + \\ ret + \\ + \\1: .cfi_undefined lr + \\ mov fp, 0 + \\ mov lr, 0 + \\ + \\ mov x0,x3 + \\ blr x2 + \\ mov x8,#93 // SYS_exit + \\ svc #0 + ); +} + pub const restore = restore_rt; pub fn restore_rt() callconv(.Naked) noreturn { diff --git a/lib/std/os/linux/arm.zig b/lib/std/os/linux/arm.zig index e9263b5cea85..c936156577a7 100644 --- a/lib/std/os/linux/arm.zig +++ b/lib/std/os/linux/arm.zig @@ -134,6 +134,26 @@ pub fn clone() callconv(.Naked) usize { ); } +pub fn clone3() callconv(.Naked) usize { + asm volatile ( + \\ stmfd sp!,{r7} + \\ mov r7,#435 // SYS_clone3 + \\ svc 0 + \\ tst r0,r0 + \\ beq 1f + \\ ldmfd sp!,{r7} + \\ bx lr + \\ + \\ // https://github.com/llvm/llvm-project/issues/115891 + \\1: mov r11, #0 + \\ mov lr, #0 + \\ mov r0,r3 + \\ bx r2 + \\ mov r7,#1 // SYS_exit + \\ svc 0 + ); +} + pub fn restore() callconv(.Naked) noreturn { switch (@import("builtin").zig_backend) { .stage2_c => asm volatile (