Skip to content

XNU as a loadable kernel module inside Linux (macOS personality for arm64 Linux)

C

Hosted test helpers: dslocal groups match /etc/group (wheel, daemon, nobody, staff; CPython's test_grp compares both), console-send-file keeps a last line without a newline, scripts for Metal/ictool probes, Firewalk build and Alamofire's full xcodebuild test; vm-gpu-prep.sh can skip the kernel rebuild

Heyang Zhou0ffece1308f6
diff --git a/scripts/vm-sysdisk-launchd.sh b/scripts/vm-sysdisk-launchd.sh
index c599d8d..6147801 100755
--- a/scripts/vm-sysdisk-launchd.sh
+++ b/scripts/vm-sysdisk-launchd.sh
@@ -58,12 +58,15 @@ if [ "${MODE:-launchd}" = launchd ]; then
UP
}
u root 0 0 /var/root "System Administrator"; u daemon 1 1 /var/root "System Services"
- sudo tee $D/groups/wheel.plist >/dev/null <<'GP'
+ # the same groups as /etc/group, so the directory node and libinfo's file module agree (CPython's test_grp checks both)
+ g() { sudo tee $D/groups/$1.plist >/dev/null <<GP
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
-<plist version="1.0"><dict><key>name</key><array><string>wheel</string></array><key>gid</key><array><string>0</string></array>
-<key>users</key><array><string>root</string></array><key>generateduid</key><array><string>ABCDEFAB-CDEF-ABCD-EFAB-CDEF00000000</string></array></dict></plist>
+<plist version="1.0"><dict><key>name</key><array><string>$1</string></array><key>gid</key><array><string>$2</string></array>
+<key>users</key><array>${3:+<string>$3</string>}</array><key>generateduid</key><array><string>ABCDEFAB-CDEF-ABCD-EFAB-CDEF0000$4</string></array></dict></plist>
GP
+ }
+ g wheel 0 root 0000; g daemon 1 root 0001; g nobody -2 "" FFFE; g staff 20 root 0014
sudo chmod -R go-rwx /mnt/sys/private/var/db/dslocal
# flat files for libinfo's file module
printf 'root:*:0:0:System Administrator:/var/root:/bin/sh\ndaemon:*:1:1:System Services:/var/root:/usr/bin/false\nnobody:*:-2:-2:Unprivileged User:/var/empty:/usr/bin/false\n' | sudo tee /mnt/sys/private/etc/passwd >/dev/null
diff --git a/tools/hosted/tests/af.sh b/tools/hosted/tests/af.sh
new file mode 100644
index 0000000..e769ab0
--- /dev/null
+++ b/tools/hosted/tests/af.sh
@@ -0,0 +1,10 @@
+# Firewalk on :8080, then Alamofire's full xcodebuild test
+cd /var/root/src/Firewalk
+(./.build/release/firewalk < /dev/null > /tmp/firewalk.log 2>&1 &)
+sleep 5; curl -sS -o /dev/null -w "firewalk: HTTP %{http_code}\n" http://127.0.0.1:8080/get
+grep -n "static var host\|ProcessInfo\|environment\[" /var/root/src/Alamofire-5.10.2/Tests/TestHelpers.swift | head -5
+cd /var/root/src/Alamofire-5.10.2
+time launchctl asuser 0 xcodebuild -project Alamofire.xcodeproj -scheme "Alamofire macOS" -configuration Debug -destination "platform=macOS" -derivedDataPath /tmp/afdd7 CODE_SIGNING_ALLOWED=NO MACOSX_DEPLOYMENT_TARGET=12.0 ENABLE_THREAD_SANITIZER=NO test > /tmp/afall.log 2>&1
+echo "AFRC=$?"
+grep -a -E "Executed [0-9]+ tests|\*\* .* (SUCCEEDED|FAILED) \*\*" /tmp/afall.log | tail -3
+grep -a "error: -\[" /tmp/afall.log | sed "s/.*error: -\[//" | cut -d" " -f1-2 | sort | uniq -c | sort -nr | head -15
diff --git a/tools/hosted/tests/afds.sh b/tools/hosted/tests/afds.sh
new file mode 100644
index 0000000..ce213e9
--- /dev/null
+++ b/tools/hosted/tests/afds.sh
@@ -0,0 +1,3 @@
+cd /tmp
+grep -a "error: -\[" afall.log | grep -a "DataStreamTests\|DataStreamConcurrency" | sed "s/.*error: -\[Alamofire_macOS_Tests\.//" | cut -c1-230 | head -16
+grep -a "firewalk\|Firewalk" /tmp/firewalk.log | tail -3; tail -5 /tmp/firewalk.log
diff --git a/tools/hosted/tests/afep.sh b/tools/hosted/tests/afep.sh
new file mode 100644
index 0000000..9457b03
--- /dev/null
+++ b/tools/hosted/tests/afep.sh
@@ -0,0 +1,4 @@
+cd /var/root/src/Alamofire-5.10.2/Tests
+grep -n "case stream\|case payloads\|\"/stream\|\"/payloads\|static func stream\|static func payloads\|path: \"/" TestHelpers.swift | head -12
+for p in /stream/2 /payloads/2 /bytes/10 /get; do curl -s -o /dev/null -w "$p -> %{http_code}\n" http://127.0.0.1:8080$p; done
+cd /var/root/src/Firewalk && git log -1 --format="%h %ad %s" --date=short && grep -rn "\"stream\"\|\"payloads\"" Sources | head -5
diff --git a/tools/hosted/tests/afsum.sh b/tools/hosted/tests/afsum.sh
new file mode 100644
index 0000000..d460507
--- /dev/null
+++ b/tools/hosted/tests/afsum.sh
@@ -0,0 +1,5 @@
+cd /tmp
+grep -a "error: -\[" afall.log | sed "s/.*error: -\[Alamofire_macOS_Tests\.//" | cut -d" " -f1 | sort | uniq -c | sort -nr
+grep -a "error: -\[" afall.log | grep -a DataStreamTests | head -3 | cut -c1-300
+grep -a "error: -\[" afall.log | grep -a "TLSEvaluation" | head -2 | cut -c1-300
+grep -a "error: -\[" afall.log | grep -av "TLSEvaluation\|DataStream" | sed "s/.*error: -\[Alamofire_macOS_Tests\.//" | cut -c1-200 | head -12
diff --git a/tools/hosted/tests/arch.m b/tools/hosted/tests/arch.m
new file mode 100644
index 0000000..7b3effc
--- /dev/null
+++ b/tools/hosted/tests/arch.m
@@ -0,0 +1,21 @@
+#import <Foundation/Foundation.h>
+#import <Metal/Metal.h>
+#import <objc/runtime.h>
+#include <dlfcn.h>
+int main(void) {
+ MTLCreateSystemDefaultDevice();
+ Dl_info info; dladdr((void *)MTLCreateSystemDefaultDevice, &info);
+ unsigned n = 0; const char **names = objc_copyClassNamesForImage(info.dli_fname, &n);
+ for (unsigned i = 0; i < n; i++) {
+ Class c = objc_getClass(names[i]);
+ if (!class_getInstanceMethod(c, sel_registerName("subType"))) continue;
+ printf("class %s : %s\n", names[i], class_getName(class_getSuperclass(c)));
+ unsigned m = 0; Method *ms = class_copyMethodList(c, &m);
+ for (unsigned j = 0; j < m; j++) printf(" - %s %s\n", sel_getName(method_getName(ms[j])), method_getTypeEncoding(ms[j]));
+ ms = class_copyMethodList(object_getClass(c), &m);
+ for (unsigned j = 0; j < m; j++) printf(" + %s %s\n", sel_getName(method_getName(ms[j])), method_getTypeEncoding(ms[j]));
+ unsigned k = 0; Ivar *iv = class_copyIvarList(c, &k);
+ for (unsigned j = 0; j < k; j++) printf(" ivar %s %s @%td\n", ivar_getName(iv[j]), ivar_getTypeEncoding(iv[j]), ivar_getOffset(iv[j]));
+ }
+ return 0;
+}
diff --git a/tools/hosted/tests/crash.sh b/tools/hosted/tests/crash.sh
index 75970e2..30253e1 100644
--- a/tools/hosted/tests/crash.sh
+++ b/tools/hosted/tests/crash.sh
@@ -1,6 +1,6 @@
cd /tmp
ls -t /Library/Logs/DiagnosticReports /var/root/Library/Logs/DiagnosticReports 2>/dev/null | head -8
-f=$(ls -t /Library/Logs/DiagnosticReports/*.ips /var/root/Library/Logs/DiagnosticReports/*.ips 2>/dev/null | head -1)
+f=$(ls -t /Library/Logs/DiagnosticReports/${1:-}*.ips /var/root/Library/Logs/DiagnosticReports/${1:-}*.ips 2>/dev/null | head -1)
echo "REPORT $f"
python3 - "$f" <<'PY'
import json,sys
@@ -12,7 +12,7 @@ print('asi', b.get('asi'))
imgs=b.get('usedImages',[])
for th in b.get('threads',[]):
if th.get('triggered'):
- for fr in th.get('frames',[])[:14]:
+ for fr in th.get('frames',[])[:22]:
im=imgs[fr['imageIndex']] if fr.get('imageIndex') is not None and fr['imageIndex']<len(imgs) else {}
print(' ', im.get('name','?'), fr.get('symbol','?'), hex(fr.get('imageOffset',0)))
PY
diff --git a/tools/hosted/tests/fw.sh b/tools/hosted/tests/fw.sh
new file mode 100644
index 0000000..bba0db7
--- /dev/null
+++ b/tools/hosted/tests/fw.sh
@@ -0,0 +1,6 @@
+# Build and start Alamofire's local test server Firewalk (Vapor, SwiftPM dependencies fetched over the network)
+cd /var/root/src
+[ -d Firewalk ] || git clone --depth 1 https://github.com/Alamofire/Firewalk.git > /tmp/fw-clone.log 2>&1
+cd Firewalk && echo "clone rc=$? $(git log --oneline -1 2>/dev/null)"
+( time swift build -c release ) > /tmp/fw-build.log 2>&1
+echo "FWBUILD rc=$?" >> /tmp/fw-build.log
diff --git a/tools/hosted/tests/fwst.sh b/tools/hosted/tests/fwst.sh
new file mode 100644
index 0000000..a9461ef
--- /dev/null
+++ b/tools/hosted/tests/fwst.sh
@@ -0,0 +1,3 @@
+cat /tmp/fw.out /tmp/fw-clone.log 2>/dev/null | tail -5
+tail -5 /tmp/fw-build.log 2>/dev/null
+ls /var/root/src/Firewalk/.build 2>/dev/null | head
diff --git a/tools/hosted/tests/t10.sh b/tools/hosted/tests/t10.sh
new file mode 100644
index 0000000..4b4dbff
--- /dev/null
+++ b/tools/hosted/tests/t10.sh
@@ -0,0 +1,6 @@
+cd /tmp
+bash /tmp/upd.sh
+./m 2>&1 | grep -v "^metal2vulkan" | tail -4
+I="/Applications/Xcode.app/Contents/Applications/Icon Composer.app/Contents/Executables/ictool"
+rm -f /tmp/t.png; XNU_CPU_METAL_TRACE=1 "$I" /tmp/t.icon --export-image --output-file /tmp/t.png --platform macOS --rendition Default --width 16 --height 16 --scale 2 > /tmp/ic.log 2>&1
+echo "ictool rc=$?"; grep -v "^metal2vulkan\|^XCM new\|^XCM render\|^XCM compute" /tmp/ic.log | tail -12; ls -la /tmp/t.png; file /tmp/t.png
diff --git a/tools/hosted/tests/t11.sh b/tools/hosted/tests/t11.sh
new file mode 100644
index 0000000..8bc8ff7
--- /dev/null
+++ b/tools/hosted/tests/t11.sh
@@ -0,0 +1,2 @@
+cd /tmp
+grep -v "^metal2vulkan\|^XCM new\|^XCM render\|^XCM compute" /tmp/ic.log | head -24 | cut -c1-220
diff --git a/tools/hosted/tests/t12.sh b/tools/hosted/tests/t12.sh
new file mode 100644
index 0000000..8855300
--- /dev/null
+++ b/tools/hosted/tests/t12.sh
@@ -0,0 +1,4 @@
+cd /tmp
+XNU_CPU_METAL_TRACE=1 "/Applications/Xcode.app/Contents/Applications/Icon Composer.app/Contents/Executables/ictool" /tmp/t.icon --export-image --output-file /tmp/t.png --platform macOS --rendition Default --width 16 --height 16 --scale 2 > /tmp/ic2.log 2>&1
+echo "rc=$?"; grep -c . /tmp/ic2.log
+grep -v "^metal2vulkan" /tmp/ic2.log | grep -i "XCM\|stub" | sort | uniq -c | sort -nr | head -40 | cut -c1-200
diff --git a/tools/hosted/tests/t13.sh b/tools/hosted/tests/t13.sh
new file mode 100644
index 0000000..8f68c33
--- /dev/null
+++ b/tools/hosted/tests/t13.sh
@@ -0,0 +1,5 @@
+cd /tmp
+pgrep -lx trustd; pgrep -lx securityd
+xcrun swiftc trust.swift -o trust 2>&1 | tail -2; ./trust 2>&1 | tail -3
+security verify-cert -c /var/root/src/Alamofire-5.10.2/Tests/Resources/Certificates/alamofire.org/alamofire-root-ca.cer 2>&1 | tail -2
+log show --last 2m --style compact --predicate 'process == "trustd" OR subsystem == "com.apple.securityd"' 2>/dev/null | tail -8 | cut -c1-220
diff --git a/tools/hosted/tests/t8.sh b/tools/hosted/tests/t8.sh
new file mode 100644
index 0000000..cf77f40
--- /dev/null
+++ b/tools/hosted/tests/t8.sh
@@ -0,0 +1,5 @@
+cd /tmp
+rm -f /tmp/msgSends-*
+I="/Applications/Xcode.app/Contents/Applications/Icon Composer.app/Contents/Executables/ictool"
+NSObjCMessageLoggingEnabled=YES "$I" /tmp/t.icon --export-image --output-file /tmp/t.png --platform macOS --rendition Default --width 16 --height 16 --scale 2 > /dev/null 2>&1
+for f in /tmp/msgSends-*; do echo "== $f $(wc -l < $f)"; grep -n "XcmBackendDevice\|MTLLoader\|TargetDeviceArch" $f | tail -25 | cut -c1-160; done
diff --git a/tools/hosted/tests/t9.sh b/tools/hosted/tests/t9.sh
new file mode 100644
index 0000000..072a37b
--- /dev/null
+++ b/tools/hosted/tests/t9.sh
@@ -0,0 +1,3 @@
+cd /tmp
+xcrun clang arch.m -framework Foundation -framework Metal -o arch 2>&1 | grep error | head
+./arch 2>&1 | grep -v "^metal2vulkan" | cut -c1-160 | head -80
diff --git a/tools/hosted/tests/trust.swift b/tools/hosted/tests/trust.swift
new file mode 100644
index 0000000..4013844
--- /dev/null
+++ b/tools/hosted/tests/trust.swift
@@ -0,0 +1,9 @@
+import Foundation
+import Security
+// Does Security.framework's trust evaluation (trustd) work? URLSession HTTPS uses it; curl does not.
+let sem = DispatchSemaphore(value: 0)
+let task = URLSession.shared.dataTask(with: URL(string: "https://www.apple.com/")!) { data, resp, err in
+ print("URLSession https:", (resp as? HTTPURLResponse)?.statusCode ?? -1, data?.count ?? 0, err.map { "\($0)" } ?? "no error")
+ sem.signal()
+}
+task.resume(); _ = sem.wait(timeout: .now() + 30)
diff --git a/tools/hosted/tests/upd.sh b/tools/hosted/tests/upd.sh
new file mode 100644
index 0000000..2f5f72b
--- /dev/null
+++ b/tools/hosted/tests/upd.sh
@@ -0,0 +1,2 @@
+# In the hosted macOS: fetch the Metal plugin bundle from the Linux side and replace /Library/GPUBundles/XnuCpuMetal.bundle
+cd /tmp && curl -sS -o XnuCpuMetal.bundle.tgz http://192.168.77.1:8765/XnuCpuMetal.bundle.tgz && rm -rf /Library/GPUBundles/XnuCpuMetal.bundle && tar -C /Library/GPUBundles -xzf XnuCpuMetal.bundle.tgz && echo "bundle updated: $(du -sh /Library/GPUBundles/XnuCpuMetal.bundle | cut -f1)"