1/* 2 * Copyright (c) 1999-2011 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/* Copyright (c) 1992 NeXT Computer, Inc. All rights reserved. 29 */ 30 31#include "SYS.h" 32 33#if defined(__i386__) 34 35 .globl _errno 36 37LABEL(cerror) 38 movl $0,%ecx 39 jmp 1f 40LABEL(cerror_nocancel) 41 movl $1,%ecx 421: REG_TO_EXTERN(%eax, _errno) 43 mov %esp,%edx 44 andl $0xfffffff0,%esp 45 subl $16,%esp 46 movl %edx,8(%esp) 47 movl %ecx,4(%esp) 48 movl %eax,(%esp) 49 CALL_EXTERN(_cthread_set_errno_self) 50 movl 8(%esp),%esp 51 movl $-1,%eax 52 movl $-1,%edx /* in case a 64-bit value is returned */ 53 ret 54 55LABEL(__sysenter_trap) 56 popl %edx 57 movl %esp, %ecx 58 sysenter 59 60#elif defined(__x86_64__) 61 62 .globl _errno 63 64LABEL(cerror) 65 /* cancelable syscall, for arg1 to _cthread_set_errno_self */ 66 movq $0,%rsi 67 jmp 1f 68LABEL(cerror_nocancel) 69 /* non-cancelable, see above. */ 70 movq $1,%rsi 711: PICIFY(_errno) /* address -> %r11 */ 72 movl %eax,(%r11) 73 mov %rsp,%rdx 74 andq $-16,%rsp 75 subq $16,%rsp 76 // Preserve the original stack 77 movq %rdx,(%rsp) 78 movq %rax,%rdi 79 CALL_EXTERN(_cthread_set_errno_self) 80 // Restore the original stack 81 movq (%rsp),%rsp 82 movq $-1,%rax 83 movq $-1,%rdx /* in case a 128-bit value is returned */ 84 ret 85 86#elif defined(__arm__) 87 88 .globl _errno 89 90MI_ENTRY_POINT(cerror) 91 stmfd sp!, {r7, lr} 92 mov r7, sp 93 MI_GET_ADDRESS(r3,_errno) 94 str r0, [r3] 95 MI_CALL_EXTERNAL(_cthread_set_errno_self) 96 mov r0, #-1 97 mov r1, #-1 98 ldmfd sp!, {r7, pc} 99 100#else 101#error Unsupported architecture 102#endif 103 104#if defined(__i386__) || defined(__x86_64__) 105 106 .globl _i386_get_ldt 107 ALIGN 108_i386_get_ldt: 109 movl $6,%eax 110 MACHDEP_SYSCALL_TRAP 111 jnb 2f 112 jmp cerror 1132: ret 114 115 116 .globl _i386_set_ldt 117 ALIGN 118_i386_set_ldt: 119 movl $5,%eax 120 MACHDEP_SYSCALL_TRAP 121 jnb 2f 122 jmp cerror 1232: ret 124 125#endif 126