authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-09 17:05:48+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-09 17:53:03+02:00
log516040582da20208d2026996c0ca9cf4c1fc20be
tree8ad0c419222004e01bf984c552239abf2d8b4706
parent6d2c427635dfcdbe5867c5af5194cbe175b85003
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.os.linux: fix some bonkers indentation in inline assembly


11 files changed, 290 insertions(+), 291 deletions(-)

lib/std/os/linux/aarch64.zig+21-21
......@@ -116,36 +116,36 @@ pub fn clone() callconv(.naked) u64 {
116116 // syscall(SYS_clone, flags, stack, ptid, tls, ctid)
117117 // x8, x0, x1, x2, x3, x4
118118 asm volatile (
119 \\ // align stack and save func,arg
120 \\ and x1,x1,#-16
121 \\ stp x0,x3,[x1,#-16]!
119 \\ // align stack and save func,arg
120 \\ and x1,x1,#-16
121 \\ stp x0,x3,[x1,#-16]!
122122 \\
123 \\ // syscall
124 \\ uxtw x0,w2
125 \\ mov x2,x4
126 \\ mov x3,x5
127 \\ mov x4,x6
128 \\ mov x8,#220 // SYS_clone
129 \\ svc #0
123 \\ // syscall
124 \\ uxtw x0,w2
125 \\ mov x2,x4
126 \\ mov x3,x5
127 \\ mov x4,x6
128 \\ mov x8,#220 // SYS_clone
129 \\ svc #0
130130 \\
131 \\ cbz x0,1f
132 \\ // parent
133 \\ ret
131 \\ cbz x0,1f
132 \\ // parent
133 \\ ret
134134 \\
135 \\ // child
135 \\ // child
136136 \\1:
137137 );
138138 if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
139 \\ .cfi_undefined lr
139 \\ .cfi_undefined lr
140140 );
141141 asm volatile (
142 \\ mov fp, 0
143 \\ mov lr, 0
142 \\ mov fp, 0
143 \\ mov lr, 0
144144 \\
145 \\ ldp x1,x0,[sp],#16
146 \\ blr x1
147 \\ mov x8,#93 // SYS_exit
148 \\ svc #0
145 \\ ldp x1,x0,[sp],#16
146 \\ blr x1
147 \\ mov x8,#93 // SYS_exit
148 \\ svc #0
149149 );
150150}
151151
lib/std/os/linux/arc.zig+23-23
......@@ -116,37 +116,37 @@ pub fn clone() callconv(.naked) u32 {
116116 // syscall(SYS_clone, flags, stack, ptid, tls, ctid)
117117 // r8 r0, r1, r2, r3, r4
118118 asm volatile (
119 \\ // Align stack pointer
120 \\ and r1, r1, -16
121 \\ mov r10, r0
122 \\ mov r11, r3
123 \\ // Setup the arguments
124 \\ mov r0, r2
125 \\ mov r2, r4
126 \\ mov r3, r5
127 \\ mov r4, r6
128 \\ mov r8, 220 // SYS_clone
129 \\ trap_s 0
130 \\ cmp r0, 0
131 \\ beq 1f
132 \\ j [blink]
133 \\ // Child
134 \\ 1:
119 \\ // Align stack pointer
120 \\ and r1, r1, -16
121 \\ mov r10, r0
122 \\ mov r11, r3
123 \\ // Setup the arguments
124 \\ mov r0, r2
125 \\ mov r2, r4
126 \\ mov r3, r5
127 \\ mov r4, r6
128 \\ mov r8, 220 // SYS_clone
129 \\ trap_s 0
130 \\ cmp r0, 0
131 \\ beq 1f
132 \\ j [blink]
133 \\ // Child
134 \\1:
135135 );
136136 if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
137137 \\ .cfi_undefined blink
138138 );
139139
140140 asm volatile (
141 \\ mov fp, 0
142 \\ mov blink, 0
141 \\ mov fp, 0
142 \\ mov blink, 0
143143 \\
144 \\ mov r0, r11
145 \\ jl [r10]
144 \\ mov r0, r11
145 \\ jl [r10]
146146 \\
147 \\ // Exit
148 \\ mov r8, 93 // SYS_exit
149 \\ trap_s 0
147 \\ // Exit
148 \\ mov r8, 93 // SYS_exit
149 \\ trap_s 0
150150 );
151151}
152152
lib/std/os/linux/arm.zig+25-23
......@@ -116,32 +116,34 @@ pub fn clone() callconv(.naked) u32 {
116116 // syscall(SYS_clone, flags, stack, ptid, tls, ctid)
117117 // r7 r0, r1, r2, r3, r4
118118 asm volatile (
119 \\ stmfd sp!,{r4,r5,r6,r7}
120 \\ mov r7,#120 // SYS_clone
121 \\ mov r6,r3
122 \\ mov r5,r0
123 \\ mov r0,r2
124 \\ and r1,r1,#-16
125 \\ ldr r2,[sp,#16]
126 \\ ldr r3,[sp,#20]
127 \\ ldr r4,[sp,#24]
128 \\ svc 0
129 \\ tst r0,r0
130 \\ beq 1f
131 \\ ldmfd sp!,{r4,r5,r6,r7}
132 \\ bx lr
119 \\ stmfd sp!,{r4,r5,r6,r7}
120 \\ mov r7,#120 // SYS_clone
121 \\ mov r6,r3
122 \\ mov r5,r0
123 \\ mov r0,r2
124 \\ and r1,r1,#-16
125 \\ ldr r2,[sp,#16]
126 \\ ldr r3,[sp,#20]
127 \\ ldr r4,[sp,#24]
128 \\ svc 0
129 \\ tst r0,r0
130 \\ beq 1f
131 \\ ldmfd sp!,{r4,r5,r6,r7}
132 \\ bx lr
133133 \\
134 \\ // https://github.com/llvm/llvm-project/issues/115891
135 \\1: mov r7, #0
136 \\ mov r11, #0
137 \\ mov lr, #0
134 \\ // https://github.com/llvm/llvm-project/issues/115891
135 \\1:
136 \\ mov r7, #0
137 \\ mov r11, #0
138 \\ mov lr, #0
138139 \\
139 \\ mov r0,r6
140 \\ bl 3f
141 \\ mov r7,#1 // SYS_exit
142 \\ svc 0
140 \\ mov r0,r6
141 \\ bl 3f
142 \\ mov r7,#1 // SYS_exit
143 \\ svc 0
143144 \\
144 \\3: bx r5
145 \\3:
146 \\ bx r5
145147 );
146148}
147149
lib/std/os/linux/powerpc.zig+7-7
......@@ -16,7 +16,7 @@ pub fn syscall0(
1616 \\ sc
1717 \\ bns+ 1f
1818 \\ neg 3, 3
19 \\ 1:
19 \\1:
2020 : [ret] "={r3}" (-> u32),
2121 [r0_out] "={r0}" (r0_out),
2222 : [number] "{r0}" (@backingInt(number)),
......@@ -33,7 +33,7 @@ pub fn syscall1(
3333 \\ sc
3434 \\ bns+ 1f
3535 \\ neg 3, 3
36 \\ 1:
36 \\1:
3737 : [ret] "={r3}" (-> u32),
3838 [r0_out] "={r0}" (r0_out),
3939 : [number] "{r0}" (@backingInt(number)),
......@@ -53,7 +53,7 @@ pub fn syscall2(
5353 \\ sc
5454 \\ bns+ 1f
5555 \\ neg 3, 3
56 \\ 1:
56 \\1:
5757 : [ret] "={r3}" (-> u32),
5858 [r0_out] "={r0}" (r0_out),
5959 [r4_out] "={r4}" (r4_out),
......@@ -77,7 +77,7 @@ pub fn syscall3(
7777 \\ sc
7878 \\ bns+ 1f
7979 \\ neg 3, 3
80 \\ 1:
80 \\1:
8181 : [ret] "={r3}" (-> u32),
8282 [r0_out] "={r0}" (r0_out),
8383 [r4_out] "={r4}" (r4_out),
......@@ -105,7 +105,7 @@ pub fn syscall4(
105105 \\ sc
106106 \\ bns+ 1f
107107 \\ neg 3, 3
108 \\ 1:
108 \\1:
109109 : [ret] "={r3}" (-> u32),
110110 [r0_out] "={r0}" (r0_out),
111111 [r4_out] "={r4}" (r4_out),
......@@ -137,7 +137,7 @@ pub fn syscall5(
137137 \\ sc
138138 \\ bns+ 1f
139139 \\ neg 3, 3
140 \\ 1:
140 \\1:
141141 : [ret] "={r3}" (-> u32),
142142 [r0_out] "={r0}" (r0_out),
143143 [r4_out] "={r4}" (r4_out),
......@@ -173,7 +173,7 @@ pub fn syscall6(
173173 \\ sc
174174 \\ bns+ 1f
175175 \\ neg 3, 3
176 \\ 1:
176 \\1:
177177 : [ret] "={r3}" (-> u32),
178178 [r0_out] "={r0}" (r0_out),
179179 [r4_out] "={r4}" (r4_out),
lib/std/os/linux/powerpc64.zig+40-40
......@@ -16,7 +16,7 @@ pub fn syscall0(
1616 \\ sc
1717 \\ bns+ 1f
1818 \\ neg 3, 3
19 \\ 1:
19 \\1:
2020 : [ret] "={r3}" (-> u64),
2121 [r0_out] "={r0}" (r0_out),
2222 : [number] "{r0}" (@backingInt(number)),
......@@ -33,7 +33,7 @@ pub fn syscall1(
3333 \\ sc
3434 \\ bns+ 1f
3535 \\ neg 3, 3
36 \\ 1:
36 \\1:
3737 : [ret] "={r3}" (-> u64),
3838 [r0_out] "={r0}" (r0_out),
3939 : [number] "{r0}" (@backingInt(number)),
......@@ -53,7 +53,7 @@ pub fn syscall2(
5353 \\ sc
5454 \\ bns+ 1f
5555 \\ neg 3, 3
56 \\ 1:
56 \\1:
5757 : [ret] "={r3}" (-> u64),
5858 [r0_out] "={r0}" (r0_out),
5959 [r4_out] "={r4}" (r4_out),
......@@ -77,7 +77,7 @@ pub fn syscall3(
7777 \\ sc
7878 \\ bns+ 1f
7979 \\ neg 3, 3
80 \\ 1:
80 \\1:
8181 : [ret] "={r3}" (-> u64),
8282 [r0_out] "={r0}" (r0_out),
8383 [r4_out] "={r4}" (r4_out),
......@@ -105,7 +105,7 @@ pub fn syscall4(
105105 \\ sc
106106 \\ bns+ 1f
107107 \\ neg 3, 3
108 \\ 1:
108 \\1:
109109 : [ret] "={r3}" (-> u64),
110110 [r0_out] "={r0}" (r0_out),
111111 [r4_out] "={r4}" (r4_out),
......@@ -137,7 +137,7 @@ pub fn syscall5(
137137 \\ sc
138138 \\ bns+ 1f
139139 \\ neg 3, 3
140 \\ 1:
140 \\1:
141141 : [ret] "={r3}" (-> u64),
142142 [r0_out] "={r0}" (r0_out),
143143 [r4_out] "={r4}" (r4_out),
......@@ -173,7 +173,7 @@ pub fn syscall6(
173173 \\ sc
174174 \\ bns+ 1f
175175 \\ neg 3, 3
176 \\ 1:
176 \\1:
177177 : [ret] "={r3}" (-> u64),
178178 [r0_out] "={r0}" (r0_out),
179179 [r4_out] "={r4}" (r4_out),
......@@ -198,51 +198,51 @@ pub fn clone() callconv(.naked) u64 {
198198 // syscall(SYS_clone, flags, stack, ptid, tls, ctid)
199199 // 0 3, 4, 5, 6, 7
200200 asm volatile (
201 \\ # create initial stack frame for new thread
202 \\ clrrdi 4, 4, 4
203 \\ li 0, 0
204 \\ stdu 0,-32(4)
201 \\ # create initial stack frame for new thread
202 \\ clrrdi 4, 4, 4
203 \\ li 0, 0
204 \\ stdu 0,-32(4)
205205 \\
206 \\ # save fn and arg to child stack
207 \\ std 3, 8(4)
208 \\ std 6, 16(4)
206 \\ # save fn and arg to child stack
207 \\ std 3, 8(4)
208 \\ std 6, 16(4)
209209 \\
210 \\ # shuffle args into correct registers and call SYS_clone
211 \\ mr 3, 5
212 \\ #mr 4, 4
213 \\ mr 5, 7
214 \\ mr 6, 8
215 \\ mr 7, 9
216 \\ li 0, 120 # SYS_clone = 120
217 \\ sc
210 \\ # shuffle args into correct registers and call SYS_clone
211 \\ mr 3, 5
212 \\ #mr 4, 4
213 \\ mr 5, 7
214 \\ mr 6, 8
215 \\ mr 7, 9
216 \\ li 0, 120 # SYS_clone = 120
217 \\ sc
218218 \\
219 \\ # if error, negate return (errno)
220 \\ bns+ 1f
221 \\ neg 3, 3
219 \\ # if error, negate return (errno)
220 \\ bns+ 1f
221 \\ neg 3, 3
222222 \\
223223 \\1:
224 \\ # if we're the parent, return
225 \\ cmpwi cr7, 3, 0
226 \\ bnelr cr7
224 \\ # if we're the parent, return
225 \\ cmpwi cr7, 3, 0
226 \\ bnelr cr7
227227 \\
228 \\ # we're the child
228 \\ # we're the child
229229 );
230230 if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
231 \\ .cfi_undefined lr
231 \\ .cfi_undefined lr
232232 );
233233 asm volatile (
234 \\ li 31, 0
235 \\ mtlr 31
234 \\ li 31, 0
235 \\ mtlr 31
236236 \\
237 \\ # call fn(arg)
238 \\ ld 3, 16(1)
239 \\ ld 12, 8(1)
240 \\ mtctr 12
241 \\ bctrl
237 \\ # call fn(arg)
238 \\ ld 3, 16(1)
239 \\ ld 12, 8(1)
240 \\ mtctr 12
241 \\ bctrl
242242 \\
243 \\ # call SYS_exit. exit code is already in r3 from fn return value
244 \\ li 0, 1 # SYS_exit = 1
245 \\ sc
243 \\ # call SYS_exit. exit code is already in r3 from fn return value
244 \\ li 0, 1 # SYS_exit = 1
245 \\ sc
246246 );
247247}
248248
lib/std/os/linux/riscv32.zig+25-25
......@@ -116,41 +116,41 @@ pub fn clone() callconv(.naked) u32 {
116116 // syscall(SYS_clone, flags, stack, ptid, tls, ctid)
117117 // a7 a0, a1, a2, a3, a4
118118 asm volatile (
119 \\ andi a1, a1, -16
120 \\ # Save func and arg to stack
121 \\ addi a1, a1, -16
122 \\ sw a0, 0(a1)
123 \\ sw a3, 4(a1)
119 \\ andi a1, a1, -16
120 \\ # Save func and arg to stack
121 \\ addi a1, a1, -16
122 \\ sw a0, 0(a1)
123 \\ sw a3, 4(a1)
124124 \\
125 \\ # Call SYS_clone
126 \\ mv a0, a2
127 \\ mv a2, a4
128 \\ mv a3, a5
129 \\ mv a4, a6
130 \\ li a7, 220 # SYS_clone
131 \\ ecall
125 \\ # Call SYS_clone
126 \\ mv a0, a2
127 \\ mv a2, a4
128 \\ mv a3, a5
129 \\ mv a4, a6
130 \\ li a7, 220 # SYS_clone
131 \\ ecall
132132 \\
133 \\ beqz a0, 1f
134 \\ # Parent
135 \\ ret
133 \\ beqz a0, 1f
134 \\ # Parent
135 \\ ret
136136 \\
137 \\ # Child
137 \\ # Child
138138 \\1:
139139 );
140140 if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
141 \\ .cfi_undefined ra
141 \\ .cfi_undefined ra
142142 );
143143 asm volatile (
144 \\ mv fp, zero
145 \\ mv ra, zero
144 \\ mv fp, zero
145 \\ mv ra, zero
146146 \\
147 \\ lw a1, 0(sp)
148 \\ lw a0, 4(sp)
149 \\ jalr a1
147 \\ lw a1, 0(sp)
148 \\ lw a0, 4(sp)
149 \\ jalr a1
150150 \\
151 \\ # Exit
152 \\ li a7, 93 # SYS_exit
153 \\ ecall
151 \\ # Exit
152 \\ li a7, 93 # SYS_exit
153 \\ ecall
154154 );
155155}
156156
lib/std/os/linux/riscv64.zig+25-25
......@@ -116,41 +116,41 @@ pub fn clone() callconv(.naked) u64 {
116116 // syscall(SYS_clone, flags, stack, ptid, tls, ctid)
117117 // a7 a0, a1, a2, a3, a4
118118 asm volatile (
119 \\ andi a1, a1, -16
120 \\ # Save func and arg to stack
121 \\ addi a1, a1, -16
122 \\ sd a0, 0(a1)
123 \\ sd a3, 8(a1)
119 \\ andi a1, a1, -16
120 \\ # Save func and arg to stack
121 \\ addi a1, a1, -16
122 \\ sd a0, 0(a1)
123 \\ sd a3, 8(a1)
124124 \\
125 \\ # Call SYS_clone
126 \\ mv a0, a2
127 \\ mv a2, a4
128 \\ mv a3, a5
129 \\ mv a4, a6
130 \\ li a7, 220 # SYS_clone
131 \\ ecall
125 \\ # Call SYS_clone
126 \\ mv a0, a2
127 \\ mv a2, a4
128 \\ mv a3, a5
129 \\ mv a4, a6
130 \\ li a7, 220 # SYS_clone
131 \\ ecall
132132 \\
133 \\ beqz a0, 1f
134 \\ # Parent
135 \\ ret
133 \\ beqz a0, 1f
134 \\ # Parent
135 \\ ret
136136 \\
137 \\ # Child
137 \\ # Child
138138 \\1:
139139 );
140140 if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
141 \\ .cfi_undefined ra
141 \\ .cfi_undefined ra
142142 );
143143 asm volatile (
144 \\ mv fp, zero
145 \\ mv ra, zero
144 \\ mv fp, zero
145 \\ mv ra, zero
146146 \\
147 \\ ld a1, 0(sp)
148 \\ ld a0, 8(sp)
149 \\ jalr a1
147 \\ ld a1, 0(sp)
148 \\ ld a0, 8(sp)
149 \\ jalr a1
150150 \\
151 \\ # Exit
152 \\ li a7, 93 # SYS_exit
153 \\ ecall
151 \\ # Exit
152 \\ li a7, 93 # SYS_exit
153 \\ ecall
154154 );
155155}
156156
lib/std/os/linux/s390x.zig+49-50
......@@ -111,72 +111,71 @@ pub fn syscall6(
111111
112112pub fn clone() callconv(.naked) u64 {
113113 asm volatile (
114 \\# int clone(
115 \\# fn, a = r2
116 \\# stack, b = r3
117 \\# flags, c = r4
118 \\# arg, d = r5
119 \\# ptid, e = r6
120 \\# tls, f = *(r15+160)
121 \\# ctid) g = *(r15+168)
122 \\#
123 \\# pseudo C code:
124 \\# tid = syscall(SYS_clone,b,c,e,g,f);
125 \\# if (!tid) syscall(SYS_exit, a(d));
126 \\# return tid;
114 \\ # int clone(
115 \\ # fn, a = r2
116 \\ # stack, b = r3
117 \\ # flags, c = r4
118 \\ # arg, d = r5
119 \\ # ptid, e = r6
120 \\ # tls, f = *(r15+160)
121 \\ # ctid) g = *(r15+168)
122 \\ #
123 \\ # pseudo C code:
124 \\ # tid = syscall(SYS_clone,b,c,e,g,f);
125 \\ # if (!tid) syscall(SYS_exit, a(d));
126 \\ # return tid;
127127 \\
128 \\# preserve call-saved register used as syscall arg
129 \\stg %%r6, 48(%%r15)
128 \\ # preserve call-saved register used as syscall arg
129 \\ stg %%r6, 48(%%r15)
130130 \\
131 \\# create initial stack frame for new thread
132 \\nill %%r3, 0xfff8
133 \\aghi %%r3, -160
134 \\lghi %%r0, 0
135 \\stg %%r0, 0(%%r3)
131 \\ # create initial stack frame for new thread
132 \\ nill %%r3, 0xfff8
133 \\ aghi %%r3, -160
134 \\ lghi %%r0, 0
135 \\ stg %%r0, 0(%%r3)
136136 \\
137 \\# save fn and arg to child stack
138 \\stg %%r2, 8(%%r3)
139 \\stg %%r5, 16(%%r3)
137 \\ # save fn and arg to child stack
138 \\ stg %%r2, 8(%%r3)
139 \\ stg %%r5, 16(%%r3)
140140 \\
141 \\# shuffle args into correct registers and call SYS_clone
142 \\lgr %%r2, %%r3
143 \\lgr %%r3, %%r4
144 \\lgr %%r4, %%r6
145 \\lg %%r5, 168(%%r15)
146 \\lg %%r6, 160(%%r15)
147 \\svc 120
141 \\ # shuffle args into correct registers and call SYS_clone
142 \\ lgr %%r2, %%r3
143 \\ lgr %%r3, %%r4
144 \\ lgr %%r4, %%r6
145 \\ lg %%r5, 168(%%r15)
146 \\ lg %%r6, 160(%%r15)
147 \\ svc 120
148148 \\
149 \\# restore call-saved register
150 \\lg %%r6, 48(%%r15)
149 \\ # restore call-saved register
150 \\ lg %%r6, 48(%%r15)
151151 \\
152 \\# if error or if we're the parent, return
153 \\ltgr %%r2, %%r2
154 \\bnzr %%r14
152 \\ # if error or if we're the parent, return
153 \\ ltgr %%r2, %%r2
154 \\ bnzr %%r14
155155 \\
156 \\# we're the child
156 \\ # we're the child
157157 );
158158 if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
159 \\.cfi_undefined %%r14
159 \\ .cfi_undefined %%r14
160160 );
161161 asm volatile (
162 \\lghi %%r11, 0
163 \\lghi %%r14, 0
162 \\ lghi %%r11, 0
163 \\ lghi %%r14, 0
164164 \\
165 \\# call fn(arg)
166 \\lg %%r1, 8(%%r15)
167 \\lg %%r2, 16(%%r15)
168 \\basr %%r14, %%r1
169 \\
170 \\# call SYS_exit. exit code is already in r2 from fn return value
171 \\svc 1
165 \\ # call fn(arg)
166 \\ lg %%r1, 8(%%r15)
167 \\ lg %%r2, 16(%%r15)
168 \\ basr %%r14, %%r1
172169 \\
170 \\ # call SYS_exit. exit code is already in r2 from fn return value
171 \\ svc 1
173172 );
174173}
175174
176175pub fn restore() callconv(.naked) noreturn {
177176 asm volatile (
178 \\lghi %%r1, %[number]
179 \\svc 0
177 \\ lghi %%r1, %[number]
178 \\ svc 0
180179 :
181180 : [number] "K" (@backingInt(SYS.sigreturn)),
182181 );
......@@ -184,8 +183,8 @@ pub fn restore() callconv(.naked) noreturn {
184183
185184pub fn restore_rt() callconv(.naked) noreturn {
186185 asm volatile (
187 \\lghi %%r1, %[number]
188 \\svc 0
186 \\ lghi %%r1, %[number]
187 \\ svc 0
189188 :
190189 : [number] "K" (@backingInt(SYS.rt_sigreturn)),
191190 );
lib/std/os/linux/x32.zig+21-22
......@@ -125,35 +125,34 @@ pub fn syscall_lseek(
125125
126126pub fn clone() callconv(.naked) u32 {
127127 asm volatile (
128 \\ movl $0x40000038,%%eax // SYS_clone
129 \\ mov %%rdi,%%r11
130 \\ mov %%rdx,%%rdi
131 \\ mov %%r8,%%rdx
132 \\ mov %%r9,%%r8
133 \\ mov 8(%%rsp),%%r10d
134 \\ mov %%r11,%%r9
135 \\ and $-16,%%rsi
136 \\ sub $8,%%rsi
137 \\ mov %%rcx,(%%rsi)
138 \\ syscall
139 \\ test %%eax,%%eax
140 \\ jz 1f
141 \\ ret
128 \\ movl $0x40000038,%%eax // SYS_clone
129 \\ mov %%rdi,%%r11
130 \\ mov %%rdx,%%rdi
131 \\ mov %%r8,%%rdx
132 \\ mov %%r9,%%r8
133 \\ mov 8(%%rsp),%%r10d
134 \\ mov %%r11,%%r9
135 \\ and $-16,%%rsi
136 \\ sub $8,%%rsi
137 \\ mov %%rcx,(%%rsi)
138 \\ syscall
139 \\ test %%eax,%%eax
140 \\ jz 1f
141 \\ ret
142142 \\
143143 \\1:
144144 );
145145 if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
146 \\ .cfi_undefined %%rip
146 \\ .cfi_undefined %%rip
147147 );
148148 asm volatile (
149 \\ xor %%ebp,%%ebp
150 \\
151 \\ pop %%rdi
152 \\ call *%%r9
153 \\ mov %%eax,%%edi
154 \\ movl $0x4000003c,%%eax // SYS_exit
155 \\ syscall
149 \\ xor %%ebp,%%ebp
156150 \\
151 \\ pop %%rdi
152 \\ call *%%r9
153 \\ mov %%eax,%%edi
154 \\ movl $0x4000003c,%%eax // SYS_exit
155 \\ syscall
157156 );
158157}
159158
lib/std/os/linux/x86.zig+33-33
......@@ -142,46 +142,46 @@ pub fn clone() callconv(.naked) u32 {
142142 // syscall(SYS_clone, flags, stack, ptid, tls, ctid)
143143 // eax, ebx, ecx, edx, esi, edi
144144 asm volatile (
145 \\ pushl %%ebp
146 \\ movl %%esp,%%ebp
147 \\ pushl %%ebx
148 \\ pushl %%esi
149 \\ pushl %%edi
150 \\ // Setup the arguments
151 \\ movl 16(%%ebp),%%ebx
152 \\ movl 12(%%ebp),%%ecx
153 \\ andl $-16,%%ecx
154 \\ subl $20,%%ecx
155 \\ movl 20(%%ebp),%%eax
156 \\ movl %%eax,4(%%ecx)
157 \\ movl 8(%%ebp),%%eax
158 \\ movl %%eax,0(%%ecx)
159 \\ movl 24(%%ebp),%%edx
160 \\ movl 28(%%ebp),%%esi
161 \\ movl 32(%%ebp),%%edi
162 \\ movl $120,%%eax // SYS_clone
163 \\ int $128
164 \\ testl %%eax,%%eax
165 \\ jz 1f
166 \\ popl %%edi
167 \\ popl %%esi
168 \\ popl %%ebx
169 \\ popl %%ebp
170 \\ retl
145 \\ pushl %%ebp
146 \\ movl %%esp,%%ebp
147 \\ pushl %%ebx
148 \\ pushl %%esi
149 \\ pushl %%edi
150 \\ // Setup the arguments
151 \\ movl 16(%%ebp),%%ebx
152 \\ movl 12(%%ebp),%%ecx
153 \\ andl $-16,%%ecx
154 \\ subl $20,%%ecx
155 \\ movl 20(%%ebp),%%eax
156 \\ movl %%eax,4(%%ecx)
157 \\ movl 8(%%ebp),%%eax
158 \\ movl %%eax,0(%%ecx)
159 \\ movl 24(%%ebp),%%edx
160 \\ movl 28(%%ebp),%%esi
161 \\ movl 32(%%ebp),%%edi
162 \\ movl $120,%%eax // SYS_clone
163 \\ int $128
164 \\ testl %%eax,%%eax
165 \\ jz 1f
166 \\ popl %%edi
167 \\ popl %%esi
168 \\ popl %%ebx
169 \\ popl %%ebp
170 \\ retl
171171 \\
172172 \\1:
173173 );
174174 if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
175 \\ .cfi_undefined %%eip
175 \\ .cfi_undefined %%eip
176176 );
177177 asm volatile (
178 \\ xorl %%ebp,%%ebp
178 \\ xorl %%ebp,%%ebp
179179 \\
180 \\ popl %%eax
181 \\ calll *%%eax
182 \\ movl %%eax,%%ebx
183 \\ movl $1,%%eax // SYS_exit
184 \\ int $128
180 \\ popl %%eax
181 \\ calll *%%eax
182 \\ movl %%eax,%%ebx
183 \\ movl $1,%%eax // SYS_exit
184 \\ int $128
185185 );
186186}
187187
lib/std/os/linux/x86_64.zig+21-22
......@@ -111,35 +111,34 @@ pub fn syscall6(
111111
112112pub fn clone() callconv(.naked) u64 {
113113 asm volatile (
114 \\ movl $56,%%eax // SYS_clone
115 \\ movq %%rdi,%%r11
116 \\ movq %%rdx,%%rdi
117 \\ movq %%r8,%%rdx
118 \\ movq %%r9,%%r8
119 \\ movq 8(%%rsp),%%r10
120 \\ movq %%r11,%%r9
121 \\ andq $-16,%%rsi
122 \\ subq $8,%%rsi
123 \\ movq %%rcx,(%%rsi)
124 \\ syscall
125 \\ testq %%rax,%%rax
126 \\ jz 1f
127 \\ retq
114 \\ movl $56,%%eax // SYS_clone
115 \\ movq %%rdi,%%r11
116 \\ movq %%rdx,%%rdi
117 \\ movq %%r8,%%rdx
118 \\ movq %%r9,%%r8
119 \\ movq 8(%%rsp),%%r10
120 \\ movq %%r11,%%r9
121 \\ andq $-16,%%rsi
122 \\ subq $8,%%rsi
123 \\ movq %%rcx,(%%rsi)
124 \\ syscall
125 \\ testq %%rax,%%rax
126 \\ jz 1f
127 \\ retq
128128 \\
129129 \\1:
130130 );
131131 if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile (
132 \\ .cfi_undefined %%rip
132 \\ .cfi_undefined %%rip
133133 );
134134 asm volatile (
135 \\ xorl %%ebp,%%ebp
136 \\
137 \\ popq %%rdi
138 \\ callq *%%r9
139 \\ movl %%eax,%%edi
140 \\ movl $60,%%eax // SYS_exit
141 \\ syscall
135 \\ xorl %%ebp,%%ebp
142136 \\
137 \\ popq %%rdi
138 \\ callq *%%r9
139 \\ movl %%eax,%%edi
140 \\ movl $60,%%eax // SYS_exit
141 \\ syscall
143142 );
144143}
145144