Skip to content

Commit 132cb97

Browse files
committed
std.process.Child: use clone3 on arm and arm64
1 parent 9726435 commit 132cb97

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

lib/std/os/linux/aarch64.zig

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,25 @@ pub fn clone() callconv(.Naked) usize {
133133
);
134134
}
135135

136+
pub fn clone3() callconv(.Naked) usize {
137+
asm volatile (
138+
\\ mov x8,#435 // SYS_clone3
139+
\\ svc #0
140+
\\
141+
\\ cbz x0,1f
142+
\\ ret
143+
\\
144+
\\1: .cfi_undefined lr
145+
\\ mov fp, 0
146+
\\ mov lr, 0
147+
\\
148+
\\ mov x0,x3
149+
\\ blr x2
150+
\\ mov x8,#93 // SYS_exit
151+
\\ svc #0
152+
);
153+
}
154+
136155
pub const restore = restore_rt;
137156

138157
pub fn restore_rt() callconv(.Naked) noreturn {

lib/std/os/linux/arm.zig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,26 @@ pub fn clone() callconv(.Naked) usize {
134134
);
135135
}
136136

137+
pub fn clone3() callconv(.Naked) usize {
138+
asm volatile (
139+
\\ stmfd sp!,{r7}
140+
\\ mov r7,#435 // SYS_clone3
141+
\\ svc 0
142+
\\ tst r0,r0
143+
\\ beq 1f
144+
\\ ldmfd sp!,{r7}
145+
\\ bx lr
146+
\\
147+
\\ // https://github.com/llvm/llvm-project/issues/115891
148+
\\1: mov r11, #0
149+
\\ mov lr, #0
150+
\\ mov r0,r3
151+
\\ bx r2
152+
\\ mov r7,#1 // SYS_exit
153+
\\ svc 0
154+
);
155+
}
156+
137157
pub fn restore() callconv(.Naked) noreturn {
138158
switch (@import("builtin").zig_backend) {
139159
.stage2_c => asm volatile (

0 commit comments

Comments
 (0)