|
|
Message-ID: <20251208174940.949856-4-bill.roberts@arm.com>
Date: Mon, 8 Dec 2025 11:44:46 -0600
From: Bill Roberts <bill.roberts@....com>
To: musl@...ts.openwall.com
Cc: Bill Roberts <bill.roberts@....com>
Subject: [RFC 03/14] aarch64: rewrite vfork routine in C using inline asm
Rewrite the AArch64 vfork routine from assembly into
C implementations using inline assembly.
This change eliminates the need for handwritten function prologues and
epilogues in vfork.s, which simplifies maintenance and allows the compiler
to automatically insert architecture features such as BTI landing pads and
pointer authentication (PAC) sequences where applicable.
Moving to C also enables the compiler to manage register allocation,
stack usage, and ABI compliance automatically while keeping the low-level
behavior (bitmasks and register accesses) explicit and verifiable.
No functional changes intended.
Signed-off-by: Bill Roberts <bill.roberts@....com>
---
src/process/aarch64/vfork.c | 21 +++++++++++++++++++++
src/process/aarch64/vfork.s | 9 ---------
2 files changed, 21 insertions(+), 9 deletions(-)
create mode 100644 src/process/aarch64/vfork.c
delete mode 100644 src/process/aarch64/vfork.s
diff --git a/src/process/aarch64/vfork.c b/src/process/aarch64/vfork.c
new file mode 100644
index 00000000..87ec8ebf
--- /dev/null
+++ b/src/process/aarch64/vfork.c
@@ -0,0 +1,21 @@
+#include <sys/types.h>
+
+#include "syscall.h"
+
+pid_t vfork(void)
+{
+ /* aarch64 Linux syscall: x8 = nr, x0..x5 = args, ret in x0 */
+ register long x8 __asm__("x8") = 220; /* SYS_clone */
+ register long x0 __asm__("x0") = 0x4111; /* SIGCHLD | CLONE_VM | CLONE_VFORK */
+ register long x1 __asm__("x1") = 0; /* arg2 = 0 */
+
+ __asm__ volatile (
+ "svc 0\n\t"
+ ".hidden __syscall_ret\n\t"
+ "b __syscall_ret\n\t"
+ : "+r"(x0) /* x0 = in/out */
+ : "r"(x1), "r"(x8) /* inputs */
+ : "memory", "cc"
+ );
+ __builtin_unreachable();
+}
diff --git a/src/process/aarch64/vfork.s b/src/process/aarch64/vfork.s
deleted file mode 100644
index 429bec8c..00000000
--- a/src/process/aarch64/vfork.s
+++ /dev/null
@@ -1,9 +0,0 @@
-.global vfork
-.type vfork,%function
-vfork:
- mov x8, 220 // SYS_clone
- mov x0, 0x4111 // SIGCHLD | CLONE_VM | CLONE_VFORK
- mov x1, 0
- svc 0
- .hidden __syscall_ret
- b __syscall_ret
--
2.51.0
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.