Files
reims-vgpu/guest/bundle/tests/bundle_sync_check.sh
T
Anees Iqbal 59c4dfcc98 ✅ Check that the bundle takes no object's lock
tests/bundle_sync_check.sh fails where the x86-64 bundle or the native build
of the bundle's sources imports objc_sync_enter or objc_sync_exit, the
runtime's object lock that every @synchronized takes and an app's
@synchronized on the same object takes too. A grep of src/ covers the device
shell's arm64 code, which neither build compiles. `make test` runs it beside
bundle_files_check.sh. Over the sets and sources of the commit before the
locks' fix it fails on the x86-64, arm64 and arm64e bundles. The guest sets'
records take the Makefile's new hash; their kexts are unchanged.
2026-11-26 17:36:27 -08:00

34 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
# bundle_sync_check.sh BUNDLE SRC [OBJECT...]: that the bundle takes no lock on an object an app can
# reach. @synchronized(x) locks x's own lock in the Objective-C runtime (objc_sync_enter), which an
# app's @synchronized(x) takes too: an app that holds its command buffer's across the buffer's commit
# and waitUntilCompleted, as a 2D game on a common engine does, waits there for good if the bundle's
# completion takes the same lock. So the bundle keeps locks of its own (std::mutex), never an
# object's (tests/queue_tests.mm, AN APP'S LOCKS). Every route to the runtime's lock imports
# objc_sync_enter or objc_sync_exit: neither may be imported by the x86-64 bundle, BUNDLE, nor by
# the OBJECTs, which `make test` passes as the native build of the bundle's sources but the device
# shell's, so the arm64 device's code is looked at too. The grep of SRC finds a @synchronized in
# what neither build compiles (the device shell's arm64 code). Part of `make test`.
set -euo pipefail
exe=$1
src=$2
shift 2
[ -f "$exe" ] || exe=$exe/Contents/MacOS/reims-graphics
fails=0
for bin in "$exe" "$@"; do
calls=$(nm -u "$bin" | grep -E '^_objc_sync_(enter|exit)$' || true)
if [ -n "$calls" ]; then
echo "bundle_sync_check: FAIL: $bin imports" $calls "(a @synchronized or a call of the runtime's object lock)"
fails=1
fi
done
# Code lines only: a line that starts a // comment, or a /* */ comment's * line, is not code.
lines=$(grep -rnE '@synchronized|objc_sync_(enter|exit)' "$src" | grep -vE '^[^:]+:[0-9]+:[[:space:]]*(//|\*|/\*)' || true)
if [ -n "$lines" ]; then
echo "bundle_sync_check: FAIL: the runtime's object lock in $src:"
echo "$lines"
fails=1
fi
[ $fails = 0 ] || exit 1
echo "bundle_sync_check: no objc_sync_enter or objc_sync_exit in $exe and $# objects, and no @synchronized in $src"