authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-18 02:21:59+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-18 11:16:31+02:00
log842de66db831e24476c381aeac625e340030c76b
treedd476d763e94c6135f00f56c25202659ed41c2b5
parentf3eacec226661c11357102dbca5d888817aafbd7
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.os.linux: fix some issues in x32 inline asm

ref https://github.com/ziglang/zig/issues/22189

1 files changed, 17 insertions(+), 19 deletions(-)

lib/std/os/linux/x32.zig+17-19
......@@ -1,5 +1,3 @@
1// TODO: A lot of this file is very likely wrong.
2
31const builtin = @import("builtin");
42const std = @import("../../std.zig");
53const SYS = std.os.linux.SYS;
......@@ -84,20 +82,20 @@ pub fn syscall6(
8482
8583pub fn clone() callconv(.naked) u32 {
8684 asm volatile (
87 \\ movl $56,%%eax // SYS_clone
88 \\ movq %%rdi,%%r11
89 \\ movq %%rdx,%%rdi
90 \\ movq %%r8,%%rdx
91 \\ movq %%r9,%%r8
92 \\ movq 8(%%rsp),%%r10
93 \\ movq %%r11,%%r9
94 \\ andq $-16,%%rsi
95 \\ subq $8,%%rsi
96 \\ movq %%rcx,(%%rsi)
85 \\ movl $0x40000038,%%eax // SYS_clone
86 \\ mov %%rdi,%%r11
87 \\ mov %%rdx,%%rdi
88 \\ mov %%r8,%%rdx
89 \\ mov %%r9,%%r8
90 \\ mov 8(%%rsp),%%r10
91 \\ mov %%r11,%%r9
92 \\ and $-16,%%rsi
93 \\ sub $8,%%rsi
94 \\ mov %%rcx,(%%rsi)
9795 \\ syscall
98 \\ testq %%rax,%%rax
96 \\ test %%eax,%%eax
9997 \\ jz 1f
100 \\ retq
98 \\ ret
10199 \\
102100 \\1:
103101 );
......@@ -105,12 +103,12 @@ pub fn clone() callconv(.naked) u32 {
105103 \\ .cfi_undefined %%rip
106104 );
107105 asm volatile (
108 \\ xorl %%ebp,%%ebp
106 \\ xor %%ebp,%%ebp
109107 \\
110 \\ popq %%rdi
111 \\ callq *%%r9
112 \\ movl %%eax,%%edi
113 \\ movl $60,%%eax // SYS_exit
108 \\ pop %%rdi
109 \\ call *%%r9
110 \\ mov %%eax,%%edi
111 \\ movl $0x4000003c,%%eax // SYS_exit
114112 \\ syscall
115113 \\
116114 );