diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9e0fb7d..94a61d9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -560,7 +560,8 @@ jobs: C cd probe mcpp build --release --target x86_64-macos-musl 2>&1 | tee build.log - grep -q 'openkal-macos@0.23.4' build.log || { echo "::error::the working tree was not the kernel-abi layer"; exit 1; } + version="$(sed -n 's/^version *= *"\(.*\)"/\1/p' ../openkal-macos/mcpp.toml | head -1)" + grep -q "openkal-macos@$version" build.log || { echo "::error::the working tree was not the kernel-abi layer"; exit 1; } mkdir -p ../out && cp "$(find target -name zeroing -type f | head -1)" ../out/ - uses: actions/upload-artifact@v4 with: { name: zeroing-x86_64, path: out/ } diff --git a/README.md b/README.md index e6b0d61..155d520 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ written on the kernel's own calls. openkal = "0.25.0" [target.'cfg(os = "macos")'.dependencies] -openkal-macos = "0.23.4" +openkal-macos = "0.23.5" ``` Its purpose is as much to test the specification as to be used. A specification @@ -183,6 +183,17 @@ same image parses as fast on Linux arm64. Since 0.17.1 it is the same kernel ide this system's library keeps for each thread (`pthread_threadid_np`, a name no C library in this ecosystem defines). +## What 0.23.5 corrects + +**A part of `fork` the library does not export is not called.** Starting a context +(`kal_space_start`, and a confined start) calls the parts of the library's own `fork` +by their names: dyld's, the allocator's, the C library's and the thread library's +handlers. They were ordinary imports, so a system built from the same sources whose +library does not export every one of them did not start the program at all (measured +on PureDarwin 26.5: `dyld: Symbol not found: __pthread_atfork_prepare`, expected in +`/usr/lib/libSystem.B.dylib`). Each is now a weak import, called when it is bound. On +macOS every one is bound and nothing changes. + ## What 0.23.4 corrects **The stub of `libSystem` lists `__bzero` for x86_64.** Clang lowers a zeroing diff --git a/mcpp.toml b/mcpp.toml index f359817..95eb345 100644 --- a/mcpp.toml +++ b/mcpp.toml @@ -1,7 +1,7 @@ [package] namespace = "mcpplibs" name = "openkal-macos" -version = "0.23.4" +version = "0.23.5" description = "An implementation of openkal for macOS, written on the kernel's own calls. Its purpose is as much to test the specification as to be used." license = "Apache-2.0" diff --git a/src/space.cpp b/src/space.cpp index 0d8ef8f..8cb0efe 100644 --- a/src/space.cpp +++ b/src/space.cpp @@ -44,32 +44,42 @@ extern "C" { // in this ecosystem defines, so it is reachable beneath one as above one. The // handlers a program registers with `pthread_atfork' are not run: a copy made // here is not a `fork' the program asked for. -void _dyld_atfork_prepare(void); -void _dyld_atfork_parent(void); -void _dyld_fork_child(void); -void _malloc_fork_prepare(void); -void _malloc_fork_parent(void); -void _malloc_fork_child(void); -void _libc_fork_prepare(void); -void _libc_fork_parent(void); -void _libc_fork_child(void); -void _pthread_atfork_prepare(void); -void _pthread_atfork_parent(void); -void _pthread_atfork_child(void); -void _mach_fork_child(void); +// EACH PART IS BOUND IF THE LIBRARY HAS IT (0.23.5). The names are the library's +// own, between its parts, and a system built from the same sources need not +// export every one of them from the library a program links (measured on +// PureDarwin 26.5: `Symbol not found: __pthread_atfork_prepare', and the +// program was not started at all). A part that is not there is not called: the +// state it would have prepared is that part's, which a program that cannot +// name the part did not reach either. +#define OKM_PART __attribute__((weak_import)) +void _dyld_atfork_prepare(void) OKM_PART; +void _dyld_atfork_parent(void) OKM_PART; +void _dyld_fork_child(void) OKM_PART; +void _malloc_fork_prepare(void) OKM_PART; +void _malloc_fork_parent(void) OKM_PART; +void _malloc_fork_child(void) OKM_PART; +void _libc_fork_prepare(void) OKM_PART; +void _libc_fork_parent(void) OKM_PART; +void _libc_fork_child(void) OKM_PART; +void _pthread_atfork_prepare(void) OKM_PART; +void _pthread_atfork_parent(void) OKM_PART; +void _pthread_atfork_child(void) OKM_PART; +void _mach_fork_child(void) OKM_PART; +#undef OKM_PART } // extern "C" namespace { +void part(void (*routine)(void)) { if (routine != nullptr) routine(); } void prepare() { - _dyld_atfork_prepare(); _malloc_fork_prepare(); _libc_fork_prepare(); _pthread_atfork_prepare(); + part(_dyld_atfork_prepare); part(_malloc_fork_prepare); part(_libc_fork_prepare); part(_pthread_atfork_prepare); } void in_the_original() { - _pthread_atfork_parent(); _libc_fork_parent(); _malloc_fork_parent(); _dyld_atfork_parent(); + part(_pthread_atfork_parent); part(_libc_fork_parent); part(_malloc_fork_parent); part(_dyld_atfork_parent); } void in_the_copy() { - _mach_fork_child(); _dyld_fork_child(); _pthread_atfork_child(); _malloc_fork_child(); _libc_fork_child(); + part(_mach_fork_child); part(_dyld_fork_child); part(_pthread_atfork_child); part(_malloc_fork_child); part(_libc_fork_child); } } // namespace