1 /* -*- mode: C++; c-basic-offset: 4; tab-width: 4 -*-
3 * Copyright (c) 2004-2009 Apple Inc. All rights reserved.
5 * @APPLE_LICENSE_HEADER_START@
7 * This file contains Original Code and/or Modifications of Original Code
8 * as defined in and that are subject to the Apple Public Source License
9 * Version 2.0 (the 'License'). You may not use this file except in
10 * compliance with the License. Please obtain a copy of the License at
11 * http://www.opensource.apple.com/apsl/ and read it before using this
14 * The Original Code and all software distributed under the License are
15 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
19 * Please see the License for the specific language governing rights and
20 * limitations under the License.
22 * @APPLE_LICENSE_HEADER_END@
33 // from _simple.h in libc
34 typedef struct _SIMPLE
* _SIMPLE_STRING
;
35 extern void _simple_vdprintf(int __fd
, const char *__fmt
, va_list __ap
);
36 extern void _simple_dprintf(int __fd
, const char *__fmt
, ...);
37 extern _SIMPLE_STRING
_simple_salloc(void);
38 extern int _simple_vsprintf(_SIMPLE_STRING __b
, const char *__fmt
, va_list __ap
);
39 extern void _simple_sfree(_SIMPLE_STRING __b
);
40 extern char * _simple_string(_SIMPLE_STRING __b
);
42 // dyld::log(const char* format, ...)
43 extern void _ZN4dyld3logEPKcz(const char*, ...);
45 // dyld::halt(const char* msg);
46 extern void _ZN4dyld4haltEPKc(const char* msg
) __attribute__((noreturn
));
49 // abort called by C++ unwinding code
52 _ZN4dyld4haltEPKc("dyld calling abort()\n");
55 // std::terminate called by C++ unwinding code
56 void _ZSt9terminatev()
58 _ZN4dyld4haltEPKc("dyld std::terminate()\n");
61 // std::unexpected called by C++ unwinding code
62 void _ZSt10unexpectedv()
64 _ZN4dyld4haltEPKc("dyld std::unexpected()\n");
67 // __cxxabiv1::__terminate(void (*)()) called to terminate process
68 void _ZN10__cxxabiv111__terminateEPFvvE()
70 _ZN4dyld4haltEPKc("dyld std::__terminate()\n");
73 // __cxxabiv1::__unexpected(void (*)()) called to terminate process
74 void _ZN10__cxxabiv112__unexpectedEPFvvE()
76 _ZN4dyld4haltEPKc("dyld std::__unexpected()\n");
79 // __cxxabiv1::__terminate_handler
80 void* _ZN10__cxxabiv119__terminate_handlerE
= &_ZSt9terminatev
;
82 // __cxxabiv1::__unexpected_handler
83 void* _ZN10__cxxabiv120__unexpected_handlerE
= &_ZSt10unexpectedv
;
86 void __assert_rtn(const char* func
, const char* file
, int line
, const char* failedexpr
)
89 _ZN4dyld3logEPKcz("Assertion failed: (%s), file %s, line %d.\n", failedexpr
, file
, line
);
91 _ZN4dyld3logEPKcz("Assertion failed: (%s), function %s, file %s, line %d.\n", failedexpr
, func
, file
, line
);
96 // called by libuwind code before aborting
97 size_t fwrite(const void* ptr
, size_t size
, size_t nitme
, FILE* stream
)
99 return fprintf(stream
, "%s", (char*)ptr
);
102 // called by libuwind code before aborting
103 int fprintf(FILE* file
, const char* format
, ...)
106 va_start(list
, format
);
107 _simple_vdprintf(STDERR_FILENO
, format
, list
);
112 // called by LIBC_ABORT
113 void abort_report_np(const char* format
, ...)
117 _SIMPLE_STRING s
= _simple_salloc();
119 va_start(list
, format
);
120 _simple_vsprintf(s
, format
, list
);
122 str
= _simple_string(s
);
125 // _simple_salloc failed, but at least format may have useful info by itself
128 _ZN4dyld4haltEPKc(str
);
129 // _ZN4dyld4haltEPKc doesn't return, so we can't call _simple_sfree
133 // real cthread_set_errno_self() has error handling that pulls in
134 // pthread_exit() which pulls in fprintf()
135 extern int* __error(void);
136 void cthread_set_errno_self(int err
)
143 * We have our own localtime() to avoid needing the notify API which is used
144 * by the code in libc.a for localtime() which is used by arc4random().
146 struct tm
* localtime(const time_t* t
)
148 return (struct tm
*)NULL
;
153 // The stack protector routines in lib.c bring in too much stuff, so
154 // make our own custom ones.
156 long __stack_chk_guard
= 0;
157 static __attribute__((constructor
)) void __guard_setup(void)
160 __stack_chk_guard
= ((long)arc4random() << 32) | arc4random();
162 __stack_chk_guard
= arc4random();
165 extern void _ZN4dyld4haltEPKc(const char*);
166 void __stack_chk_fail()
168 _ZN4dyld4haltEPKc("stack buffer overrun");