Commit a779450fef

LemonBoy <thatlemon@gmail.com>
2020-02-07 16:07:51
linux/i386: Make syscall6 more robust and correct
LLVM10 exposed a subtle flaw in the previous implementation that made the mmap tests fail.
1 parent 7a58ec8
Changed files (1)
lib
std
os
linux
lib/std/os/linux/i386.zig
@@ -72,11 +72,17 @@ pub fn syscall6(
     arg5: usize,
     arg6: usize,
 ) usize {
+    // The 6th argument is passed via memory as we're out of registers if ebp is
+    // used as frame pointer. We push arg6 value on the stack before changing
+    // ebp or esp as the compiler may reference it as an offset relative to one
+    // of those two registers.
     return asm volatile (
-        \\  push %%ebp
-        \\  mov %[arg6], %%ebp
-        \\  int $0x80
-        \\  pop %%ebp
+        \\ push %[arg6]
+        \\ push %%ebp
+        \\ mov  4(%%esp), %%ebp
+        \\ int  $0x80
+        \\ pop  %%ebp
+        \\ add  $4, %%esp
         : [ret] "={eax}" (-> usize)
         : [number] "{eax}" (number),
           [arg1] "{ebx}" (arg1),