Skip to content

Latest commit

 

History

History
53 lines (45 loc) · 11.2 KB

Darwin.md

File metadata and controls

53 lines (45 loc) · 11.2 KB

Darwin (C library, POSIX, Mach)

Rows: 26: 23 ✅ 3 🟡

Area: Swift, Darwin & runtimes · Issues: area:runtime

How isim implements it

  • Passthrough: the host's glibc, through a libSystem shim that translates errno values, signals and structures (isim/runtime/libsystem.c, darwin_extras.inc).
  • Adapted:
    • the SDK headers are isim's own subset (isim/sdk-src/usr/include);
    • Mach is in-process (isim/runtime/mach.inc);
    • sysctl / uname give fixed answers, like Apple's Simulator on an Intel Mac.
  • Passthrough: SQLite, zlib and libc++ are the host's (libc++ 22 is built for isim).

API

API / feature Status iOS Notes
libc / POSIX (stdio, malloc, string, pthreads, time, files) ✅ ≤17 host glibc with Darwin layouts. unistd.h, stdlib.h, string.h / strings.h, signal.h and time.h declare the full common set (sysconf with Darwin's _SC_*, pathconf, mkstemp / mkdtemp, strsep, strptime, getentropy, qsort_r with Darwin's argument order, getopt and its globals, sigaction / sigset_t / sigaltstack with Darwin's layouts, …); errno.h has every Darwin value. Adapted: fork / exec* and changing the user or group fail with EPERM, as in the iOS sandbox. Tested: LibcTest (test_libc), SwiftExtrasTest
sys/mman.h, sys/sysctl.h (+ sysctlnametomib, struct kinfo_proc), sys/utsname.h, sys/resource.h, sys/random.h ✅ ≤17 adapted: msync / madvise flags and RLIMIT_* translated, RLIM_INFINITY is Darwin's, ru_maxrss in bytes; uname and sysctl describe a Simulator on an Intel Mac (Darwin, x86_64). Tested: LibcTest, SwiftExtrasTest (utsname, sysctlbyname from Swift)
sys/event.h (kqueue, kevent, kevent64) 🟡 ≤17 adapted: a kqueue is an epoll instance; EVFILT_READ / EVFILT_WRITE (data: bytes ready / buffer space, EV_EOF), EVFILT_TIMER (timerfd, NOTE_SECONDS / USECONDS / NSECONDS), EVFILT_USER (eventfd, NOTE_TRIGGER, NOTE_FF*); EV_ONESHOT, EV_CLEAR, EV_DISPATCH, EV_RECEIPT. Not supported (EINVAL): EVFILT_VNODE, EVFILT_PROC, EVFILT_SIGNAL, EVFILT_MACHPORT. Tested: LibcTest
sys/xattr.h ✅ ≤17 adapted: the host file system's user. attributes (XATTR_NOFOLLOW, XATTR_CREATE / REPLACE, ENOATTR); position must be 0 (no resource forks). Tested: LibcTest
wchar.h, regex.h ✅ ≤17 wide-character functions passthrough; multibyte conversions in UTF-8 (adapted: as under a UTF-8 locale); POSIX regex compiled by the host's C library behind Darwin's regex_t / 64-bit regmatch_t, flags and error codes translated, REG_NOSPEC and REG_PEND supported (REG_ENHANCED is not: REG_INVARG). Tested: LibcTest, HelloToolchain's C package (posix.c)
execinfo.h ✅ ≤17 adapted: backtrace walks the guest's frame pointers; backtrace_symbols(_fd) in Darwin's format (0 MyApp 0x… function + 52). Tested: LibcTest
syslog.h, pwd.h, termios.h ✅ ≤17 adapted: syslog goes to the unified log (isim log; %m, LOG_PERROR, setlogmask), as on iOS; the user database has the device's one user, mobile, home = the app's home; termios flags, control characters and speeds translated to and from the host's. Tested: LibcTest
notify.h (notify_post, notify_register_check / dispatch / signal / file_descriptor, state, suspend / resume) ✅ ≤17 adapted: delivered to every process of the device (the app, its extensions, other apps); the rows are on the DarwinNotify page. In isim's Foundation, so the app must load Foundation. Tested: LibcTest, NotifyTest
Swift's type-generic math (tgmath): sin, cos, tan, atan2, pow, exp, log… on Float, and the generic sqrt, fabs, floor, ceil, round, trunc, fmod, remainder, fma ✅ ≤17 as in Apple's Darwin overlay (isim/swift/overlays/Darwin/tgmath.swift), over the C library's float functions. Tested (HelloMetalKit: tan(Float))
libkern/OSAtomic.h (OSAtomic*, OSSpinLock, OSAtomicEnqueue / Dequeue) ✅ ≤17 isim's implementations with the compiler's atomics (deprecated as on iOS). Tested: LibcTest
os/activity.h, os/proc.h 🟡 ≤17 adapted: activities keep each thread's current activity and their identifiers but are not shown in isim log; os_proc_available_memory is a 3 GB per-app limit minus the app's resident size. Tested: LibcTest, SwiftExtrasTest
Darwin locales (newlocale, uselocale, localeconv, <xlocale.h> _l functions), <ctype.h> rune tables ✅ ≤17 adapted: the host's glibc locale objects (NULL = the C locale); setlocale records the app's choice without changing the host process's locale. Tested: test_system_objc
libc++ iostreams, locales, <regex>, std::shared_mutex, <memory_resource> ✅ ≤17 libc++ 22 built with localization (char only; no wide characters, <filesystem>, random_device or to_chars for floating point). Tested: test_system_objc
zlib (libz), libcompression (compression_encode_buffer/decode) 🟡 ≤17 passthrough: the host's zlib; libcompression supports COMPRESSION_ZLIB only (LZFSE, LZ4, LZMA fail). Tested: test_system_objc
pipe, pread/pwrite, dup/dup2, kill, signal/raise with Darwin signal numbers (SIGUSR1 = 30, ...); Swift open/fcntl/ioctl and SIG_IGN/SIG_DFL ✅ ≤17 numbers translated to the host's and back for handlers. Tested: SwiftExtrasTest (pipe sources, raise(SIGUSR1))
flock (<sys/file.h>: LOCK_SH/LOCK_EX/LOCK_NB/LOCK_UN), <sys/stat.h> mode bits (S_IRWXU … S_ISVTX, S_IF*) ✅ ≤17 flock passthrough (lock values match Linux); the mode bits are mode_t as in Apple's Darwin overlay, so Swift's open(path, flags, S_IRUSR | S_IWUSR) takes the non-variadic form. Tested: SwiftExtrasTest (POSIX)
errno from Swift ✅ ≤17 the Darwin overlay (import Darwin, also through Foundation) reads and sets the thread's errno, translated to Darwin values; the Foundation overlay's old copy stays for ABI. Tested (swift-extras POSIXTests)
dlopen of app-bundled dylibs/frameworks, dlsym, dladdr, dlopen_preflight, NSBundle code loading ✅ ≤17 adapted: isim's loader maps dylibs, MH_BUNDLEs and frameworks (Objective-C and Swift) with their own dependencies, TLV, initializers, +load, categories; paths with @rpath / @executable_path / @loader_path (from the calling image), RTLD_NOLOAD, RTLD_FIRST; dlsym on a handle searches its dependencies, RTLD_DEFAULT / RTLD_MAIN_ONLY / RTLD_NEXT / RTLD_SELF; an image or dependency that cannot load fails with a dyld-style dlerror (the app keeps running). NSBundle load, loadAndReturnError:, preflightAndReturnError:, isLoaded, principalClass (NSPrincipalClass, else the first class), classNamed:, allFrameworks, allBundles. Images are never unloaded (dlclose / unload, as on iOS for Objective-C and Swift code). Embedded frameworks linked at build time: HelloToolchain. Tested: tests/dlopen
Mach APIs (<mach/mach.h>, <mach/mach_time.h>): time, task_info, task_threads / thread_info, host_info / host_statistics(64) / host_processor_info, vm_allocate & co., ports and mach_msg, semaphores, clocks ✅ ≤17 adapted on Linux, the calling task only (other task ports are invalid destinations). mach_absolute_time (CLOCK_UPTIME_RAW, timebase 1/1), mach_continuous_time, mach_wait_until; task_info MACH_TASK_BASIC_INFO, TASK_BASIC_INFO, TASK_THREAD_TIMES_INFO, TASK_EVENTS_INFO, TASK_VM_INFO (phys_footprint = dirty anonymous memory; revisions by count) from /proc; thread_info basic / identifier / extended (cpu_usage averaged over about a second), pthread_mach_thread_np / pthread_from_mach_thread_np / pthread_threadid_np agree with thread ports (Linux tids); host_info reports the simulated device's memory (as ProcessInfo.physicalMemory) and the host's CPUs, VM page counts scaled to that memory; vm_read_overwrite reads without faulting; ports are in-process queues: simple messages (no port or memory descriptors), queue limits, send / receive timeouts, MACH_RCV_LARGE, reply and send-once rights, dead names; no port sets, exception ports or thread_get_state / thread_suspend. thread_policy_set is accepted, not applied (stub). Tested: tests/mach (Objective-C and Swift)
SQLite (sqlite3 C API, import SQLite3) ✅ ≤17 /usr/lib/libsqlite3.dylib forwards to the host's libsqlite3.so.0 (loaded on first use; a function the host's SQLite lacks stops the app with a message). Tested: SecurityTest, HelloSecurity
BSD sockets (socket, bind/listen/accept, connect, send/recv, getaddrinfo, inet_pton, poll/select, getifaddrs) ✅ ≤17 Darwin structs, constants and errno translated to the host's; tested (TCP server + client, socketpair, poll, select, getifaddrs, SO_RCVTIMEO); read/write errno translated too; UDP unverified
Simulator environment (SIMULATOR_MODEL_IDENTIFIER, SIMULATOR_DEVICE_NAME, SIMULATOR_RUNTIME_VERSION, SIMULATOR_UDID, SIMULATOR_ROOT, SIMULATOR_SHARED_RESOURCES_DIRECTORY, SIMULATOR_MAINSCREEN_*, …) ✅ ≤17 adapted: set by isim's launcher from the device and iOS version like Apple's Simulator (SYSTEM-PROMPTS.md); the UDID is made once per device data; SIMULATOR_ROOT is isim's SDK. Tested: HelloOSVersions (test_versions)
POSIXErrorCode, MachErrorCode ✅ ≤17 passthrough: Apple's Darwin overlay enums (Swift's stdlib/public/Platform), Darwin's values; POSIXErrorCode(rawValue: errno). Before 0.22 isim had a partial POSIXErrorCode in Network. Tested: HelloBytes (test_bytes)
fcntl, ioctl, open/openat from Swift ✅ ≤17 the Darwin Swift overlay wraps the variadic C functions like Apple's: fcntl with no argument, an Int32 or a pointer (F_GETFL/F_SETFL O_NONBLOCK, F_GETFD/F_SETFD, F_DUPFD), ioctl (FIONREAD, FIONBIO, FIOCLEX), open/openat with a mode (AT_FDCWD, O_DIRECTORY, O_NOFOLLOW); Darwin flags translated to the host's. Tested (swift-extras POSIXTests)
stdin / stdout / stderr in Swift, FILE (UnsafeMutablePointer<FILE>) ✅ ≤17 as Apple's Darwin overlay: the standard streams over __stdinp / __stdoutp / __stderrp; FILE has Darwin's layout so Swift imports FILE * as on iOS (only pointers cross isim's libSystem; the host owns the object). Tested (HelloAudioModules -policies: fflush(stdout))
DarwinBoolean (C's MacTypes Boolean) ✅ ≤17 passthrough: Apple's Darwin overlay type and the conversion functions Swift's Clang importer uses, so C Boolean parameters and results import as Bool (a Boolean * as UnsafeMutablePointer<DarwinBoolean>). Before 0.28 AudioToolbox had its own copy (rebuild apps that used it). Tested (test_swift_foundation)

Not yet in isim

Nothing (or not measured yet).