]> git.saurik.com Git - apple/xnu.git/blob - libsyscall/custom/__gettimeofday.s
xnu-7195.101.1.tar.gz
[apple/xnu.git] / libsyscall / custom / __gettimeofday.s
1 /*
2 * Copyright (c) 1999-2016 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29 #include "SYS.h"
30
31 /*
32 * A third argument, of type uint64_t*, was added to the gettimeofday syscall
33 * for use cases that also want to know the mach_absolute_time that matches the
34 * time value returned.
35 *
36 * __gettimeofday takes the traditional two arguments. It will zero out the
37 * third argument argument before entering the kernel, behaving like the old
38 * call.
39 *
40 * __gettimeofday_with_mach will pass it through and supporting kernels will
41 * copy-out the mach_absolute_time. Old kernels will leave the pointed to
42 * value alone.
43 */
44
45 .private_extern ___gettimeofday_with_mach
46
47 #if defined(__i386__)
48
49 LABEL(___gettimeofday)
50 pushl $0
51 pushl 12(%esp)
52 pushl 12(%esp)
53 calll ___gettimeofday_with_mach
54 addl $12, %esp
55 ret
56
57 LABEL(___gettimeofday_with_mach)
58 UNIX_SYSCALL_INT_NONAME(gettimeofday,0)
59 /*
60 * <rdar://problem/26410029>
61 * If eax is 0, we're on a new kernel and timeval was written by the kernel.
62 * Otherwise, eax:edx contains the timeval and we marshal into timeval.
63 */
64 cmp $0, %eax
65 je 2f
66 mov 4(%esp),%ecx
67 mov %eax,(%ecx)
68 mov %edx,4(%ecx)
69 xor %eax,%eax
70 2:
71 ret
72
73 #elif defined(__x86_64__)
74
75 __SYSCALL(___gettimeofday_with_mach, gettimeofday, 3)
76
77 LABEL(___gettimeofday)
78 movq $0x0, %rdx // zero out third argument
79
80 UNIX_SYSCALL_NONAME(gettimeofday,0,cerror_nocancel)
81 /*
82 * <rdar://problem/26410029>
83 * If rax is 0, we're on a new kernel and timeval was written by the kernel.
84 * Otherwise, rax:rdx contains the timeval and we marshal into timeval.
85 */
86 cmp $0, %rax
87 je 2f
88 movq %rax, (%rdi)
89 movl %edx, 8(%rdi)
90 xorl %eax, %eax
91 2:
92 ret
93
94 #elif defined(__arm__)
95
96 __SYSCALL2(___gettimeofday_with_mach, gettimeofday, 3, cerror_nocancel)
97
98 .text
99 .align 2
100 .globl ___gettimeofday
101 ___gettimeofday:
102 mov r2, #0x0
103 SYSCALL_NONAME(gettimeofday, 3, cerror_nocancel)
104 bx lr
105
106 #elif defined(__arm64__)
107
108 __SYSCALL2(___gettimeofday_with_mach, gettimeofday, 3, cerror_nocancel)
109
110 .text
111 .align 2
112 .globl ___gettimeofday
113 ___gettimeofday:
114 movz x2, #0x0
115 SYSCALL_NONAME(gettimeofday, 3, cerror_nocancel)
116 ret
117
118 #else
119 #error Unsupported architecture
120 #endif