shithub: mc

Download patch

ref: 36fbbe032a98da86409bdb82da1b34cb3a83cca4
parent: 6e4233aaa4883cff2054ae8b43aeff9cf49cad61
author: Ori Bernstein <[email protected]>
date: Wed Aug 27 07:16:21 EDT 2014

Fix gettimeofday() on OSX.

    It's another wonky syscall.

--- a/libstd/sys-osx.myr
+++ b/libstd/sys-osx.myr
@@ -622,8 +622,20 @@
 	-> x castto(uint64)
 }
 
-extern const __osx_fork : (-> pid)
+/* OSX has a number of funky syscalls */
+extern const __osx_fork	: (-> pid)
 extern const __osx_pipe : (fd : fd# -> int64)
+extern const __osx_getpid	: (-> pid)
+extern const __osx_lseek	: (fd:fd, off:uint64, whence:int64 -> int64)
+extern const __osx_gettimeofday	: (tv : timeval#, tz : timezone# -> int)
+/*
+extern const __osx_ptrace
+extern const __osx_signalstack
+extern const __osx_sigreturn
+extern const __osx_thread_selfid
+extern const __osx_vfork
+*/
+
 extern const cstring : (str : byte[:] -> byte#)
 extern const alloca : (sz : size -> byte#)
 extern const __cenvp : byte##
@@ -737,7 +749,7 @@
 	-> syscall(Sysmmap, a(addr), a(len), a(prot), a(flags), a(fd), a(off)) castto(byte#)}
 
 /* time */
-const gettimeofday = {tv, tz;	-> syscall(Sysgettimeofday, a(tv), a(tz)) castto(int)}
+const gettimeofday = {tv, tz;	-> __osx_gettimeofday(tv, tz) castto(int)}
 const settimeofday = {tv, tz;	-> syscall(Syssettimeofday, a(tv), a(tz)) castto(int)}
 
 /* faked  with gettimeofday */
--- a/libstd/syscall-osx.s
+++ b/libstd/syscall-osx.s
@@ -25,10 +25,10 @@
 	movq 128(%rsp),%r9
 
 	syscall
-	jae success
+	jae .success
 	negq %rax
 
-success:
+.success:
 	popq %r11
 	popq %rcx
 	popq %r9
@@ -63,14 +63,14 @@
 	movq $0x2000002,%rax
 	syscall
 
-	jae forksuccess
+	jae .forksuccess
 	negq %rax
 
-forksuccess:
+.forksuccess:
 	testl %edx,%edx
-	jz isparent
+	jz .isparent
 	xorq %rax,%rax
-isparent:
+.isparent:
 
 	popq %r11 
 	popq %rcx 
@@ -103,13 +103,48 @@
 	movq $0x200002a,%rax
 	syscall
 
-	jae pipesuccess
+	jae .pipesuccess
 	negq %rax
 
-pipesuccess:
-	movq 88 (%rsp),%rdi
+.pipesuccess:
+	movq 80(%rsp),%rdi
 	movl %eax,(%rdi)
 	movl %edx,4(%rdi)
+	xorq %rax,%rax
+
+	popq %r11 
+	popq %rcx 
+	popq %r9
+	popq %r8
+	popq %r10 
+	popq %rdx 
+	popq %rsi 
+	popq %rdi 
+	popq %rbp
+	ret
+
+.globl _std$__osx_gettimeofday
+_std$__osx_gettimeofday:
+	pushq %rbp
+	pushq %rdi 
+	pushq %rsi 
+	pushq %rdx 
+	pushq %r10 
+	pushq %r8
+	pushq %r9
+	pushq %rcx 
+	pushq %r11 
+
+	movq $0x2000074,%rax
+	syscall
+
+	jae .gettimeofdaysuccess
+	negq %rax
+
+.gettimeofdaysuccess:
+	movq 80(%rsp),%rdi
+	movq %rax, (%rdi)
+	movl %edx,8(%rdi)
 	xorq %rax,%rax
 
 	popq %r11