From 516040582da20208d2026996c0ca9cf4c1fc20be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 9 Aug 2026 17:05:48 +0200 Subject: [PATCH] std.os.linux: fix some bonkers indentation in inline assembly --- lib/std/os/linux/aarch64.zig | 42 +++++++-------- lib/std/os/linux/arc.zig | 46 ++++++++-------- lib/std/os/linux/arm.zig | 48 +++++++++-------- lib/std/os/linux/powerpc.zig | 14 ++--- lib/std/os/linux/powerpc64.zig | 80 +++++++++++++-------------- lib/std/os/linux/riscv32.zig | 50 ++++++++--------- lib/std/os/linux/riscv64.zig | 50 ++++++++--------- lib/std/os/linux/s390x.zig | 99 +++++++++++++++++----------------- lib/std/os/linux/x32.zig | 43 ++++++++------- lib/std/os/linux/x86.zig | 66 +++++++++++------------ lib/std/os/linux/x86_64.zig | 43 ++++++++------- 11 files changed, 290 insertions(+), 291 deletions(-) diff --git a/lib/std/os/linux/aarch64.zig b/lib/std/os/linux/aarch64.zig index 5381def39f634c526d0cef748c8e89306a494544..930b75bb322040189cbbddc0ccaaf2c5f7eb413d 100644 --- a/lib/std/os/linux/aarch64.zig +++ b/lib/std/os/linux/aarch64.zig @@ -116,36 +116,36 @@ pub fn clone() callconv(.naked) u64 { // syscall(SYS_clone, flags, stack, ptid, tls, ctid) // x8, x0, x1, x2, x3, x4 asm volatile ( - \\ // align stack and save func,arg - \\ and x1,x1,#-16 - \\ stp x0,x3,[x1,#-16]! + \\ // align stack and save func,arg + \\ and x1,x1,#-16 + \\ stp x0,x3,[x1,#-16]! \\ - \\ // syscall - \\ uxtw x0,w2 - \\ mov x2,x4 - \\ mov x3,x5 - \\ mov x4,x6 - \\ mov x8,#220 // SYS_clone - \\ svc #0 + \\ // syscall + \\ uxtw x0,w2 + \\ mov x2,x4 + \\ mov x3,x5 + \\ mov x4,x6 + \\ mov x8,#220 // SYS_clone + \\ svc #0 \\ - \\ cbz x0,1f - \\ // parent - \\ ret + \\ cbz x0,1f + \\ // parent + \\ ret \\ - \\ // child + \\ // child \\1: ); if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( - \\ .cfi_undefined lr + \\ .cfi_undefined lr ); asm volatile ( - \\ mov fp, 0 - \\ mov lr, 0 + \\ mov fp, 0 + \\ mov lr, 0 \\ - \\ ldp x1,x0,[sp],#16 - \\ blr x1 - \\ mov x8,#93 // SYS_exit - \\ svc #0 + \\ ldp x1,x0,[sp],#16 + \\ blr x1 + \\ mov x8,#93 // SYS_exit + \\ svc #0 ); } diff --git a/lib/std/os/linux/arc.zig b/lib/std/os/linux/arc.zig index e2c0785ffc53158eb4b6e17656bd4e95c155481f..faef23963b6effd064af866192bcad3949aea2d1 100644 --- a/lib/std/os/linux/arc.zig +++ b/lib/std/os/linux/arc.zig @@ -116,37 +116,37 @@ pub fn clone() callconv(.naked) u32 { // syscall(SYS_clone, flags, stack, ptid, tls, ctid) // r8 r0, r1, r2, r3, r4 asm volatile ( - \\ // Align stack pointer - \\ and r1, r1, -16 - \\ mov r10, r0 - \\ mov r11, r3 - \\ // Setup the arguments - \\ mov r0, r2 - \\ mov r2, r4 - \\ mov r3, r5 - \\ mov r4, r6 - \\ mov r8, 220 // SYS_clone - \\ trap_s 0 - \\ cmp r0, 0 - \\ beq 1f - \\ j [blink] - \\ // Child - \\ 1: + \\ // Align stack pointer + \\ and r1, r1, -16 + \\ mov r10, r0 + \\ mov r11, r3 + \\ // Setup the arguments + \\ mov r0, r2 + \\ mov r2, r4 + \\ mov r3, r5 + \\ mov r4, r6 + \\ mov r8, 220 // SYS_clone + \\ trap_s 0 + \\ cmp r0, 0 + \\ beq 1f + \\ j [blink] + \\ // Child + \\1: ); if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( \\ .cfi_undefined blink ); asm volatile ( - \\ mov fp, 0 - \\ mov blink, 0 + \\ mov fp, 0 + \\ mov blink, 0 \\ - \\ mov r0, r11 - \\ jl [r10] + \\ mov r0, r11 + \\ jl [r10] \\ - \\ // Exit - \\ mov r8, 93 // SYS_exit - \\ trap_s 0 + \\ // Exit + \\ mov r8, 93 // SYS_exit + \\ trap_s 0 ); } diff --git a/lib/std/os/linux/arm.zig b/lib/std/os/linux/arm.zig index 7d7631b36c6380474e540f2c43d2c59900e319da..522d1c925b5fc2e73377e8591a7a8ca72828ecde 100644 --- a/lib/std/os/linux/arm.zig +++ b/lib/std/os/linux/arm.zig @@ -116,32 +116,34 @@ pub fn clone() callconv(.naked) u32 { // syscall(SYS_clone, flags, stack, ptid, tls, ctid) // r7 r0, r1, r2, r3, r4 asm volatile ( - \\ stmfd sp!,{r4,r5,r6,r7} - \\ mov r7,#120 // SYS_clone - \\ mov r6,r3 - \\ mov r5,r0 - \\ mov r0,r2 - \\ and r1,r1,#-16 - \\ ldr r2,[sp,#16] - \\ ldr r3,[sp,#20] - \\ ldr r4,[sp,#24] - \\ svc 0 - \\ tst r0,r0 - \\ beq 1f - \\ ldmfd sp!,{r4,r5,r6,r7} - \\ bx lr + \\ stmfd sp!,{r4,r5,r6,r7} + \\ mov r7,#120 // SYS_clone + \\ mov r6,r3 + \\ mov r5,r0 + \\ mov r0,r2 + \\ and r1,r1,#-16 + \\ ldr r2,[sp,#16] + \\ ldr r3,[sp,#20] + \\ ldr r4,[sp,#24] + \\ svc 0 + \\ tst r0,r0 + \\ beq 1f + \\ ldmfd sp!,{r4,r5,r6,r7} + \\ bx lr \\ - \\ // https://github.com/llvm/llvm-project/issues/115891 - \\1: mov r7, #0 - \\ mov r11, #0 - \\ mov lr, #0 + \\ // https://github.com/llvm/llvm-project/issues/115891 + \\1: + \\ mov r7, #0 + \\ mov r11, #0 + \\ mov lr, #0 \\ - \\ mov r0,r6 - \\ bl 3f - \\ mov r7,#1 // SYS_exit - \\ svc 0 + \\ mov r0,r6 + \\ bl 3f + \\ mov r7,#1 // SYS_exit + \\ svc 0 \\ - \\3: bx r5 + \\3: + \\ bx r5 ); } diff --git a/lib/std/os/linux/powerpc.zig b/lib/std/os/linux/powerpc.zig index 6d47674234948a9a6e3fb0070507e852bf418656..b1ccf17b5594f4b60beb013f4b7f810e4f318705 100644 --- a/lib/std/os/linux/powerpc.zig +++ b/lib/std/os/linux/powerpc.zig @@ -16,7 +16,7 @@ pub fn syscall0( \\ sc \\ bns+ 1f \\ neg 3, 3 - \\ 1: + \\1: : [ret] "={r3}" (-> u32), [r0_out] "={r0}" (r0_out), : [number] "{r0}" (@backingInt(number)), @@ -33,7 +33,7 @@ pub fn syscall1( \\ sc \\ bns+ 1f \\ neg 3, 3 - \\ 1: + \\1: : [ret] "={r3}" (-> u32), [r0_out] "={r0}" (r0_out), : [number] "{r0}" (@backingInt(number)), @@ -53,7 +53,7 @@ pub fn syscall2( \\ sc \\ bns+ 1f \\ neg 3, 3 - \\ 1: + \\1: : [ret] "={r3}" (-> u32), [r0_out] "={r0}" (r0_out), [r4_out] "={r4}" (r4_out), @@ -77,7 +77,7 @@ pub fn syscall3( \\ sc \\ bns+ 1f \\ neg 3, 3 - \\ 1: + \\1: : [ret] "={r3}" (-> u32), [r0_out] "={r0}" (r0_out), [r4_out] "={r4}" (r4_out), @@ -105,7 +105,7 @@ pub fn syscall4( \\ sc \\ bns+ 1f \\ neg 3, 3 - \\ 1: + \\1: : [ret] "={r3}" (-> u32), [r0_out] "={r0}" (r0_out), [r4_out] "={r4}" (r4_out), @@ -137,7 +137,7 @@ pub fn syscall5( \\ sc \\ bns+ 1f \\ neg 3, 3 - \\ 1: + \\1: : [ret] "={r3}" (-> u32), [r0_out] "={r0}" (r0_out), [r4_out] "={r4}" (r4_out), @@ -173,7 +173,7 @@ pub fn syscall6( \\ sc \\ bns+ 1f \\ neg 3, 3 - \\ 1: + \\1: : [ret] "={r3}" (-> u32), [r0_out] "={r0}" (r0_out), [r4_out] "={r4}" (r4_out), diff --git a/lib/std/os/linux/powerpc64.zig b/lib/std/os/linux/powerpc64.zig index d6f488cad409bef8f7ab9ce082eda5e23ca7f35e..92963a2efbe089d164c4d9296f7596552c1abcc4 100644 --- a/lib/std/os/linux/powerpc64.zig +++ b/lib/std/os/linux/powerpc64.zig @@ -16,7 +16,7 @@ pub fn syscall0( \\ sc \\ bns+ 1f \\ neg 3, 3 - \\ 1: + \\1: : [ret] "={r3}" (-> u64), [r0_out] "={r0}" (r0_out), : [number] "{r0}" (@backingInt(number)), @@ -33,7 +33,7 @@ pub fn syscall1( \\ sc \\ bns+ 1f \\ neg 3, 3 - \\ 1: + \\1: : [ret] "={r3}" (-> u64), [r0_out] "={r0}" (r0_out), : [number] "{r0}" (@backingInt(number)), @@ -53,7 +53,7 @@ pub fn syscall2( \\ sc \\ bns+ 1f \\ neg 3, 3 - \\ 1: + \\1: : [ret] "={r3}" (-> u64), [r0_out] "={r0}" (r0_out), [r4_out] "={r4}" (r4_out), @@ -77,7 +77,7 @@ pub fn syscall3( \\ sc \\ bns+ 1f \\ neg 3, 3 - \\ 1: + \\1: : [ret] "={r3}" (-> u64), [r0_out] "={r0}" (r0_out), [r4_out] "={r4}" (r4_out), @@ -105,7 +105,7 @@ pub fn syscall4( \\ sc \\ bns+ 1f \\ neg 3, 3 - \\ 1: + \\1: : [ret] "={r3}" (-> u64), [r0_out] "={r0}" (r0_out), [r4_out] "={r4}" (r4_out), @@ -137,7 +137,7 @@ pub fn syscall5( \\ sc \\ bns+ 1f \\ neg 3, 3 - \\ 1: + \\1: : [ret] "={r3}" (-> u64), [r0_out] "={r0}" (r0_out), [r4_out] "={r4}" (r4_out), @@ -173,7 +173,7 @@ pub fn syscall6( \\ sc \\ bns+ 1f \\ neg 3, 3 - \\ 1: + \\1: : [ret] "={r3}" (-> u64), [r0_out] "={r0}" (r0_out), [r4_out] "={r4}" (r4_out), @@ -198,51 +198,51 @@ pub fn clone() callconv(.naked) u64 { // syscall(SYS_clone, flags, stack, ptid, tls, ctid) // 0 3, 4, 5, 6, 7 asm volatile ( - \\ # create initial stack frame for new thread - \\ clrrdi 4, 4, 4 - \\ li 0, 0 - \\ stdu 0,-32(4) + \\ # create initial stack frame for new thread + \\ clrrdi 4, 4, 4 + \\ li 0, 0 + \\ stdu 0,-32(4) \\ - \\ # save fn and arg to child stack - \\ std 3, 8(4) - \\ std 6, 16(4) + \\ # save fn and arg to child stack + \\ std 3, 8(4) + \\ std 6, 16(4) \\ - \\ # shuffle args into correct registers and call SYS_clone - \\ mr 3, 5 - \\ #mr 4, 4 - \\ mr 5, 7 - \\ mr 6, 8 - \\ mr 7, 9 - \\ li 0, 120 # SYS_clone = 120 - \\ sc + \\ # shuffle args into correct registers and call SYS_clone + \\ mr 3, 5 + \\ #mr 4, 4 + \\ mr 5, 7 + \\ mr 6, 8 + \\ mr 7, 9 + \\ li 0, 120 # SYS_clone = 120 + \\ sc \\ - \\ # if error, negate return (errno) - \\ bns+ 1f - \\ neg 3, 3 + \\ # if error, negate return (errno) + \\ bns+ 1f + \\ neg 3, 3 \\ \\1: - \\ # if we're the parent, return - \\ cmpwi cr7, 3, 0 - \\ bnelr cr7 + \\ # if we're the parent, return + \\ cmpwi cr7, 3, 0 + \\ bnelr cr7 \\ - \\ # we're the child + \\ # we're the child ); if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( - \\ .cfi_undefined lr + \\ .cfi_undefined lr ); asm volatile ( - \\ li 31, 0 - \\ mtlr 31 + \\ li 31, 0 + \\ mtlr 31 \\ - \\ # call fn(arg) - \\ ld 3, 16(1) - \\ ld 12, 8(1) - \\ mtctr 12 - \\ bctrl + \\ # call fn(arg) + \\ ld 3, 16(1) + \\ ld 12, 8(1) + \\ mtctr 12 + \\ bctrl \\ - \\ # call SYS_exit. exit code is already in r3 from fn return value - \\ li 0, 1 # SYS_exit = 1 - \\ sc + \\ # call SYS_exit. exit code is already in r3 from fn return value + \\ li 0, 1 # SYS_exit = 1 + \\ sc ); } diff --git a/lib/std/os/linux/riscv32.zig b/lib/std/os/linux/riscv32.zig index 16e39c50df60df12dbe86658a5c8c1ab68a16b16..609e59151da3012b9de1061979767e3f94b0d3e6 100644 --- a/lib/std/os/linux/riscv32.zig +++ b/lib/std/os/linux/riscv32.zig @@ -116,41 +116,41 @@ pub fn clone() callconv(.naked) u32 { // syscall(SYS_clone, flags, stack, ptid, tls, ctid) // a7 a0, a1, a2, a3, a4 asm volatile ( - \\ andi a1, a1, -16 - \\ # Save func and arg to stack - \\ addi a1, a1, -16 - \\ sw a0, 0(a1) - \\ sw a3, 4(a1) + \\ andi a1, a1, -16 + \\ # Save func and arg to stack + \\ addi a1, a1, -16 + \\ sw a0, 0(a1) + \\ sw a3, 4(a1) \\ - \\ # Call SYS_clone - \\ mv a0, a2 - \\ mv a2, a4 - \\ mv a3, a5 - \\ mv a4, a6 - \\ li a7, 220 # SYS_clone - \\ ecall + \\ # Call SYS_clone + \\ mv a0, a2 + \\ mv a2, a4 + \\ mv a3, a5 + \\ mv a4, a6 + \\ li a7, 220 # SYS_clone + \\ ecall \\ - \\ beqz a0, 1f - \\ # Parent - \\ ret + \\ beqz a0, 1f + \\ # Parent + \\ ret \\ - \\ # Child + \\ # Child \\1: ); if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( - \\ .cfi_undefined ra + \\ .cfi_undefined ra ); asm volatile ( - \\ mv fp, zero - \\ mv ra, zero + \\ mv fp, zero + \\ mv ra, zero \\ - \\ lw a1, 0(sp) - \\ lw a0, 4(sp) - \\ jalr a1 + \\ lw a1, 0(sp) + \\ lw a0, 4(sp) + \\ jalr a1 \\ - \\ # Exit - \\ li a7, 93 # SYS_exit - \\ ecall + \\ # Exit + \\ li a7, 93 # SYS_exit + \\ ecall ); } diff --git a/lib/std/os/linux/riscv64.zig b/lib/std/os/linux/riscv64.zig index accde6d5e6a06db1cfcd4be94f2165ff2c2b6cc4..3d3ce7dba36dd759c5124efaebcfd6c74c588bcb 100644 --- a/lib/std/os/linux/riscv64.zig +++ b/lib/std/os/linux/riscv64.zig @@ -116,41 +116,41 @@ pub fn clone() callconv(.naked) u64 { // syscall(SYS_clone, flags, stack, ptid, tls, ctid) // a7 a0, a1, a2, a3, a4 asm volatile ( - \\ andi a1, a1, -16 - \\ # Save func and arg to stack - \\ addi a1, a1, -16 - \\ sd a0, 0(a1) - \\ sd a3, 8(a1) + \\ andi a1, a1, -16 + \\ # Save func and arg to stack + \\ addi a1, a1, -16 + \\ sd a0, 0(a1) + \\ sd a3, 8(a1) \\ - \\ # Call SYS_clone - \\ mv a0, a2 - \\ mv a2, a4 - \\ mv a3, a5 - \\ mv a4, a6 - \\ li a7, 220 # SYS_clone - \\ ecall + \\ # Call SYS_clone + \\ mv a0, a2 + \\ mv a2, a4 + \\ mv a3, a5 + \\ mv a4, a6 + \\ li a7, 220 # SYS_clone + \\ ecall \\ - \\ beqz a0, 1f - \\ # Parent - \\ ret + \\ beqz a0, 1f + \\ # Parent + \\ ret \\ - \\ # Child + \\ # Child \\1: ); if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( - \\ .cfi_undefined ra + \\ .cfi_undefined ra ); asm volatile ( - \\ mv fp, zero - \\ mv ra, zero + \\ mv fp, zero + \\ mv ra, zero \\ - \\ ld a1, 0(sp) - \\ ld a0, 8(sp) - \\ jalr a1 + \\ ld a1, 0(sp) + \\ ld a0, 8(sp) + \\ jalr a1 \\ - \\ # Exit - \\ li a7, 93 # SYS_exit - \\ ecall + \\ # Exit + \\ li a7, 93 # SYS_exit + \\ ecall ); } diff --git a/lib/std/os/linux/s390x.zig b/lib/std/os/linux/s390x.zig index 4f90ad2081a613d8416464df25a98c8529b9d3a9..beebd97c1a89d9c6cb96a890b1fd74fd9a444337 100644 --- a/lib/std/os/linux/s390x.zig +++ b/lib/std/os/linux/s390x.zig @@ -111,72 +111,71 @@ pub fn syscall6( pub fn clone() callconv(.naked) u64 { asm volatile ( - \\# int clone( - \\# fn, a = r2 - \\# stack, b = r3 - \\# flags, c = r4 - \\# arg, d = r5 - \\# ptid, e = r6 - \\# tls, f = *(r15+160) - \\# ctid) g = *(r15+168) - \\# - \\# pseudo C code: - \\# tid = syscall(SYS_clone,b,c,e,g,f); - \\# if (!tid) syscall(SYS_exit, a(d)); - \\# return tid; + \\ # int clone( + \\ # fn, a = r2 + \\ # stack, b = r3 + \\ # flags, c = r4 + \\ # arg, d = r5 + \\ # ptid, e = r6 + \\ # tls, f = *(r15+160) + \\ # ctid) g = *(r15+168) + \\ # + \\ # pseudo C code: + \\ # tid = syscall(SYS_clone,b,c,e,g,f); + \\ # if (!tid) syscall(SYS_exit, a(d)); + \\ # return tid; \\ - \\# preserve call-saved register used as syscall arg - \\stg %%r6, 48(%%r15) + \\ # preserve call-saved register used as syscall arg + \\ stg %%r6, 48(%%r15) \\ - \\# create initial stack frame for new thread - \\nill %%r3, 0xfff8 - \\aghi %%r3, -160 - \\lghi %%r0, 0 - \\stg %%r0, 0(%%r3) + \\ # create initial stack frame for new thread + \\ nill %%r3, 0xfff8 + \\ aghi %%r3, -160 + \\ lghi %%r0, 0 + \\ stg %%r0, 0(%%r3) \\ - \\# save fn and arg to child stack - \\stg %%r2, 8(%%r3) - \\stg %%r5, 16(%%r3) + \\ # save fn and arg to child stack + \\ stg %%r2, 8(%%r3) + \\ stg %%r5, 16(%%r3) \\ - \\# shuffle args into correct registers and call SYS_clone - \\lgr %%r2, %%r3 - \\lgr %%r3, %%r4 - \\lgr %%r4, %%r6 - \\lg %%r5, 168(%%r15) - \\lg %%r6, 160(%%r15) - \\svc 120 + \\ # shuffle args into correct registers and call SYS_clone + \\ lgr %%r2, %%r3 + \\ lgr %%r3, %%r4 + \\ lgr %%r4, %%r6 + \\ lg %%r5, 168(%%r15) + \\ lg %%r6, 160(%%r15) + \\ svc 120 \\ - \\# restore call-saved register - \\lg %%r6, 48(%%r15) + \\ # restore call-saved register + \\ lg %%r6, 48(%%r15) \\ - \\# if error or if we're the parent, return - \\ltgr %%r2, %%r2 - \\bnzr %%r14 + \\ # if error or if we're the parent, return + \\ ltgr %%r2, %%r2 + \\ bnzr %%r14 \\ - \\# we're the child + \\ # we're the child ); if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( - \\.cfi_undefined %%r14 + \\ .cfi_undefined %%r14 ); asm volatile ( - \\lghi %%r11, 0 - \\lghi %%r14, 0 + \\ lghi %%r11, 0 + \\ lghi %%r14, 0 \\ - \\# call fn(arg) - \\lg %%r1, 8(%%r15) - \\lg %%r2, 16(%%r15) - \\basr %%r14, %%r1 - \\ - \\# call SYS_exit. exit code is already in r2 from fn return value - \\svc 1 + \\ # call fn(arg) + \\ lg %%r1, 8(%%r15) + \\ lg %%r2, 16(%%r15) + \\ basr %%r14, %%r1 \\ + \\ # call SYS_exit. exit code is already in r2 from fn return value + \\ svc 1 ); } pub fn restore() callconv(.naked) noreturn { asm volatile ( - \\lghi %%r1, %[number] - \\svc 0 + \\ lghi %%r1, %[number] + \\ svc 0 : : [number] "K" (@backingInt(SYS.sigreturn)), ); @@ -184,8 +183,8 @@ pub fn restore() callconv(.naked) noreturn { pub fn restore_rt() callconv(.naked) noreturn { asm volatile ( - \\lghi %%r1, %[number] - \\svc 0 + \\ lghi %%r1, %[number] + \\ svc 0 : : [number] "K" (@backingInt(SYS.rt_sigreturn)), ); diff --git a/lib/std/os/linux/x32.zig b/lib/std/os/linux/x32.zig index 19509018dd88783047346930ddff37d8b05887df..0e6d6b6c19aed9c378f8034a845ec2f7a66d9665 100644 --- a/lib/std/os/linux/x32.zig +++ b/lib/std/os/linux/x32.zig @@ -125,35 +125,34 @@ pub fn syscall_lseek( pub fn clone() callconv(.naked) u32 { asm volatile ( - \\ movl $0x40000038,%%eax // SYS_clone - \\ mov %%rdi,%%r11 - \\ mov %%rdx,%%rdi - \\ mov %%r8,%%rdx - \\ mov %%r9,%%r8 - \\ mov 8(%%rsp),%%r10d - \\ mov %%r11,%%r9 - \\ and $-16,%%rsi - \\ sub $8,%%rsi - \\ mov %%rcx,(%%rsi) - \\ syscall - \\ test %%eax,%%eax - \\ jz 1f - \\ ret + \\ movl $0x40000038,%%eax // SYS_clone + \\ mov %%rdi,%%r11 + \\ mov %%rdx,%%rdi + \\ mov %%r8,%%rdx + \\ mov %%r9,%%r8 + \\ mov 8(%%rsp),%%r10d + \\ mov %%r11,%%r9 + \\ and $-16,%%rsi + \\ sub $8,%%rsi + \\ mov %%rcx,(%%rsi) + \\ syscall + \\ test %%eax,%%eax + \\ jz 1f + \\ ret \\ \\1: ); if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( - \\ .cfi_undefined %%rip + \\ .cfi_undefined %%rip ); asm volatile ( - \\ xor %%ebp,%%ebp - \\ - \\ pop %%rdi - \\ call *%%r9 - \\ mov %%eax,%%edi - \\ movl $0x4000003c,%%eax // SYS_exit - \\ syscall + \\ xor %%ebp,%%ebp \\ + \\ pop %%rdi + \\ call *%%r9 + \\ mov %%eax,%%edi + \\ movl $0x4000003c,%%eax // SYS_exit + \\ syscall ); } diff --git a/lib/std/os/linux/x86.zig b/lib/std/os/linux/x86.zig index 4a1c593c121939fb58e4ce33cf1d9b2a11f260a2..1537deb7751794f01973e5629614cd803ffc7bf7 100644 --- a/lib/std/os/linux/x86.zig +++ b/lib/std/os/linux/x86.zig @@ -142,46 +142,46 @@ pub fn clone() callconv(.naked) u32 { // syscall(SYS_clone, flags, stack, ptid, tls, ctid) // eax, ebx, ecx, edx, esi, edi asm volatile ( - \\ pushl %%ebp - \\ movl %%esp,%%ebp - \\ pushl %%ebx - \\ pushl %%esi - \\ pushl %%edi - \\ // Setup the arguments - \\ movl 16(%%ebp),%%ebx - \\ movl 12(%%ebp),%%ecx - \\ andl $-16,%%ecx - \\ subl $20,%%ecx - \\ movl 20(%%ebp),%%eax - \\ movl %%eax,4(%%ecx) - \\ movl 8(%%ebp),%%eax - \\ movl %%eax,0(%%ecx) - \\ movl 24(%%ebp),%%edx - \\ movl 28(%%ebp),%%esi - \\ movl 32(%%ebp),%%edi - \\ movl $120,%%eax // SYS_clone - \\ int $128 - \\ testl %%eax,%%eax - \\ jz 1f - \\ popl %%edi - \\ popl %%esi - \\ popl %%ebx - \\ popl %%ebp - \\ retl + \\ pushl %%ebp + \\ movl %%esp,%%ebp + \\ pushl %%ebx + \\ pushl %%esi + \\ pushl %%edi + \\ // Setup the arguments + \\ movl 16(%%ebp),%%ebx + \\ movl 12(%%ebp),%%ecx + \\ andl $-16,%%ecx + \\ subl $20,%%ecx + \\ movl 20(%%ebp),%%eax + \\ movl %%eax,4(%%ecx) + \\ movl 8(%%ebp),%%eax + \\ movl %%eax,0(%%ecx) + \\ movl 24(%%ebp),%%edx + \\ movl 28(%%ebp),%%esi + \\ movl 32(%%ebp),%%edi + \\ movl $120,%%eax // SYS_clone + \\ int $128 + \\ testl %%eax,%%eax + \\ jz 1f + \\ popl %%edi + \\ popl %%esi + \\ popl %%ebx + \\ popl %%ebp + \\ retl \\ \\1: ); if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( - \\ .cfi_undefined %%eip + \\ .cfi_undefined %%eip ); asm volatile ( - \\ xorl %%ebp,%%ebp + \\ xorl %%ebp,%%ebp \\ - \\ popl %%eax - \\ calll *%%eax - \\ movl %%eax,%%ebx - \\ movl $1,%%eax // SYS_exit - \\ int $128 + \\ popl %%eax + \\ calll *%%eax + \\ movl %%eax,%%ebx + \\ movl $1,%%eax // SYS_exit + \\ int $128 ); } diff --git a/lib/std/os/linux/x86_64.zig b/lib/std/os/linux/x86_64.zig index 465a330156554a035b258bcf682fab24cb4fe7ba..9764941fbe5e774c081435b0d7378fd89ad1d083 100644 --- a/lib/std/os/linux/x86_64.zig +++ b/lib/std/os/linux/x86_64.zig @@ -111,35 +111,34 @@ pub fn syscall6( pub fn clone() callconv(.naked) u64 { asm volatile ( - \\ movl $56,%%eax // SYS_clone - \\ movq %%rdi,%%r11 - \\ movq %%rdx,%%rdi - \\ movq %%r8,%%rdx - \\ movq %%r9,%%r8 - \\ movq 8(%%rsp),%%r10 - \\ movq %%r11,%%r9 - \\ andq $-16,%%rsi - \\ subq $8,%%rsi - \\ movq %%rcx,(%%rsi) - \\ syscall - \\ testq %%rax,%%rax - \\ jz 1f - \\ retq + \\ movl $56,%%eax // SYS_clone + \\ movq %%rdi,%%r11 + \\ movq %%rdx,%%rdi + \\ movq %%r8,%%rdx + \\ movq %%r9,%%r8 + \\ movq 8(%%rsp),%%r10 + \\ movq %%r11,%%r9 + \\ andq $-16,%%rsi + \\ subq $8,%%rsi + \\ movq %%rcx,(%%rsi) + \\ syscall + \\ testq %%rax,%%rax + \\ jz 1f + \\ retq \\ \\1: ); if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( - \\ .cfi_undefined %%rip + \\ .cfi_undefined %%rip ); asm volatile ( - \\ xorl %%ebp,%%ebp - \\ - \\ popq %%rdi - \\ callq *%%r9 - \\ movl %%eax,%%edi - \\ movl $60,%%eax // SYS_exit - \\ syscall + \\ xorl %%ebp,%%ebp \\ + \\ popq %%rdi + \\ callq *%%r9 + \\ movl %%eax,%%edi + \\ movl $60,%%eax // SYS_exit + \\ syscall ); } -- 2.54.0