Skip to content

Commit

Permalink
std.process.Child: use clone3 on arm and arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
ruihe774 committed Jan 3, 2025
1 parent 6305638 commit 46c23d2
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/std/os/linux/aarch64.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 20 additions & 0 deletions lib/std/os/linux/arm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down

0 comments on commit 46c23d2

Please sign in to comment.