ref: c1c535265d7cdb43050b9e65e40dd9d4eb0d05e9
parent: 0163d4d78382e9cbdd427a55fe08c4b234133e43
author: Ori Bernstein <[email protected]>
date: Sat Jun 14 11:49:49 EDT 2014
Appropriately save/restore registers. We clobber them, we should restore them. That's the calling convention. So say we all.
--- a/libstd/syscall-linux.s
+++ b/libstd/syscall-linux.s
@@ -1,6 +1,14 @@
.globl std$syscall
std$syscall:
- pushq %rbp
+ pushq %rbp
+ pushq %rdi
+ pushq %rsi
+ pushq %rdx
+ pushq %r10
+ pushq %r8
+ pushq %r9
+ pushq %rcx
+ pushq %r11
/*
hack: We load 6 args regardless of
how many we actually have. This may
@@ -8,16 +16,24 @@
doesn't use them, it's going to be
harmless.
*/
- movq 16(%rsp),%rax
- movq 24(%rsp),%rdi
- movq 32(%rsp),%rsi
- movq 40(%rsp),%rdx
- movq 48(%rsp),%r10
- movq 56(%rsp),%r8
- movq 64(%rsp),%r9
+ movq 80 (%rsp),%rax
+ movq 88 (%rsp),%rdi
+ movq 96 (%rsp),%rsi
+ movq 104(%rsp),%rdx
+ movq 112(%rsp),%r10
+ movq 120(%rsp),%r8
+ movq 128(%rsp),%r9
syscall
+ popq %r11
+ popq %rcx
+ popq %r9
+ popq %r8
+ popq %r10
+ popq %rdx
+ popq %rsi
+ popq %rdi
popq %rbp
ret
--- a/libstd/syscall-osx.s
+++ b/libstd/syscall-osx.s
@@ -1,6 +1,14 @@
.globl _std$syscall
_std$syscall:
- pushq %rbp
+ pushq %rbp
+ pushq %rdi
+ pushq %rsi
+ pushq %rdx
+ pushq %r10
+ pushq %r8
+ pushq %r9
+ pushq %rcx
+ pushq %r11
/*
hack: We load 6 args regardless of
how many we actually have. This may
@@ -8,20 +16,31 @@
doesn't use them, it's going to be
harmless.
*/
- movq 16(%rsp),%rax
- movq 24(%rsp),%rdi
- movq 32(%rsp),%rsi
- movq 40(%rsp),%rdx
- movq 48(%rsp),%r10
- movq 56(%rsp),%r8
- movq 64(%rsp),%r9
+ movq 80 (%rsp),%rax
+ movq 88 (%rsp),%rdi
+ movq 96 (%rsp),%rsi
+ movq 104(%rsp),%rdx
+ movq 112(%rsp),%r10
+ movq 120(%rsp),%r8
+ movq 128(%rsp),%r9
syscall
+ syscall
jae success
negq %rax
success:
popq %rbp
+
+ popq %r11
+ popq %rcx
+ popq %r9
+ popq %r8
+ popq %r10
+ popq %rdx
+ popq %rsi
+ popq %rdi
+ popq %rbp
ret
/*
@@ -35,6 +54,14 @@
.globl _std$__osx_fork
_std$__osx_fork:
pushq %rbp
+ pushq %rdi
+ pushq %rsi
+ pushq %rdx
+ pushq %r10
+ pushq %r8
+ pushq %r9
+ pushq %rcx
+ pushq %r11
movq $0x2000002,%rax
syscall
@@ -47,6 +74,14 @@
jz isparent
xorq %rax,%rax
isparent:
+ popq %r11
+ popq %rcx
+ popq %r9
+ popq %r8
+ popq %r10
+ popq %rdx
+ popq %rsi
+ popq %rdi
popq %rbp
ret