···11+#define __SYSCALL_32BIT_ARG_BYTES 24
22+#include "SYS.h"
33+44+#ifndef SYS_fsgetpath_ext
55+#error "SYS_fsgetpath_ext not defined. The header files libsyscall is building against do not match syscalls.master."
66+#endif
77+88+#if defined(__arm64__)
99+MI_ENTRY_POINT(_fsgetpath_ext)
1010+ZERO_EXTEND(1)
1111+SYSCALL_NONAME(fsgetpath_ext, 5, cerror_nocancel)
1212+ret
1313+#else
1414+#if defined(__i386__) || defined(__x86_64__) || defined(__ppc__) || defined(__arm__) || defined(__arm64__)
1515+__SYSCALL2(_fsgetpath_ext, fsgetpath_ext, 5, cerror_nocancel)
1616+#endif
1717+1818+#endif
1919+
+177
src/kernel/libsyscall/custom/__fork.S
···11+/*
22+ * Copyright (c) 1999-2010 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. The rights granted to you under the License
1010+ * may not be used to create, or enable the creation or redistribution of,
1111+ * unlawful or unlicensed copies of an Apple operating system, or to
1212+ * circumvent, violate, or enable the circumvention or violation of, any
1313+ * terms of an Apple operating system software license agreement.
1414+ *
1515+ * Please obtain a copy of the License at
1616+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
1717+ *
1818+ * The Original Code and all software distributed under the License are
1919+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
2020+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
2121+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2222+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
2323+ * Please see the License for the specific language governing rights and
2424+ * limitations under the License.
2525+ *
2626+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
2727+ */
2828+/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
2929+ *
3030+ * File: libc/ppc/sys/fork.s
3131+ *
3232+ * HISTORY
3333+ * 18-Nov-92 Ben Fathi (benf@next.com)
3434+ * Created from M88K sources
3535+ *
3636+ * 11-Jan-92 Peter King (king@next.com)
3737+ * Created from M68K sources
3838+ */
3939+4040+/*
4141+ * All of the asm stubs in this file have been adjusted so the pre/post
4242+ * fork handlers and dyld fixup are done in C inside Libc. As such, Libc
4343+ * expects the __fork asm to fix up the return code to be -1, 0 or pid
4444+ * and errno if needed.
4545+ */
4646+4747+#include "SYS.h"
4848+4949+#if defined(__i386__)
5050+5151+LEAF(___fork, 0)
5252+ subl $28, %esp // Align the stack, with 16 bytes of extra padding that we'll need
5353+5454+ movl $ SYS_fork,%eax; // code for fork -> eax
5555+ #ifdef DARLING
5656+ call __darling_bsd_syscall
5757+ cmpl $0, %eax
5858+ jnb L1
5959+ #else
6060+ UNIX_SYSCALL_TRAP // do the system call
6161+ jnc L1 // jump if CF==0
6262+ #endif
6363+6464+ CALL_EXTERN(tramp_cerror)
6565+ movl $-1,%eax
6666+ addl $28, %esp // restore the stack
6767+ ret
6868+6969+L1:
7070+ orl %edx,%edx // CF=OF=0, ZF set if zero result
7171+ jz L2 // parent, since r1 == 0 in parent, 1 in child
7272+7373+ //child here...
7474+ xorl %eax,%eax // zero eax
7575+ REG_TO_EXTERN(%eax, __current_pid);
7676+L2:
7777+ addl $28, %esp // restore the stack
7878+ // parent ends up here skipping child portion
7979+ ret
8080+8181+#elif defined(__x86_64__)
8282+8383+LEAF(___fork, 0)
8484+ subq $24, %rsp // Align the stack, plus room for local storage
8585+8686+ #ifdef DARLING
8787+ movl $ SYS_fork, %eax
8888+ call __darling_bsd_syscall
8989+ cmpq $0, %rax
9090+ jnb L1
9191+ #else
9292+ movl $ SYSCALL_CONSTRUCT_UNIX(SYS_fork),%eax; // code for fork -> rax
9393+ UNIX_SYSCALL_TRAP // do the system call
9494+ jnc L1 // jump if CF==0
9595+ #endif
9696+9797+ movq %rax, %rdi
9898+ CALL_EXTERN(_cerror)
9999+ movq $-1, %rax
100100+ addq $24, %rsp // restore the stack
101101+ ret
102102+103103+L1:
104104+ #ifdef DARLING
105105+ testl %eax, %eax
106106+ jnz L2
107107+ #else
108108+ orl %edx,%edx // CF=OF=0, ZF set if zero result
109109+ jz L2 // parent, since r1 == 0 in parent, 1 in child
110110+ #endif
111111+112112+ //child here...
113113+ xorq %rax, %rax
114114+ PICIFY(__current_pid)
115115+ movl %eax,(%r11)
116116+L2:
117117+ // parent ends up here skipping child portion
118118+ addq $24, %rsp // restore the stack
119119+ ret
120120+121121+#elif defined(__arm__)
122122+123123+MI_ENTRY_POINT(___fork)
124124+ stmfd sp!, {r4, r7, lr}
125125+ add r7, sp, #4
126126+127127+ mov r1, #1 // prime results
128128+ mov r12, #SYS_fork
129129+ swi #SWI_SYSCALL // make the syscall
130130+ bcs Lbotch // error?
131131+132132+ cmp r1, #0 // parent (r1=0) or child(r1=1)
133133+ beq Lparent
134134+135135+ //child here...
136136+ MI_GET_ADDRESS(r3, __current_pid)
137137+ mov r0, #0
138138+ str r0, [r3] // clear cached pid in child
139139+ ldmfd sp!, {r4, r7, pc}
140140+141141+Lbotch:
142142+ MI_CALL_EXTERNAL(_cerror) // jump here on error
143143+ mov r0,#-1 // set the error
144144+ // fall thru
145145+Lparent:
146146+ ldmfd sp!, {r4, r7, pc} // pop and return
147147+148148+#elif defined(__arm64__)
149149+150150+#include <mach/arm64/asm.h>
151151+152152+MI_ENTRY_POINT(___fork)
153153+ ARM64_STACK_PROLOG
154154+ PUSH_FRAME
155155+ // ARM moves a 1 in to r1 here, but I can't see why.
156156+ mov x16, #SYS_fork // Syscall code
157157+ svc #SWI_SYSCALL // Trap to kernel
158158+ b.cs Lbotch // Carry bit indicates failure
159159+ cbz x1, Lparent // x1 == 0 indicates that we are the parent
160160+161161+ // Child
162162+ MI_GET_ADDRESS(x9, __current_pid) // Get address of cached "current pid"
163163+ mov w0, #0
164164+ str w0, [x9] // Clear cached current pid
165165+ POP_FRAME // And done
166166+ ARM64_STACK_EPILOG
167167+168168+Lbotch:
169169+ MI_CALL_EXTERNAL(_cerror) // Handle error
170170+ mov w0, #-1 // Return value is -1
171171+Lparent:
172172+ POP_FRAME // Return
173173+ ARM64_STACK_EPILOG
174174+175175+#else
176176+#error Unsupported architecture
177177+#endif
+1-1
src/kernel/libsyscall/custom/__fork.s
···5454 movl $ SYS_fork,%eax; // code for fork -> eax
5555 #ifdef DARLING
5656 call __darling_bsd_syscall
5757- cmpq $0, %eax
5757+ cmpl $0, %eax
5858 jnb L1
5959 #else
6060 UNIX_SYSCALL_TRAP // do the system call
+173
src/kernel/libsyscall/custom/__getpid.S
···11+/*
22+ * Copyright (c) 1999-2007 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. The rights granted to you under the License
1010+ * may not be used to create, or enable the creation or redistribution of,
1111+ * unlawful or unlicensed copies of an Apple operating system, or to
1212+ * circumvent, violate, or enable the circumvention or violation of, any
1313+ * terms of an Apple operating system software license agreement.
1414+ *
1515+ * Please obtain a copy of the License at
1616+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
1717+ *
1818+ * The Original Code and all software distributed under the License are
1919+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
2020+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
2121+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2222+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
2323+ * Please see the License for the specific language governing rights and
2424+ * limitations under the License.
2525+ *
2626+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
2727+ */
2828+2929+#include "SYS.h"
3030+3131+#if defined(__i386__)
3232+3333+ .data
3434+ .private_extern __current_pid
3535+L__current_pid_addr:
3636+ __current_pid:
3737+ .long 0
3838+3939+#if defined(__DYNAMIC__)
4040+#define GET_CURRENT_PID \
4141+ call 0f ; \
4242+0: ; \
4343+ popl %ecx ; \
4444+ leal L__current_pid_addr-0b(%ecx), %ecx
4545+4646+#define __current_pid (%ecx)
4747+4848+#else
4949+#define GET_CURRENT_PID
5050+#endif
5151+5252+/*
5353+ * If __current_pid is > 0, return it, else make syscall.
5454+ * If __current_pid is 0, cache result of syscall.
5555+ */
5656+TEXT
5757+LEAF(___getpid, 0)
5858+ GET_CURRENT_PID
5959+ movl __current_pid, %eax
6060+ testl %eax, %eax
6161+ jle 1f
6262+ ret
6363+1:
6464+ UNIX_SYSCALL_NONAME(getpid, 0, cerror_nocancel)
6565+ movl %eax, %edx
6666+ xorl %eax, %eax
6767+ GET_CURRENT_PID
6868+ lock
6969+ cmpxchgl %edx, __current_pid
7070+ movl %edx, %eax
7171+ ret
7272+7373+#elif defined(__x86_64__)
7474+7575+ .data
7676+ .private_extern __current_pid
7777+__current_pid:
7878+ .long 0
7979+8080+/*
8181+ * If __current_pid is > 0, return it, else make syscall.
8282+ * If __current_pid is 0, cache result of syscall.
8383+ */
8484+TEXT
8585+LEAF(___getpid, 0)
8686+ movl __current_pid(%rip), %eax
8787+ testl %eax, %eax
8888+ jle 1f
8989+ ret
9090+1:
9191+ UNIX_SYSCALL_NONAME(getpid, 0, cerror_nocancel)
9292+ movl %eax, %edx
9393+ xorl %eax, %eax
9494+ leaq __current_pid(%rip), %rcx
9595+ lock
9696+ cmpxchgl %edx, (%rcx)
9797+ movl %edx, %eax
9898+ ret
9999+100100+#elif defined(__arm__)
101101+102102+#include <arm/arch.h>
103103+104104+ .data
105105+ .globl __current_pid
106106+ .align 2
107107+__current_pid:
108108+ /* Cached pid. Possible values:
109109+ * 0: no value cached
110110+ * > 0: cached PID of current process
111111+ * < 0: negative number of vforks in progress
112112+ * INT_MIN: for pre-ARMv6, "looking" value (0x80000000)
113113+ */
114114+ .long 0
115115+116116+MI_ENTRY_POINT(___getpid)
117117+ ldr r3, L__current_pid
118118+L1: add r3, pc, r3 // r3 = &__current_pid
119119+ ldr r0, [r3] // get the cached pid
120120+ cmp r0, #0
121121+ bxgt lr // if positive, return it
122122+123123+ SYSCALL_NONAME(getpid, 0, cerror_nocancel)
124124+125125+#ifdef _ARM_ARCH_6
126126+ ldrex r2, [r3] // see if we can cache it
127127+ cmp r2, #0 // we can't if there are any...
128128+ bxlt lr // ...vforks in progress
129129+ strex r2, r0, [r3] // ignore conflicts
130130+#else
131131+ mov r1, #0x80000000 // load "looking" value
132132+ swp r2, r1, [r3] // look at the value, lock others out
133133+ cmp r2, r1 // anyone else trying to look?
134134+ bxeq lr // yes, so return immediately/
135135+ cmp r2, #0 // see if we can cache it
136136+ streq r0, [r3] // if zero, we can
137137+ strne r2, [r3] // otherwise restore previous value
138138+#endif
139139+140140+ bx lr
141141+142142+L__current_pid:
143143+ .long __current_pid - (L1+8)
144144+145145+#elif defined(__arm64__)
146146+ .data
147147+ .globl __current_pid
148148+ .align 2
149149+__current_pid:
150150+ /* cached pid. possible values:
151151+ * 0: no value cached
152152+ * > 0: cached pid of current process
153153+ * < 0: negative number of vforks in progress
154154+ * int_min: for pre-armv6, "looking" value (0x80000000)
155155+ */
156156+ .long 0
157157+158158+MI_ENTRY_POINT(___getpid)
159159+ MI_GET_ADDRESS(x9, __current_pid) // Get address of cached value
160160+ ldr w0, [x9] // Load it
161161+ cmp w0, #0 // See if there's a cached value
162162+ b.le L_notcached // If not, make syscall
163163+ ret // Else, we're done
164164+L_notcached:
165165+ SYSCALL_NONAME(getpid, 0, cerror_nocancel)
166166+ ldxr w10, [x9] // Exclusive load
167167+ cbnz w10, L_done // Unless unset, don't even try
168168+ stxr wzr, w0, [x9] // Try to store, but don't care if we fail (someone will win, or not)
169169+L_done:
170170+ ret // Done
171171+#else
172172+#error Unsupported architecture
173173+#endif
+120
src/kernel/libsyscall/custom/__gettimeofday.S
···11+/*
22+ * Copyright (c) 1999-2016 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. The rights granted to you under the License
1010+ * may not be used to create, or enable the creation or redistribution of,
1111+ * unlawful or unlicensed copies of an Apple operating system, or to
1212+ * circumvent, violate, or enable the circumvention or violation of, any
1313+ * terms of an Apple operating system software license agreement.
1414+ *
1515+ * Please obtain a copy of the License at
1616+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
1717+ *
1818+ * The Original Code and all software distributed under the License are
1919+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
2020+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
2121+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2222+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
2323+ * Please see the License for the specific language governing rights and
2424+ * limitations under the License.
2525+ *
2626+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
2727+ */
2828+2929+#include "SYS.h"
3030+3131+/*
3232+ * A third argument, of type uint64_t*, was added to the gettimeofday syscall
3333+ * for use cases that also want to know the mach_absolute_time that matches the
3434+ * time value returned.
3535+ *
3636+ * __gettimeofday takes the traditional two arguments. It will zero out the
3737+ * third argument argument before entering the kernel, behaving like the old
3838+ * call.
3939+ *
4040+ * __gettimeofday_with_mach will pass it through and supporting kernels will
4141+ * copy-out the mach_absolute_time. Old kernels will leave the pointed to
4242+ * value alone.
4343+ */
4444+4545+.private_extern ___gettimeofday_with_mach
4646+4747+#if defined(__i386__)
4848+4949+LABEL(___gettimeofday)
5050+ pushl $0
5151+ pushl 12(%esp)
5252+ pushl 12(%esp)
5353+ calll ___gettimeofday_with_mach
5454+ addl $12, %esp
5555+ ret
5656+5757+LABEL(___gettimeofday_with_mach)
5858+ UNIX_SYSCALL_INT_NONAME(gettimeofday,0)
5959+ /*
6060+ * <rdar://problem/26410029>
6161+ * If eax is 0, we're on a new kernel and timeval was written by the kernel.
6262+ * Otherwise, eax:edx contains the timeval and we marshal into timeval.
6363+ */
6464+ cmp $0, %eax
6565+ je 2f
6666+ mov 4(%esp),%ecx
6767+ mov %eax,(%ecx)
6868+ mov %edx,4(%ecx)
6969+ xor %eax,%eax
7070+2:
7171+ ret
7272+7373+#elif defined(__x86_64__)
7474+7575+__SYSCALL(___gettimeofday_with_mach, gettimeofday, 3)
7676+7777+LABEL(___gettimeofday)
7878+ movq $0x0, %rdx // zero out third argument
7979+8080+ UNIX_SYSCALL_NONAME(gettimeofday,0,cerror_nocancel)
8181+ /*
8282+ * <rdar://problem/26410029>
8383+ * If rax is 0, we're on a new kernel and timeval was written by the kernel.
8484+ * Otherwise, rax:rdx contains the timeval and we marshal into timeval.
8585+ */
8686+ cmp $0, %rax
8787+ je 2f
8888+ movq %rax, (%rdi)
8989+ movl %edx, 8(%rdi)
9090+ xorl %eax, %eax
9191+2:
9292+ ret
9393+9494+#elif defined(__arm__)
9595+9696+__SYSCALL2(___gettimeofday_with_mach, gettimeofday, 3, cerror_nocancel)
9797+9898+.text
9999+.align 2
100100+.globl ___gettimeofday
101101+___gettimeofday:
102102+ mov r2, #0x0
103103+ SYSCALL_NONAME(gettimeofday, 3, cerror_nocancel)
104104+ bx lr
105105+106106+#elif defined(__arm64__)
107107+108108+__SYSCALL2(___gettimeofday_with_mach, gettimeofday, 3, cerror_nocancel)
109109+110110+.text
111111+.align 2
112112+.globl ___gettimeofday
113113+___gettimeofday:
114114+ movz x2, #0x0
115115+ SYSCALL_NONAME(gettimeofday, 3, cerror_nocancel)
116116+ ret
117117+118118+#else
119119+#error Unsupported architecture
120120+#endif
···11+/*
22+ * Copyright (c) 1999-2007 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. The rights granted to you under the License
1010+ * may not be used to create, or enable the creation or redistribution of,
1111+ * unlawful or unlicensed copies of an Apple operating system, or to
1212+ * circumvent, violate, or enable the circumvention or violation of, any
1313+ * terms of an Apple operating system software license agreement.
1414+ *
1515+ * Please obtain a copy of the License at
1616+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
1717+ *
1818+ * The Original Code and all software distributed under the License are
1919+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
2020+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
2121+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2222+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
2323+ * Please see the License for the specific language governing rights and
2424+ * limitations under the License.
2525+ *
2626+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
2727+ */
2828+2929+#include "SYS.h"
3030+3131+#if defined(__x86_64__)
3232+3333+__SYSCALL(___kdebug_trace_string, kdebug_trace_string, 3)
3434+3535+#elif defined(__i386__)
3636+3737+__SYSCALL_INT(___kdebug_trace_string, kdebug_trace_string, 3)
3838+3939+#elif defined(__arm__)
4040+4141+__SYSCALL(___kdebug_trace_string, kdebug_trace_string, 4)
4242+4343+#elif defined(__arm64__)
4444+4545+__SYSCALL(___kdebug_trace_string, kdebug_trace_string, 3)
4646+4747+#else
4848+#error Unsupported architecture
4949+#endif
+49
src/kernel/libsyscall/custom/__lseek.S
···11+/*
22+ * Copyright (c) 1999-2007 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. The rights granted to you under the License
1010+ * may not be used to create, or enable the creation or redistribution of,
1111+ * unlawful or unlicensed copies of an Apple operating system, or to
1212+ * circumvent, violate, or enable the circumvention or violation of, any
1313+ * terms of an Apple operating system software license agreement.
1414+ *
1515+ * Please obtain a copy of the License at
1616+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
1717+ *
1818+ * The Original Code and all software distributed under the License are
1919+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
2020+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
2121+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2222+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
2323+ * Please see the License for the specific language governing rights and
2424+ * limitations under the License.
2525+ *
2626+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
2727+ */
2828+2929+#include "SYS.h"
3030+3131+#if defined(__x86_64__)
3232+3333+__SYSCALL(___lseek, lseek, 3)
3434+3535+#elif defined(__i386__)
3636+3737+__SYSCALL_INT(___lseek, lseek, 3)
3838+3939+#elif defined(__arm__)
4040+4141+__SYSCALL(___lseek, lseek, 4)
4242+4343+#elif defined(__arm64__)
4444+4545+__SYSCALL(___lseek, lseek, 3)
4646+4747+#else
4848+#error Unsupported architecture
4949+#endif
+70
src/kernel/libsyscall/custom/__pipe.S
···11+/*
22+ * Copyright (c) 1999-2007 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. The rights granted to you under the License
1010+ * may not be used to create, or enable the creation or redistribution of,
1111+ * unlawful or unlicensed copies of an Apple operating system, or to
1212+ * circumvent, violate, or enable the circumvention or violation of, any
1313+ * terms of an Apple operating system software license agreement.
1414+ *
1515+ * Please obtain a copy of the License at
1616+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
1717+ *
1818+ * The Original Code and all software distributed under the License are
1919+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
2020+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
2121+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2222+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
2323+ * Please see the License for the specific language governing rights and
2424+ * limitations under the License.
2525+ *
2626+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
2727+ */
2828+/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. */
2929+3030+#include "SYS.h"
3131+3232+#if defined(__i386__)
3333+3434+PSEUDO_INT(___pipe, pipe, 0)
3535+ movl 4(%esp),%ecx
3636+ movl %eax,(%ecx)
3737+ movl %edx,4(%ecx)
3838+ xorl %eax,%eax
3939+ ret
4040+4141+#elif defined(__x86_64__)
4242+4343+PSEUDO(___pipe, pipe, 0, cerror_nocancel)
4444+ movl %eax, (%rdi)
4545+ movl %edx, 4(%rdi)
4646+ xorl %eax, %eax
4747+ ret
4848+4949+#elif defined(__arm__)
5050+5151+MI_ENTRY_POINT(___pipe)
5252+ mov r3,r0 // save fildes across syscall
5353+ SYSCALL_NONAME(pipe, 0, cerror_nocancel)
5454+ str r0, [r3, #0]
5555+ str r1, [r3, #4]
5656+ mov r0,#0
5757+ bx lr
5858+5959+#elif defined(__arm64__)
6060+6161+MI_ENTRY_POINT(___pipe)
6262+ mov x9, x0 // Stash FD array
6363+ SYSCALL_NONAME(pipe, 0, cerror_nocancel)
6464+ stp w0, w1, [x9] // Save results
6565+ mov x0, #0 // Success
6666+ ret // Done
6767+6868+#else
6969+#error Unsupported architecture
7070+#endif
+74
src/kernel/libsyscall/custom/__ptrace.S
···11+/*
22+ * Copyright (c) 1999-2007 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. The rights granted to you under the License
1010+ * may not be used to create, or enable the creation or redistribution of,
1111+ * unlawful or unlicensed copies of an Apple operating system, or to
1212+ * circumvent, violate, or enable the circumvention or violation of, any
1313+ * terms of an Apple operating system software license agreement.
1414+ *
1515+ * Please obtain a copy of the License at
1616+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
1717+ *
1818+ * The Original Code and all software distributed under the License are
1919+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
2020+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
2121+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2222+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
2323+ * Please see the License for the specific language governing rights and
2424+ * limitations under the License.
2525+ *
2626+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
2727+ */
2828+/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. */
2929+3030+#include "SYS.h"
3131+3232+#if defined(__i386__)
3333+3434+ .globl _errno
3535+3636+LEAF(___ptrace, 0)
3737+ xorl %eax,%eax
3838+ REG_TO_EXTERN(%eax,_errno)
3939+ UNIX_SYSCALL_NONAME(ptrace, 4, cerror)
4040+ ret
4141+4242+#elif defined(__x86_64__)
4343+4444+ .globl _errno
4545+4646+LEAF(___ptrace, 0)
4747+ xorq %rax,%rax
4848+ PICIFY(_errno)
4949+ movl %eax,(%r11)
5050+ UNIX_SYSCALL_NONAME(ptrace, 4, cerror)
5151+ ret
5252+5353+#elif defined(__arm__)
5454+5555+MI_ENTRY_POINT(___ptrace)
5656+ MI_GET_ADDRESS(ip,_errno)
5757+ str r8, [sp, #-4]!
5858+ mov r8, #0
5959+ str r8, [ip]
6060+ ldr r8, [sp], #4
6161+ SYSCALL_NONAME(ptrace, 4, cerror)
6262+ bx lr
6363+6464+#elif defined(__arm64__)
6565+6666+MI_ENTRY_POINT(___ptrace)
6767+ MI_GET_ADDRESS(x9,_errno)
6868+ str wzr, [x9]
6969+ SYSCALL_NONAME(ptrace, 4, cerror)
7070+ ret
7171+7272+#else
7373+#error Unsupported architecture
7474+#endif
+49
src/kernel/libsyscall/custom/__sigaltstack.S
···11+/*
22+ * Copyright (c) 1999-2007 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. The rights granted to you under the License
1010+ * may not be used to create, or enable the creation or redistribution of,
1111+ * unlawful or unlicensed copies of an Apple operating system, or to
1212+ * circumvent, violate, or enable the circumvention or violation of, any
1313+ * terms of an Apple operating system software license agreement.
1414+ *
1515+ * Please obtain a copy of the License at
1616+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
1717+ *
1818+ * The Original Code and all software distributed under the License are
1919+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
2020+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
2121+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2222+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
2323+ * Please see the License for the specific language governing rights and
2424+ * limitations under the License.
2525+ *
2626+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
2727+ */
2828+2929+#include "SYS.h"
3030+3131+#if defined(__x86_64__)
3232+3333+__SYSCALL(___sigaltstack, sigaltstack, 3)
3434+3535+#elif defined(__i386__)
3636+3737+__SYSCALL_INT(___sigaltstack, sigaltstack, 3)
3838+3939+#elif defined(__arm__)
4040+4141+__SYSCALL(___sigaltstack, sigaltstack, 3)
4242+4343+#elif defined(__arm64__)
4444+4545+__SYSCALL(___sigaltstack, sigaltstack, 3)
4646+4747+#else
4848+#error Unsupported architecture
4949+#endif
+49
src/kernel/libsyscall/custom/__sigreturn.S
···11+/*
22+ * Copyright (c) 1999-2007 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. The rights granted to you under the License
1010+ * may not be used to create, or enable the creation or redistribution of,
1111+ * unlawful or unlicensed copies of an Apple operating system, or to
1212+ * circumvent, violate, or enable the circumvention or violation of, any
1313+ * terms of an Apple operating system software license agreement.
1414+ *
1515+ * Please obtain a copy of the License at
1616+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
1717+ *
1818+ * The Original Code and all software distributed under the License are
1919+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
2020+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
2121+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2222+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
2323+ * Please see the License for the specific language governing rights and
2424+ * limitations under the License.
2525+ *
2626+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
2727+ */
2828+2929+#include "SYS.h"
3030+3131+#if defined(__x86_64__)
3232+3333+__SYSCALL(___sigreturn, sigreturn, 3)
3434+3535+#elif defined(__i386__)
3636+3737+__SYSCALL_INT(___sigreturn, sigreturn, 3)
3838+3939+#elif defined(__arm__)
4040+4141+__SYSCALL(___sigreturn, sigreturn, 3)
4242+4343+#elif defined(__arm64__)
4444+4545+__SYSCALL(___sigreturn, sigreturn, 3)
4646+4747+#else
4848+#error Unsupported architecture
4949+#endif
+73
src/kernel/libsyscall/custom/__syscall.S
···11+/*
22+ * Copyright (c) 1999-2007 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. The rights granted to you under the License
1010+ * may not be used to create, or enable the creation or redistribution of,
1111+ * unlawful or unlicensed copies of an Apple operating system, or to
1212+ * circumvent, violate, or enable the circumvention or violation of, any
1313+ * terms of an Apple operating system software license agreement.
1414+ *
1515+ * Please obtain a copy of the License at
1616+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
1717+ *
1818+ * The Original Code and all software distributed under the License are
1919+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
2020+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
2121+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2222+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
2323+ * Please see the License for the specific language governing rights and
2424+ * limitations under the License.
2525+ *
2626+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
2727+ */
2828+/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. */
2929+3030+#include "SYS.h"
3131+3232+#if defined(__i386__)
3333+3434+LEAF(___syscall, 0)
3535+ popl %ecx // ret addr
3636+ popl %eax // syscall number
3737+ pushl %ecx
3838+ UNIX_SYSCALL_TRAP
3939+ movl (%esp),%edx // add one element to stack so
4040+ pushl %ecx // caller "pop" will work
4141+ jnb 2f
4242+ BRANCH_EXTERN(tramp_cerror)
4343+2:
4444+END(___syscall)
4545+4646+#elif defined(__x86_64__)
4747+4848+// For x86-64, the kernel slides the argument list for us.
4949+// The number of arguments here is variable, but our macros ignore
5050+// that value anyway.
5151+__SYSCALL(___syscall, syscall, 0);
5252+5353+#elif defined(__arm__)
5454+5555+__SYSCALL(___syscall, syscall, 7)
5656+5757+#elif defined(__arm64__)
5858+5959+/*
6060+ * Ignore nominal number of arguments: just pop from stack and let the kernel
6161+ * interpret.
6262+ */
6363+#include <mach/arm64/asm.h>
6464+MI_ENTRY_POINT(___syscall)
6565+ ldp x1, x2, [sp]
6666+ ldp x3, x4, [sp, #16]
6767+ ldp x5, x6, [sp, #32]
6868+ ldr x7, [sp, #48]
6969+ DO_SYSCALL(SYS_syscall, cerror)
7070+ ret
7171+#else
7272+#error Unsupported architecture
7373+#endif
+47
src/kernel/libsyscall/custom/__thread_selfid.S
···11+/*
22+ * Copyright (c) 1999-2007 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. The rights granted to you under the License
1010+ * may not be used to create, or enable the creation or redistribution of,
1111+ * unlawful or unlicensed copies of an Apple operating system, or to
1212+ * circumvent, violate, or enable the circumvention or violation of, any
1313+ * terms of an Apple operating system software license agreement.
1414+ *
1515+ * Please obtain a copy of the License at
1616+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
1717+ *
1818+ * The Original Code and all software distributed under the License are
1919+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
2020+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
2121+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2222+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
2323+ * Please see the License for the specific language governing rights and
2424+ * limitations under the License.
2525+ *
2626+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
2727+ */
2828+2929+#include "SYS.h"
3030+3131+#if defined(__x86_64__)
3232+3333+__SYSCALL(___thread_selfid, thread_selfid, 0)
3434+3535+#elif defined(__i386__)
3636+3737+__SYSCALL_INT(___thread_selfid, thread_selfid, 0)
3838+3939+#elif defined(__arm__)
4040+4141+__SYSCALL(___thread_selfid, thread_selfid, 0)
4242+4343+#elif defined(__arm64__)
4444+4545+__SYSCALL(___thread_selfid, thread_selfid, 0)
4646+4747+#endif
+47
src/kernel/libsyscall/custom/__thread_selfusage.S
···11+/*
22+ * Copyright (c) 2014 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. The rights granted to you under the License
1010+ * may not be used to create, or enable the creation or redistribution of,
1111+ * unlawful or unlicensed copies of an Apple operating system, or to
1212+ * circumvent, violate, or enable the circumvention or violation of, any
1313+ * terms of an Apple operating system software license agreement.
1414+ *
1515+ * Please obtain a copy of the License at
1616+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
1717+ *
1818+ * The Original Code and all software distributed under the License are
1919+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
2020+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
2121+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2222+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
2323+ * Please see the License for the specific language governing rights and
2424+ * limitations under the License.
2525+ *
2626+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
2727+ */
2828+2929+#include "SYS.h"
3030+3131+#if defined(__x86_64__)
3232+3333+__SYSCALL(___thread_selfusage, thread_selfusage, 0)
3434+3535+#elif defined(__i386__)
3636+3737+__SYSCALL_INT(___thread_selfusage, thread_selfusage, 0)
3838+3939+#elif defined(__arm__)
4040+4141+__SYSCALL(___thread_selfusage, thread_selfusage, 0)
4242+4343+#elif defined(__arm64__)
4444+4545+__SYSCALL(___thread_selfusage, thread_selfusage, 0)
4646+4747+#endif
+248
src/kernel/libsyscall/custom/__vfork.S
···11+/*
22+ * Copyright (c) 1999-2007 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. The rights granted to you under the License
1010+ * may not be used to create, or enable the creation or redistribution of,
1111+ * unlawful or unlicensed copies of an Apple operating system, or to
1212+ * circumvent, violate, or enable the circumvention or violation of, any
1313+ * terms of an Apple operating system software license agreement.
1414+ *
1515+ * Please obtain a copy of the License at
1616+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
1717+ *
1818+ * The Original Code and all software distributed under the License are
1919+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
2020+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
2121+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2222+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
2323+ * Please see the License for the specific language governing rights and
2424+ * limitations under the License.
2525+ *
2626+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
2727+ */
2828+/* Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
2929+ *
3030+ * File: libc/ppc/sys/vfork.s
3131+ *
3232+ * HISTORY
3333+ * 23-Jun-1998 Umesh Vaishampayan (umeshv@apple.com)
3434+ * Created from fork.s
3535+ *
3636+ */
3737+3838+#include "SYS.h"
3939+4040+#if defined(__i386__)
4141+4242+#if defined(__DYNAMIC__)
4343+#define GET_CURRENT_PID PICIFY(__current_pid)
4444+4545+ NON_LAZY_STUB(__current_pid)
4646+#define __current_pid (%edx)
4747+#else
4848+#define GET_CURRENT_PID
4949+#endif
5050+5151+/*
5252+ * If __current_pid >= 0, we want to put a -1 in there
5353+ * otherwise we just decrement it
5454+ */
5555+5656+LEAF(___vfork, 0)
5757+ GET_CURRENT_PID
5858+ movl __current_pid, %eax
5959+0:
6060+ xorl %ecx, %ecx
6161+ testl %eax, %eax
6262+ cmovs %eax, %ecx
6363+ decl %ecx
6464+ lock
6565+ cmpxchgl %ecx, __current_pid
6666+ jne 0b
6767+ popl %ecx
6868+ #ifdef DARLING
6969+ movl $ SYS_vfork, %eax
7070+ call __darling_bsd_syscall
7171+ cmpl $0, %eax
7272+ jnb L1
7373+ #else
7474+ movl $(SYS_vfork), %eax // code for vfork -> eax
7575+ UNIX_SYSCALL_TRAP // do the system call
7676+ jnb L1 // jump if CF==0
7777+ #endif
7878+ GET_CURRENT_PID
7979+ lock
8080+ incl __current_pid
8181+ pushl %ecx
8282+ BRANCH_EXTERN(tramp_cerror)
8383+8484+L1:
8585+ testl %edx, %edx // CF=OF=0, ZF set if zero result
8686+ jz L2 // parent, since r1 == 0 in parent, 1 in child
8787+ xorl %eax, %eax // zero eax
8888+ jmp *%ecx
8989+9090+L2:
9191+ GET_CURRENT_PID
9292+ lock
9393+ incl __current_pid
9494+ jmp *%ecx
9595+9696+#elif defined(__x86_64__)
9797+9898+/*
9999+ * If __current_pid >= 0, we want to put a -1 in there
100100+ * otherwise we just decrement it
101101+ */
102102+103103+LEAF(___vfork, 0)
104104+ movq __current_pid@GOTPCREL(%rip), %rax
105105+ movl (%rax), %eax
106106+0:
107107+ xorl %ecx, %ecx
108108+ testl %eax, %eax
109109+ cmovs %eax, %ecx
110110+ subl $1, %ecx
111111+ movq __current_pid@GOTPCREL(%rip), %rdx
112112+ lock
113113+ cmpxchgl %ecx, (%rdx)
114114+ jne 0b
115115+ #ifdef DARLING
116116+ movl $ SYS_vfork, %eax
117117+ call __darling_bsd_syscall
118118+ cmpq $0, %rax
119119+ jnb L1
120120+ #else
121121+ popq %rdi // return address in %rdi
122122+ movq $ SYSCALL_CONSTRUCT_UNIX(SYS_vfork), %rax // code for vfork -> rax
123123+ UNIX_SYSCALL_TRAP // do the system call
124124+ jnb L1 // jump if CF==0
125125+ pushq %rdi // put return address back on stack for cerror
126126+ #endif
127127+ movq __current_pid@GOTPCREL(%rip), %rcx
128128+ lock
129129+ addl $1, (%rcx)
130130+ movq %rax, %rdi
131131+ BRANCH_EXTERN(_cerror)
132132+133133+L1:
134134+ testl %edx, %edx // CF=OF=0, ZF set if zero result
135135+ jz L2 // parent, since r1 == 0 in parent, 1 in child
136136+ xorq %rax, %rax // zero rax
137137+ jmp *%rdi
138138+139139+L2:
140140+ movq __current_pid@GOTPCREL(%rip), %rdx
141141+ lock
142142+ addl $1, (%rdx)
143143+ jmp *%rdi
144144+145145+#elif defined(__arm__)
146146+147147+#include <arm/arch.h>
148148+149149+ .globl cerror
150150+ MI_ENTRY_POINT(___vfork)
151151+152152+ MI_GET_ADDRESS(r3, __current_pid) // get address of __current_pid
153153+#ifdef _ARM_ARCH_6
154154+L0:
155155+ ldrex r1, [r3]
156156+ subs r1, r1, #1 // if __current_pid <= 0, decrement it
157157+ movpl r1, #-1 // otherwise put -1 in there
158158+ strex r2, r1, [r3]
159159+ cmp r2, #0
160160+ bne L0
161161+#else
162162+ mov r2, #0x80000000 // load "looking" value
163163+L0:
164164+ swp r1, r2, [r3] // look at the value, lock others out
165165+ cmp r1, r2 // anyone else trying to look?
166166+ beq L0 // yes, so wait our turn
167167+ subs r1, r1, #1 // if __current_pid <= 0, decrement it
168168+ movpl r1, #-1 // otherwise put -1 in there
169169+ str r1, [r3]
170170+#endif
171171+172172+ mov r1, #1 // prime results
173173+ mov r12, #SYS_vfork
174174+ swi #SWI_SYSCALL // make the syscall
175175+ bcs Lbotch // error?
176176+ cmp r1, #0 // parent (r1=0) or child(r1=1)
177177+ beq Lparent
178178+179179+ //child here...
180180+ mov r0, #0
181181+ bx lr // return
182182+183183+Lbotch:
184184+ MI_CALL_EXTERNAL(_cerror) // jump here on error
185185+ mov r0,#-1 // set the error
186186+ // reload values clobbered by cerror (so we can treat them as live in Lparent)
187187+ MI_GET_ADDRESS(r3, __current_pid) // get address of __current_pid
188188+#ifndef _ARM_ARCH_6
189189+ mov r2, #0x80000000 // load "looking" value
190190+#endif
191191+ // fall thru
192192+193193+Lparent:
194194+#ifdef _ARM_ARCH_6
195195+ ldrex r1, [r3]
196196+ add r1, r1, #1 // we're back, decrement vfork count
197197+ strex r2, r1, [r3]
198198+ cmp r2, #0
199199+ bne Lparent
200200+#else
201201+ swp r1, r2, [r3] // look at the value, lock others out
202202+ cmp r1, r2 // anyone else trying to look?
203203+ beq Lparent // yes, so wait our turn
204204+ add r1, r1, #1 // we're back, decrement vfork count
205205+ str r1, [r3]
206206+#endif
207207+208208+ bx lr // return
209209+210210+#elif defined(__arm64__)
211211+212212+ MI_ENTRY_POINT(___vfork)
213213+214214+ MI_GET_ADDRESS(x9, __current_pid)
215215+Ltry_set_vfork:
216216+ ldxr w10, [x9] // Get old current pid value (exclusive)
217217+ mov w11, #-1 // Will be -1 if current value is positive
218218+ subs w10, w10, #1 // Subtract one
219219+ csel w12, w11, w10, pl // If >= 0, set to -1, else set to (current - 1)
220220+ stxr w13, w12, [x9] // Attempt exclusive store to current pid
221221+ cbnz w13, Ltry_set_vfork // If store failed, retry
222222+223223+ // ARM sets r1 to 1 here. I don't see why.
224224+ mov w16, #SYS_vfork // Set syscall code
225225+ svc #SWI_SYSCALL
226226+ b.cs Lbotch
227227+ cbz w1, Lparent
228228+229229+ // Child
230230+ mov w0, #0
231231+ ret
232232+233233+ // Error case
234234+Lbotch:
235235+ bl _cerror // Update errno
236236+ mov w0, #-1 // Set return value
237237+ MI_GET_ADDRESS(x9, __current_pid) // Reload current pid address
238238+ // Fall through
239239+Lparent:
240240+ ldxr w10, [x9] // Exclusive load current pid value
241241+ add w10, w10, #1 // Increment (i.e. decrement vfork count)
242242+ stxr w11, w10, [x9] // Attempt exclusive store of updated vfork count
243243+ cbnz w11, Lparent // If exclusive store failed, retry
244244+ ret // Done, return
245245+246246+#else
247247+#error Unsupported architecture
248248+#endif
···11+/*
22+ * Copyright (c) 1999-2015 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. The rights granted to you under the License
1010+ * may not be used to create, or enable the creation or redistribution of,
1111+ * unlawful or unlicensed copies of an Apple operating system, or to
1212+ * circumvent, violate, or enable the circumvention or violation of, any
1313+ * terms of an Apple operating system software license agreement.
1414+ *
1515+ * Please obtain a copy of the License at
1616+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
1717+ *
1818+ * The Original Code and all software distributed under the License are
1919+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
2020+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
2121+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2222+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
2323+ * Please see the License for the specific language governing rights and
2424+ * limitations under the License.
2525+ *
2626+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
2727+ */
2828+/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved.
2929+ */
3030+3131+#include "SYS.h"
3232+3333+#if defined(__i386__)
3434+3535+/*
3636+ * i386 needs custom assembly to transform the return from syscalls
3737+ * into a proper stack for a function call out to cerror{,_nocancel}.
3838+ */
3939+4040+LABEL(tramp_cerror)
4141+ mov %esp, %edx
4242+ andl $0xfffffff0, %esp
4343+ subl $16, %esp
4444+ movl %edx, 4(%esp)
4545+ movl %eax, (%esp)
4646+ CALL_EXTERN(_cerror)
4747+ movl 4(%esp), %esp
4848+ ret
4949+5050+LABEL(tramp_cerror_nocancel)
5151+ mov %esp, %edx
5252+ andl $0xfffffff0, %esp
5353+ subl $16, %esp
5454+ movl %edx, 4(%esp)
5555+ movl %eax, (%esp)
5656+ CALL_EXTERN(_cerror_nocancel)
5757+ movl 4(%esp), %esp
5858+ ret
5959+6060+LABEL(__sysenter_trap)
6161+ popl %edx
6262+ movl %esp, %ecx
6363+ sysenter
6464+6565+ .globl _i386_get_ldt
6666+ ALIGN
6767+_i386_get_ldt:
6868+ movl $6,%eax
6969+ MACHDEP_SYSCALL_TRAP
7070+ jnb 2f
7171+ jmp tramp_cerror
7272+2: ret
7373+7474+7575+ .globl _i386_set_ldt
7676+ ALIGN
7777+_i386_set_ldt:
7878+ movl $5,%eax
7979+ MACHDEP_SYSCALL_TRAP
8080+ jnb 2f
8181+ jmp tramp_cerror
8282+2: ret
8383+8484+ ALIGN
8585+ .globl __thread_set_tsd_base
8686+__thread_set_tsd_base:
8787+ pushl 4(%esp)
8888+ pushl $0
8989+ movl $3,%eax
9090+ MACHDEP_SYSCALL_TRAP
9191+ addl $8,%esp
9292+ ret
9393+9494+#elif defined(__x86_64__)
9595+9696+ .globl _i386_get_ldt
9797+ ALIGN
9898+_i386_get_ldt:
9999+ movl $SYSCALL_CONSTRUCT_MDEP(6), %eax
100100+ MACHDEP_SYSCALL_TRAP
101101+ jnb 2f
102102+ movq %rax, %rdi
103103+ jmp _cerror
104104+2: ret
105105+106106+107107+ .globl _i386_set_ldt
108108+ ALIGN
109109+_i386_set_ldt:
110110+ movl $SYSCALL_CONSTRUCT_MDEP(5), %eax
111111+ MACHDEP_SYSCALL_TRAP
112112+ jnb 2f
113113+ movq %rax, %rdi
114114+ jmp _cerror
115115+2: ret
116116+117117+ ALIGN
118118+ .globl __thread_set_tsd_base
119119+__thread_set_tsd_base:
120120+ movl $0, %esi // 0 as the second argument
121121+ movl $ SYSCALL_CONSTRUCT_MDEP(3), %eax // Machine-dependent syscall number 3
122122+ MACHDEP_SYSCALL_TRAP
123123+ ret
124124+125125+#elif defined(__arm__)
126126+127127+ .align 2
128128+ .globl __thread_set_tsd_base
129129+__thread_set_tsd_base:
130130+ mov r3, #2
131131+ mov r12, #0x80000000
132132+ swi #SWI_SYSCALL
133133+ bx lr
134134+135135+#elif defined(__arm64__)
136136+137137+ .align 2
138138+ .globl __thread_set_tsd_base
139139+__thread_set_tsd_base:
140140+ mov x3, #2
141141+ mov x16, #0x80000000
142142+ svc #SWI_SYSCALL
143143+ ret
144144+145145+#else
146146+#error unknown architecture
147147+#endif
148148+149149+.subsections_via_symbols
···11+/*
22+ * Copyright (c) 2003-2007 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. The rights granted to you under the License
1010+ * may not be used to create, or enable the creation or redistribution of,
1111+ * unlawful or unlicensed copies of an Apple operating system, or to
1212+ * circumvent, violate, or enable the circumvention or violation of, any
1313+ * terms of an Apple operating system software license agreement.
1414+ *
1515+ * Please obtain a copy of the License at
1616+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
1717+ *
1818+ * The Original Code and all software distributed under the License are
1919+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
2020+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
2121+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2222+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
2323+ * Please see the License for the specific language governing rights and
2424+ * limitations under the License.
2525+ *
2626+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
2727+ */
2828+2929+#include <sys/appleapiopts.h>
3030+#include <machine/cpu_capabilities.h>
3131+3232+#if defined(__i386__)
3333+3434+/* return mach_absolute_time in %edx:%eax
3535+ *
3636+ * The algorithm we use is:
3737+ *
3838+ * ns = ((((rdtsc - rnt_tsc_base)<<rnt_shift)*rnt_tsc_scale) / 2**32) + rnt_ns_base;
3939+ *
4040+ * rnt_shift, a constant computed during initialization, is the smallest value for which:
4141+ *
4242+ * (tscFreq << rnt_shift) > SLOW_TSC_THRESHOLD
4343+ *
4444+ * Where SLOW_TSC_THRESHOLD is about 10e9. Since most processor's tscFreq is greater
4545+ * than 1GHz, rnt_shift is usually 0. rnt_tsc_scale is also a 32-bit constant:
4646+ *
4747+ * rnt_tsc_scale = (10e9 * 2**32) / (tscFreq << rnt_shift);
4848+ */
4949+5050+ .globl _mach_absolute_time
5151+_mach_absolute_time:
5252+ pushl %ebp
5353+ movl %esp,%ebp
5454+ pushl %esi
5555+ pushl %ebx
5656+5757+0:
5858+ movl _COMM_PAGE_NT_GENERATION,%esi /* get generation (0 if being changed) */
5959+ testl %esi,%esi /* if being updated, loop until stable */
6060+ jz 0b
6161+6262+ lfence
6363+ rdtsc /* get TSC in %edx:%eax */
6464+ lfence
6565+6666+ subl _COMM_PAGE_NT_TSC_BASE,%eax
6767+ sbbl _COMM_PAGE_NT_TSC_BASE+4,%edx
6868+6969+ /*
7070+ * Prior to supporting "slow" processors, xnu always set _NT_SHIFT to 32.
7171+ * Now it defaults to 0, unless the processor is slow. The shifts
7272+ * below implicitly mask the count down to 5 bits, handling either default.
7373+ */
7474+ movl _COMM_PAGE_NT_SHIFT,%ecx
7575+ shldl %cl,%eax,%edx /* shift %edx left, filling in from %eax */
7676+ shll %cl,%eax /* finish shifting %edx:%eax left by _COMM_PAGE_NT_SHIFT bits */
7777+7878+ movl _COMM_PAGE_NT_SCALE,%ecx
7979+8080+ movl %edx,%ebx
8181+ mull %ecx
8282+ movl %ebx,%eax
8383+ movl %edx,%ebx
8484+ mull %ecx
8585+ addl %ebx,%eax
8686+ adcl $0,%edx
8787+8888+ addl _COMM_PAGE_NT_NS_BASE,%eax
8989+ adcl _COMM_PAGE_NT_NS_BASE+4,%edx
9090+9191+ cmpl _COMM_PAGE_NT_GENERATION,%esi /* have the parameters changed? */
9292+ jne 0b /* yes, loop until stable */
9393+9494+ popl %ebx
9595+ popl %esi
9696+ popl %ebp
9797+ ret
9898+9999+#elif defined(__x86_64__)
100100+101101+/*
102102+ * 64-bit version _mach_absolute_time. We return the 64-bit nanotime in %rax.
103103+ *
104104+ * The algorithm we use is:
105105+ *
106106+ * ns = ((((rdtsc - rnt_tsc_base)<<rnt_shift)*rnt_tsc_scale) / 2**32) + rnt_ns_base;
107107+ *
108108+ * rnt_shift, a constant computed during initialization, is the smallest value for which:
109109+ *
110110+ * tscFreq << rnt_shift) > SLOW_TSC_THRESHOLD
111111+ *
112112+ * Where SLOW_TSC_THRESHOLD is about 10e9. Since most processor's tscFreqs are greater
113113+ * than 1GHz, rnt_shift is usually 0. rnt_tsc_scale is also a 32-bit constant:
114114+ *
115115+ * rnt_tsc_scale = (10e9 * 2**32) / (tscFreq << rnt_shift);
116116+ *
117117+ */
118118+ .globl _mach_absolute_time
119119+_mach_absolute_time:
120120+ pushq %rbp // set up a frame for backtraces
121121+ movq %rsp,%rbp
122122+ movq $(_COMM_PAGE_TIME_DATA_START),%rsi
123123+1:
124124+ movl _NT_GENERATION(%rsi),%r8d // get generation
125125+ testl %r8d,%r8d // if 0, data is being changed...
126126+ jz 1b // ...so loop until stable
127127+ lfence
128128+ rdtsc // edx:eax := tsc
129129+ lfence
130130+ shlq $32,%rdx // rax := ((edx << 32) | eax), ie 64-bit tsc
131131+ orq %rdx,%rax
132132+133133+ /*
134134+ * Prior to supporting "slow" processors, xnu always set _NT_SHIFT to 32.
135135+ * Now it defaults to 0, unless the processor is slow. In order to maintain
136136+ * compatibility with both old and new versions of xnu, we mask the shift
137137+ * down to 0x1F, which maps the old default (32) into the new default (0).
138138+ */
139139+ movl _NT_SHIFT(%rsi),%ecx
140140+ andl $0x1F,%ecx // *** remove this line once 10.9 is GM ***
141141+ subq _NT_TSC_BASE(%rsi), %rax // rax := (tsc - base_tsc)
142142+ shlq %cl,%rax // rax := (tsc - base_tsc) << NT_SHIFT
143143+ movl _NT_SCALE(%rsi),%ecx
144144+ mulq %rcx // rdx:rax := ((tsc - base_tsc)<<shift) * scale
145145+ shrdq $32,%rdx,%rax // divide by 2**32
146146+ addq _NT_NS_BASE(%rsi),%rax // (((tsc - base_tsc) * scale) >> 32) + ns_base
147147+148148+ cmpl _NT_GENERATION(%rsi),%r8d // did the data change during computation?
149149+ jne 1b
150150+ popq %rbp
151151+ ret
152152+153153+#elif defined(__arm__)
154154+155155+#include <mach/arm/syscall_sw.h>
156156+157157+/*
158158+ * If userspace access to the timebase is supported (indicated through the commpage),
159159+ * directly reads the timebase and uses it and the current timebase offset (also in
160160+ * the commpage, and updated whenever the system wakes from sleep) to construct the
161161+ * current time value; otherwise, traps to the kernel to handle this.
162162+ *
163163+ * If we do this in user mode, there are two cases where we may need to redrive the
164164+ * read. We do 3 reads (high-low-high) to the timebase, because we only have a
165165+ * 32-bit interface to it (despite the use of mrrc). If the high bits change, we
166166+ * need to reread the register (as our returned value could otherwise be off by
167167+ * 2^32 mach absolute time units).
168168+ *
169169+ * We do two reads of the offset, before and after the register reads. If the offset
170170+ * changes, we have gone to sleep in the midst of doing a read. This case should be
171171+ * exceedingly rare, but could result in a terribly inaccurate result, so we need
172172+ * to get a fresh timebase value.
173173+ */
174174+ .text
175175+ .align 2
176176+ .globl _mach_absolute_time
177177+_mach_absolute_time:
178178+ movw ip, #((_COMM_PAGE_TIMEBASE_OFFSET) & 0x0000FFFF)
179179+ movt ip, #(((_COMM_PAGE_TIMEBASE_OFFSET) >> 16) & 0x0000FFFF)
180180+ ldrb r0, [ip, #((_COMM_PAGE_USER_TIMEBASE) - (_COMM_PAGE_TIMEBASE_OFFSET))]
181181+ cmp r0, #USER_TIMEBASE_NONE // Are userspace reads supported?
182182+ beq _mach_absolute_time_kernel // If not, go to the kernel
183183+ isb // Prevent speculation on CNTPCT across calls
184184+ // (see ARMV7C.b section B8.1.2, ARMv8 section D6.1.2)
185185+ push {r4, r5, r7, lr} // Push a frame
186186+ add r7, sp, #8
187187+L_mach_absolute_time_user:
188188+ ldr r4, [ip] // Load offset low bits
189189+ ldr r5, [ip, #4] // Load offset high bits
190190+ mrrc p15, 0, r3, r1, c14 // Read timebase high to r1
191191+ mrrc p15, 0, r0, r3, c14 // Read timebase low to r0
192192+ mrrc p15, 0, r3, r2, c14 // Read timebase high to r2
193193+ cmp r1, r2 // Did the high bits change?
194194+ bne L_mach_absolute_time_user // Loop if timebase high changed
195195+ ldr r2, [ip] // Load offset low bits
196196+ ldr r3, [ip, #4] // Load offset high bits
197197+ eor r4, r2 // Compare our offset values...
198198+ eor r5, r3
199199+ orrs r5, r4
200200+ bne L_mach_absolute_time_user // If they changed, try again
201201+ adds r0, r0, r2 // Construct mach_absolute_time
202202+ adcs r1, r1, r3
203203+ pop {r4, r5, r7, pc} // Pop the frame
204204+205205+ .text
206206+ .align 2
207207+ .globl _mach_absolute_time_kernel
208208+_mach_absolute_time_kernel:
209209+ mov r12, #-3 // Load the magic MAT number
210210+ swi #SWI_SYSCALL
211211+ bx lr
212212+213213+ .text
214214+ .align 2
215215+ .globl _mach_continuous_time_kernel
216216+_mach_continuous_time_kernel:
217217+ mov r12, #-4 // Load the magic MCT number
218218+ swi #SWI_SYSCALL
219219+ bx lr
220220+221221+#elif defined(__arm64__)
222222+223223+#include <mach/arm/syscall_sw.h>
224224+225225+/*
226226+ * If userspace access to the timebase is supported (indicated through the commpage),
227227+ * directly reads the timebase and uses it and the current timebase offset (also in
228228+ * the commpage, and updated whenever the system wakes from sleep) to construct the
229229+ * current time value; otherwise, traps to the kernel to handle this.
230230+ *
231231+ * If we do this in user mode, we do two reads of the offset, before and after we
232232+ * read the register. If the offset changes, we have gone to sleep in the midst of
233233+ * doing a read. This case should be exceedingly rare, but could result in a terribly
234234+ * inaccurate result, so we need to get a fresh timebase value.
235235+ */
236236+ .text
237237+ .align 2
238238+ .globl _mach_absolute_time
239239+_mach_absolute_time:
240240+ movk x3, #(((_COMM_PAGE_TIMEBASE_OFFSET) >> 48) & 0x000000000000FFFF), lsl #48
241241+ movk x3, #(((_COMM_PAGE_TIMEBASE_OFFSET) >> 32) & 0x000000000000FFFF), lsl #32
242242+ movk x3, #(((_COMM_PAGE_TIMEBASE_OFFSET) >> 16) & 0x000000000000FFFF), lsl #16
243243+ movk x3, #((_COMM_PAGE_TIMEBASE_OFFSET) & 0x000000000000FFFF)
244244+ ldrb w2, [x3, #((_COMM_PAGE_USER_TIMEBASE) - (_COMM_PAGE_TIMEBASE_OFFSET))]
245245+ cmp x2, #USER_TIMEBASE_NONE // Are userspace reads supported?
246246+ b.eq _mach_absolute_time_kernel // If not, go to the kernel
247247+ isb // Prevent speculation on CNTPCT across calls
248248+ // (see ARMV7C.b section B8.1.2, ARMv8 section D6.1.2)
249249+L_mach_absolute_time_user:
250250+ ldr x1, [x3] // Load the offset
251251+ mrs x0, CNTPCT_EL0 // Read the timebase
252252+ ldr x2, [x3] // Load the offset
253253+ cmp x1, x2 // Compare our offset values...
254254+ b.ne L_mach_absolute_time_user // If they changed, try again
255255+ add x0, x0, x1 // Construct mach_absolute_time
256256+ ret
257257+258258+259259+260260+ .text
261261+ .align 2
262262+ .globl _mach_absolute_time_kernel
263263+_mach_absolute_time_kernel:
264264+ mov w16, #-3 // Load the magic MAT number
265265+ svc #SWI_SYSCALL
266266+ ret
267267+268268+ .text
269269+ .align 2
270270+ .globl _mach_continuous_time_kernel
271271+_mach_continuous_time_kernel:
272272+ mov w16, #-4 // Load the magic MCT number
273273+ svc #SWI_SYSCALL
274274+ ret
275275+276276+#else
277277+#error Unsupported architecture
278278+#endif
···11+/*
22+ * Copyright (c) 2003-2007 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. The rights granted to you under the License
1010+ * may not be used to create, or enable the creation or redistribution of,
1111+ * unlawful or unlicensed copies of an Apple operating system, or to
1212+ * circumvent, violate, or enable the circumvention or violation of, any
1313+ * terms of an Apple operating system software license agreement.
1414+ *
1515+ * Please obtain a copy of the License at
1616+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
1717+ *
1818+ * The Original Code and all software distributed under the License are
1919+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
2020+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
2121+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2222+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
2323+ * Please see the License for the specific language governing rights and
2424+ * limitations under the License.
2525+ *
2626+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
2727+ */
2828+2929+#include <sys/appleapiopts.h>
3030+#include <machine/cpu_capabilities.h>
3131+3232+#if defined(__arm__)
3333+3434+ .text
3535+ .align 2
3636+ .globl _mach_approximate_time
3737+_mach_approximate_time:
3838+3939+ movw r0, #((_COMM_PAGE_APPROX_TIME_SUPPORTED>>0)&0x0FFFF)
4040+ movt r0, #((_COMM_PAGE_APPROX_TIME_SUPPORTED>>16)&0x0FFFF)
4141+ ldrb r0, [r0] // load COMM_PAGE_APPROX_TIME_SUPPORTED
4242+ cmp r0, #1 // check if approx time is supported
4343+4444+ bne _mach_absolute_time // if not supported, fall through to
4545+ // absolute_time
4646+4747+ movw r2, #((_COMM_PAGE_APPROX_TIME>>0)&0x0FFFF)
4848+ movt r2, #((_COMM_PAGE_APPROX_TIME>>16)&0x0FFFF)
4949+5050+ // at this point, r2->COMM_PAGE_APPROX_TIME, which is a 64-bit value.
5151+ // Since this is a 32-bit architecture, and the commpage is readonly,
5252+ // there is no "guaranteed" atomic way to read all 64-bits with
5353+ // hardware protection. Even the ldrd instruction is not guaranteed to
5454+ // complete atomically. The solution is to use a 32-bit high/low/high
5555+ // read with a consistency check on the high bits. To further
5656+ // complicate things, reading the same location in memory back to back
5757+ // could trigger a predictive read, which would defeat the purpose of
5858+ // doing the consistency check so we insert a data memory barrier to
5959+ // prevent this.
6060+_consistency_check:
6161+ ldr r1, [r2,#4] // load high
6262+ ldr r0, [r2] // load low
6363+ dsb // avoid predictive reads that could
6464+ // be invalid if interrupted
6565+ ldr r3, [r2,#4] // load high again
6666+ cmp r1, r3 // check that high1 == high2
6767+ bne _consistency_check // try again if not
6868+ bx lr
6969+7070+#elif defined(__i386__)
7171+7272+ .text
7373+ .align 4, 0x90
7474+ .globl _mach_approximate_time
7575+_mach_approximate_time:
7676+ pushl %ebp // push a frame
7777+ movl %esp, %ebp
7878+ cmpb $0, _COMM_PAGE_APPROX_TIME_SUPPORTED // check commpage
7979+ // "is supported" flag.
8080+ je _approx_time_not_supported // if zero, fall through to
8181+ // absolute_time
8282+ // note the comment above for 32-bit ARM applies equally to 32-bit i386.
8383+ .align 4, 0x90
8484+_approx_time_consistency_check:
8585+ movl _COMM_PAGE_APPROX_TIME+4, %edx // load high
8686+ movl _COMM_PAGE_APPROX_TIME, %eax // load low
8787+ lfence // avoid predictive reads that
8888+ // could be invalid if
8989+ // interrupted
9090+ cmpl _COMM_PAGE_APPROX_TIME+4, %edx // load high and check if equal
9191+ // to the first read
9292+ jne _approx_time_consistency_check // if not, try again.
9393+ popl %ebp
9494+ ret
9595+9696+_approx_time_not_supported:
9797+ popl %ebp
9898+ jmp _mach_absolute_time
9999+100100+#endif
···11+/*
22+ * Copyright (c) 2017 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. The rights granted to you under the License
1010+ * may not be used to create, or enable the creation or redistribution of,
1111+ * unlawful or unlicensed copies of an Apple operating system, or to
1212+ * circumvent, violate, or enable the circumvention or violation of, any
1313+ * terms of an Apple operating system software license agreement.
1414+ *
1515+ * Please obtain a copy of the License at
1616+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
1717+ *
1818+ * The Original Code and all software distributed under the License are
1919+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
2020+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
2121+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2222+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
2323+ * Please see the License for the specific language governing rights and
2424+ * limitations under the License.
2525+ *
2626+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
2727+ */
2828+2929+/*
3030+ * extern int cpu_copy_in_cksum(const void *src, void *dst, uint32_t len,
3131+ * uint32_t initial_sum);
3232+ *
3333+ * input :
3434+ * src : source starting address
3535+ * dst : destination starting address
3636+ * len : byte stream length
3737+ * initial_sum : 32bit sum
3838+ *
3939+ * output :
4040+ * the source byte stream is copied into the destination buffer
4141+ * the function returns the final 16bit checksum
4242+ */
4343+
···11+/*
22+ * Copyright (c) 2017 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. The rights granted to you under the License
1010+ * may not be used to create, or enable the creation or redistribution of,
1111+ * unlawful or unlicensed copies of an Apple operating system, or to
1212+ * circumvent, violate, or enable the circumvention or violation of, any
1313+ * terms of an Apple operating system software license agreement.
1414+ *
1515+ * Please obtain a copy of the License at
1616+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
1717+ *
1818+ * The Original Code and all software distributed under the License are
1919+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
2020+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
2121+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2222+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
2323+ * Please see the License for the specific language governing rights and
2424+ * limitations under the License.
2525+ *
2626+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
2727+ */
2828+2929+/*
3030+ * extern uint32_t os_cpu_in_cksum(const void *data, uint32_t len,
3131+ * uint32_t initial_sum);
3232+ *
3333+ * input :
3434+ * data : starting address
3535+ * len : byte stream length
3636+ * initial_sum : 32-bit sum
3737+ *
3838+ * output :
3939+ * This function returns the partial 16-bit checksum accumulated in
4040+ * a 32-bit variable (withouth 1's complement); caller is responsible
4141+ * for folding the 32-bit sum into 16-bit and performinng the 1's
4242+ * complement if applicable
4343+ */
4444+
+206
src/kernel/libsyscall/wrappers/varargs_wrappers.S
···11+/*
22+ * Copyright (c) 2011-2013 Apple Inc. All rights reserved.
33+ *
44+ * @APPLE_LICENSE_HEADER_START@
55+ *
66+ * This file contains Original Code and/or Modifications of Original Code
77+ * as defined in and that are subject to the Apple Public Source License
88+ * Version 2.0 (the 'License'). You may not use this file except in
99+ * compliance with the License. Please obtain a copy of the License at
1010+ * http://www.opensource.apple.com/apsl/ and read it before using this
1111+ * file.
1212+ *
1313+ * The Original Code and all software distributed under the License are
1414+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1515+ * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
1616+ * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
1717+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
1818+ * Please see the License for the specific language governing rights and
1919+ * limitations under the License.
2020+ *
2121+ * @APPLE_LICENSE_HEADER_END@
2222+ */
2323+2424+#ifdef __arm64__
2525+2626+#include "../custom/SYS.h"
2727+#include <mach/arm64/asm.h>
2828+2929+/*
3030+ * Stubs are to handle the ARM64 ABI for variadic functions'
3131+ * not matching the ABI used by the system call handler.
3232+ */
3333+3434+/*
3535+ * sem_t* sem_open(const char *name, int oflag, ...);
3636+ * sem_t* __sem_open(const char *name, int oflag, int mode, int value);
3737+ */
3838+MI_ENTRY_POINT(_sem_open)
3939+ ARM64_STACK_PROLOG
4040+ PUSH_FRAME
4141+#if __LP64__
4242+ ldp x2, x3, [fp, #16]
4343+#else
4444+ ldp w2, w3, [fp, #16]
4545+#endif
4646+ MI_CALL_EXTERNAL(___sem_open)
4747+#if !__LP64__
4848+ /* xnu returns a 64-bit '-1' on failure, but pointers must have the high
4949+ * 32-bits set to zero. The following instruction is equivalent to
5050+ * masking off the top 32-bits.
5151+ */
5252+ mov w0, w0
5353+#endif
5454+ POP_FRAME
5555+ ARM64_STACK_EPILOG
5656+5757+/*
5858+ * int open(const char *name, int oflag, ...);
5959+ * int __open(const char *name, int oflag, int mode, int value);
6060+ */
6161+MI_ENTRY_POINT(_open)
6262+ ARM64_STACK_PROLOG
6363+ PUSH_FRAME
6464+#if __LP64__
6565+ ldr x2, [fp, #16]
6666+#else
6767+ ldr w2, [fp, #16]
6868+#endif
6969+ MI_CALL_EXTERNAL(___open)
7070+ POP_FRAME
7171+ ARM64_STACK_EPILOG
7272+7373+/*
7474+ * int open_nocancel(const char *name, int oflag, ...);
7575+ * int __open_nocancel(const char *name, int oflag, int mode);
7676+ */
7777+MI_ENTRY_POINT(_open$NOCANCEL)
7878+ ARM64_STACK_PROLOG
7979+ PUSH_FRAME
8080+#if __LP64__
8181+ ldr x2, [fp, #16]
8282+#else
8383+ ldr w2, [fp, #16]
8484+#endif
8585+ MI_CALL_EXTERNAL(___open_nocancel)
8686+ POP_FRAME
8787+ ARM64_STACK_EPILOG
8888+8989+/*
9090+ * int openat(int fd,const char *name, int oflag, ...);
9191+ * int __openat(int fd, const char *name, int oflag, int mode, int value);
9292+ */
9393+MI_ENTRY_POINT(_openat)
9494+ ARM64_STACK_PROLOG
9595+ PUSH_FRAME
9696+#if __LP64__
9797+ ldr x3, [fp, #16]
9898+#else
9999+ ldr w3, [fp, #16]
100100+#endif
101101+ MI_CALL_EXTERNAL(___openat)
102102+ POP_FRAME
103103+ ARM64_STACK_EPILOG
104104+105105+/*
106106+ * int openat_nocancel(int fd, const char *name, int oflag, ...);
107107+ * int __openat_nocancel(int fd, const char *name, int oflag, int mode);
108108+ */
109109+MI_ENTRY_POINT(_openat$NOCANCEL)
110110+ ARM64_STACK_PROLOG
111111+ PUSH_FRAME
112112+#if __LP64__
113113+ ldr x3, [fp, #16]
114114+#else
115115+ ldr w3, [fp, #16]
116116+#endif
117117+ MI_CALL_EXTERNAL(___openat_nocancel)
118118+ POP_FRAME
119119+ ARM64_STACK_EPILOG
120120+121121+/*
122122+ * int shm_open(const char *, int, ...);
123123+ * int __shm_open(const char*, int oflag, int mode);
124124+ */
125125+MI_ENTRY_POINT(_shm_open)
126126+ ARM64_STACK_PROLOG
127127+ PUSH_FRAME
128128+#if __LP64__
129129+ ldr x2, [fp, #16]
130130+#else
131131+ ldr w2, [fp, #16]
132132+#endif
133133+ MI_CALL_EXTERNAL(___shm_open)
134134+ POP_FRAME
135135+ ARM64_STACK_EPILOG
136136+137137+/*
138138+ * int msgsys(int, ...);
139139+ * int __msgsys(int which, int a2, int a3, int a4, int a5);
140140+ */
141141+MI_ENTRY_POINT(_msgsys)
142142+ ARM64_STACK_PROLOG
143143+ PUSH_FRAME
144144+#if __LP64__
145145+ ldp x1, x2, [fp, #16]
146146+ ldp x3, x4, [fp, #32]
147147+#else
148148+ ldp w1, w2, [fp, #16]
149149+ ldp w3, w4, [fp, #24]
150150+#endif
151151+ MI_CALL_EXTERNAL(___msgsys)
152152+ POP_FRAME
153153+154154+/*
155155+ * int semsys(int, ...);
156156+ * int __semsys(int which, int a2, int a3, int a4, int a5);
157157+ */
158158+MI_ENTRY_POINT(_semsys)
159159+ ARM64_STACK_PROLOG
160160+ PUSH_FRAME
161161+#if __LP64__
162162+ ldp x1, x2, [fp, #16]
163163+ ldp x3, x4, [fp, #32]
164164+#else
165165+ ldp w1, w2, [fp, #16]
166166+ ldp w3, w4, [fp, #24]
167167+#endif
168168+ MI_CALL_EXTERNAL(___semsys)
169169+ POP_FRAME
170170+ ARM64_STACK_EPILOG
171171+172172+/*
173173+ * int semctl(int, int, int, ...);
174174+ * int __semctl(int semid, int semnum, int cmd, semun_t arg);
175175+ */
176176+ MI_ENTRY_POINT(_semctl)
177177+ ARM64_STACK_PROLOG
178178+ PUSH_FRAME
179179+#if __LP64__
180180+ ldr x3, [fp, #16]
181181+#else
182182+ ldr w3, [fp, #16]
183183+#endif
184184+ MI_CALL_EXTERNAL(___semctl)
185185+ POP_FRAME
186186+ ARM64_STACK_EPILOG
187187+188188+/*
189189+ * int shmsys(int, ...);
190190+ * int __shmsys(int which, int a2, int a3, int a4);
191191+ */
192192+ MI_ENTRY_POINT(_shmsys)
193193+ ARM64_STACK_PROLOG
194194+ PUSH_FRAME
195195+#if __LP64__
196196+ ldp x1, x2, [fp, #16]
197197+ ldr x3, [fp, #32]
198198+#else
199199+ ldp w1, w2, [fp, #16]
200200+ ldr w3, [fp, #24]
201201+#endif
202202+ MI_CALL_EXTERNAL(___shmsys)
203203+ POP_FRAME
204204+ ARM64_STACK_EPILOG
205205+206206+#endif /* defined(__arm64__) */