+ return (char *)"unknown error code";
+}
+char* mach_error_type(mach_error_t err)
+{
+ return (char *)"(unknown/unknown)";
+}
+
+// _pthread_reap_thread calls fprintf(stderr).
+// We map fprint to _simple_vdprintf and ignore FILE* stream, so ok for it to be NULL
+FILE* __stderrp = NULL;
+FILE* __stdoutp = NULL;
+
+// work with c++abi.a
+void (*__cxa_terminate_handler)() = _ZSt9terminatev;
+void (*__cxa_unexpected_handler)() = _ZSt10unexpectedv;
+
+void abort_message(const char* format, ...)
+{
+ va_list list;
+ va_start(list, format);
+ _simple_vdprintf(STDERR_FILENO, format, list);
+ va_end(list);
+}
+
+void __cxa_bad_typeid()
+{
+ _ZN4dyld4haltEPKc("__cxa_bad_typeid()");
+}
+
+// to work with libc++
+void _ZNKSt3__120__vector_base_commonILb1EE20__throw_length_errorEv()
+{
+ _ZN4dyld4haltEPKc("std::vector<>::_throw_length_error()");
+}
+
+// libc.a sometimes missing memset
+#undef memset
+void* memset(void* b, int c, size_t len)
+{
+ uint8_t* p = (uint8_t*)b;
+ for(size_t i=len; i > 0; --i)
+ *p++ = c;
+ return b;
+}
+
+
+// <rdar://problem/10111032> wrap calls to stat() with check for EAGAIN
+int _ZN4dyld7my_statEPKcP4stat(const char* path, struct stat* buf)
+{
+ int result;
+ do {
+ result = stat(path, buf);
+ } while ((result == -1) && (errno == EAGAIN));
+
+ return result;
+}
+
+// <rdar://problem/13805025> dyld should retry open() if it gets an EGAIN
+int _ZN4dyld7my_openEPKcii(const char* path, int flag, int other)
+{
+ int result;
+ do {
+ result = open(path, flag, other);
+ } while ((result == -1) && (errno == EAGAIN));
+
+ return result;
+}
+
+
+//
+// The dyld in the iOS simulator cannot do syscalls, so it calls back to
+// host dyld.
+//
+
+#if TARGET_IPHONE_SIMULATOR
+
+#include <coreSymbolicationDyldSupport.h>
+
+int myopen(const char* path, int oflag, int extra) __asm("_open");
+int myopen(const char* path, int oflag, int extra) {
+ return gSyscallHelpers->open(path, oflag, extra);
+}
+
+int close(int fd) {
+ return gSyscallHelpers->close(fd);
+}
+
+ssize_t pread(int fd, void* buf, size_t nbytes, off_t offset) {
+ return gSyscallHelpers->pread(fd, buf , nbytes, offset);
+}
+
+ssize_t write(int fd, const void *buf, size_t nbytes) {
+ return gSyscallHelpers->write(fd, buf , nbytes);
+}
+
+void* mmap(void* addr, size_t len, int prot, int flags, int fd, off_t offset) {
+ return gSyscallHelpers->mmap(addr, len, prot, flags, fd, offset);
+}
+
+int munmap(void* addr, size_t len) {
+ return gSyscallHelpers->munmap(addr, len);
+}
+
+int madvise(void* addr, size_t len, int advice) {
+ return gSyscallHelpers->madvise(addr, len, advice);
+}
+
+int stat(const char* path, struct stat* buf) {
+ return gSyscallHelpers->stat(path, buf);
+}
+
+int myfcntl(int fd, int cmd, void* result) __asm("_fcntl");
+int myfcntl(int fd, int cmd, void* result) {
+ return gSyscallHelpers->fcntl(fd, cmd, result);
+}
+
+int myioctl(int fd, unsigned long request, void* result) __asm("_ioctl");
+int myioctl(int fd, unsigned long request, void* result) {
+ return gSyscallHelpers->ioctl(fd, request, result);
+}
+
+int issetugid() {
+ return gSyscallHelpers->issetugid();
+}
+
+char* getcwd(char* buf, size_t size) {
+ return gSyscallHelpers->getcwd(buf, size);
+}
+
+char* realpath(const char* file_name, char* resolved_name) {
+ return gSyscallHelpers->realpath(file_name, resolved_name);
+}
+
+
+
+kern_return_t vm_allocate(vm_map_t target_task, vm_address_t *address,
+ vm_size_t size, int flags) {
+ return gSyscallHelpers->vm_allocate(target_task, address, size, flags);
+}
+
+kern_return_t vm_deallocate(vm_map_t target_task, vm_address_t address,
+ vm_size_t size) {
+ return gSyscallHelpers->vm_deallocate(target_task, address, size);
+}
+
+kern_return_t vm_protect(vm_map_t target_task, vm_address_t address,
+ vm_size_t size, boolean_t max, vm_prot_t prot) {
+ return gSyscallHelpers->vm_protect(target_task, address, size, max, prot);
+}
+
+
+void _ZN4dyld3logEPKcz(const char* format, ...) {
+ va_list list;
+ va_start(list, format);
+ gSyscallHelpers->vlog(format, list);
+ va_end(list);
+}
+
+void _ZN4dyld4warnEPKcz(const char* format, ...) {
+ va_list list;
+ va_start(list, format);
+ gSyscallHelpers->vwarn(format, list);
+ va_end(list);
+}
+
+
+int pthread_mutex_lock(pthread_mutex_t* m) {
+ return gSyscallHelpers->pthread_mutex_lock(m);
+}
+
+int pthread_mutex_unlock(pthread_mutex_t* m) {
+ return gSyscallHelpers->pthread_mutex_unlock(m);
+}
+
+mach_port_t mach_thread_self() {
+ return gSyscallHelpers->mach_thread_self();
+}
+
+kern_return_t mach_port_deallocate(ipc_space_t task, mach_port_name_t name) {
+ return gSyscallHelpers->mach_port_deallocate(task, name);
+}
+
+mach_port_name_t task_self_trap() {
+ return gSyscallHelpers->task_self_trap();
+}
+
+kern_return_t mach_timebase_info(mach_timebase_info_t info) {
+ return gSyscallHelpers->mach_timebase_info(info);
+}
+
+bool OSAtomicCompareAndSwapPtrBarrier(void* old, void* new, void * volatile *value) {
+ return gSyscallHelpers->OSAtomicCompareAndSwapPtrBarrier(old, new, value);
+}
+
+void OSMemoryBarrier() {
+ return gSyscallHelpers->OSMemoryBarrier();
+}
+
+uint64_t mach_absolute_time(void) {
+ return gSyscallHelpers->mach_absolute_time();
+}
+
+kern_return_t thread_switch(mach_port_name_t thread_name,
+ int option, mach_msg_timeout_t option_time) {
+ if ( gSyscallHelpers->version < 2 )
+ return KERN_FAILURE;
+ return gSyscallHelpers->thread_switch(thread_name, option, option_time);
+}
+
+DIR* opendir(const char* path) {
+ if ( gSyscallHelpers->version < 3 )
+ return NULL;
+ return gSyscallHelpers->opendir(path);