Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit
Swift apple-silicond3dmetaldxmtdxvkgame-porting-toolkitgptkmac-gamingmacosmetalfxrosetta-2steamsteam-playwinewinecx
feat(reports): say why a game quit in the run log and play reports (#201)
Raystorms6d7a87b88cc8
diff --git a/AGENTS.md b/AGENTS.mdindex 55479f9..de5c799 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -61,7 +61,7 @@ The checks the workflows run (`make -s <target>`):- **C and shell suites:** `sigcheck`, `callscheck`, `webpatch-fixtures`, `peicon-fixtures`,`panel-behavior`, `spawn-env`, `activatecheck`, `compatcheck`, `compatsvc-check`, `prefixstate-check`,`shortcutcheck`, `launch-shell`, `envcheck`, `buildcheck`, `settingscheck`, `routecheck`,- `bridgecheck`, `envpasscheck`, `prefixnotecheck`, `powernotecheck`, `gamedrivecheck`, `launchercheck`, `seedcheck`, `gamefixescheck`, `versioncheck`, `cicheck`,+ `bridgecheck`, `envpasscheck`, `prefixnotecheck`, `powernotecheck`, `exitcheck`, `gamedrivecheck`, `launchercheck`, `seedcheck`, `gamefixescheck`, `versioncheck`, `cicheck`,`compat-reported-check`- **Hardware-free device checks:** `game-host-check`, `dualsense-check`, `steam-rumble-check`diff --git a/Makefile b/Makefileindex f520110..01f2d01 100644--- a/Makefile+++ b/Makefile@@ -74,7 +74,7 @@ DEPS := $(OBJS:.o=.d)tests-list overlay-shim overlay-shim-install overlay-shim-tests \overlay-shim-bench iconmaker icon \appinfo helpers-install ntdll-resolve bridge runcheck compatcheck \- compatsvc-check prefixstate-check shortcutcheck scriptcheck envcheck buildcheck settingscheck routecheck bridgecheck envpasscheck prefixnotecheck powernotecheck gamedrivecheck \+ compatsvc-check prefixstate-check shortcutcheck scriptcheck envcheck buildcheck settingscheck routecheck bridgecheck envpasscheck prefixnotecheck powernotecheck exitcheck gamedrivecheck \gamefixescheck launchercheck padcheck launch-shell activatecheck stamp-check versioncheck cicheck compat-reported-check FORCEAPP_PAYLOAD := app/Sources/BridgeplayApp/Resources/payload@@ -143,6 +143,10 @@ powernotecheck:@if [ ! -f dylib/tests/powernotecheck.sh ]; then $(call SKIP,powernotecheck,dylib/tests/powernotecheck.sh); exit 0; fi; \sh dylib/tests/powernotecheck.sh dylib/feats/compat_run.sh+exitcheck:+ @if [ ! -f dylib/tests/exitcheck.sh ]; then $(call SKIP,exitcheck,dylib/tests/exitcheck.sh); exit 0; fi; \+ sh dylib/tests/exitcheck.sh dylib/feats/compat_run.sh+gamedrivecheck:@if [ ! -f dylib/tests/gamedrivecheck.sh ]; then $(call SKIP,gamedrivecheck,dylib/tests/gamedrivecheck.sh); exit 0; fi; \sh dylib/tests/gamedrivecheck.sh dylib/feats/compat_run.sh@@ -944,7 +948,7 @@ native-shim-tests:CI_CHECKS := mincheck l10ncheck \sigcheck callscheck webpatch-fixtures peicon-fixtures panel-behavior spawn-env \activatecheck compatcheck compatsvc-check prefixstate-check shortcutcheck launch-shell envcheck \- buildcheck settingscheck routecheck bridgecheck envpasscheck prefixnotecheck powernotecheck gamedrivecheck launchercheck \+ buildcheck settingscheck routecheck bridgecheck envpasscheck prefixnotecheck powernotecheck exitcheck gamedrivecheck launchercheck \seedcheck gamefixescheck versioncheck cicheck padcheck compat-reported-check np-native-tests native-shim-tests \app-tests native-installercheck game-host-check dualsense-check steam-rumble-checkdiff --git a/app/Sources/BridgeplayApp/Model/GameReport.swift b/app/Sources/BridgeplayApp/Model/GameReport.swiftindex a05095a..f870e3f 100644--- a/app/Sources/BridgeplayApp/Model/GameReport.swift+++ b/app/Sources/BridgeplayApp/Model/GameReport.swift@@ -19,12 +19,15 @@ enum GameReport {var macOS: Stringvar bridgeplay: Stringvar setup: [String: String] = [:]+ // A newer release the updater found, "0.7.38 (55)".+ var newerRelease: String?}static var thisMac: Machine {Machine(chip: SetupChecks.chipName, memoryBytes: ProcessInfo.processInfo.physicalMemory,macOS: SetupChecks.macOSDisplay,- bridgeplay: ProductVersion.build.map { "\(ProductVersion.short) (\($0))" } ?? ProductVersion.short)+ bridgeplay: ProductVersion.build.map { "\(ProductVersion.short) (\($0))" } ?? ProductVersion.short,+ newerRelease: LatestRelease.newer(than: ProductVersion.build))}// Facts about the Mac when the report is made, which is soon after the game ran:@@ -103,6 +106,8 @@ enum GameReport {(#"/Volumes/(?!Preboot/|Macintosh HD/)[^/\n:]+"#, "/Volumes/<drive>"),// Wine's view of a home folder whose name differs from the account name.(#"(?i)\b([A-Za-z]:\\+Users\\+)(?!(?:crossover|public|steamuser)\b)[^\\\s:'"]+"#, "$1<user>"),+ // Any other Mac home folder: another account, or the home path spelled differently.+ (#"(?<![\w.~])/Users/(?!Shared(?=[/\s:'"]|$))[^/\s:'"]+"#, "/Users/<user>"),]for name in [user] + computerNames where name.count >= 3 {text = text.replacingOccurrences(of: #"\b\#(NSRegularExpression.escapedPattern(for: name))\b"#,@@ -115,6 +120,42 @@ enum GameReport {return text}+ // Wine's lines for a process that crashed or could not start, as exit_crash_lines in+ // compat_run.sh matches them.+ static let wineErrorPattern =+ #"Unhandled (page fault|exception|illegal instruction|stack overflow)|^wine: (Call from|could not|cannot|failed)|err:module:(import_dll|LdrInitializeThunk)|wine client error"#++ static func wineErrorLines(in text: Substring, limit: Int) -> [String] {+ var found: [String] = []+ for line in text.split(separator: "\n") where found.count < limit {+ // The cheap test first: a long log has hundreds of thousands of lines.+ guard line.contains("Unhandled") || line.hasPrefix("wine: ") || line.contains("err:module:")+ || line.contains("wine client error"),+ line.range(of: wineErrorPattern, options: .regularExpression) != nil else { continue }+ let kept = String(line.prefix(300)).trimmingCharacters(in: .whitespacesAndNewlines)+ if !found.contains(kept) { found.append(kept) }+ }+ return found+ }++ // The newest `limit` characters of a Wine log. Wine's error lines from the part that+ // doesn't fit go first, so a crash early in a long session still reaches the report.+ static func wineTail(_ log: String, limit: Int) -> String {+ guard log.count > limit else { return log }+ // The heading takes room from the tail, and the part that gives way is searched too.+ var keep = limit+ while true {+ let cut = log.index(log.endIndex, offsetBy: -keep)+ let early = wineErrorLines(in: log[..<cut], limit: 20)+ guard !early.isEmpty else { return String(log[cut...]) }+ let head = "--- Wine error lines from earlier in this log ---\n" + early.joined(separator: "\n")+ + "\n--- end of the log ---\n"+ if head.count + keep <= limit { return head + String(log[cut...]) }+ if keep == 0 { return String(head.prefix(limit)) }+ keep = max(0, limit - head.count)+ }+ }+static var thisMacNames: [String] {[SCDynamicStoreCopyComputerName(nil, nil), SCDynamicStoreCopyLocalHostName(nil)].compactMap { $0 as String? }diff --git a/app/Sources/BridgeplayApp/Model/GameSession.swift b/app/Sources/BridgeplayApp/Model/GameSession.swiftindex 1a88603..6f8733c 100644--- a/app/Sources/BridgeplayApp/Model/GameSession.swift+++ b/app/Sources/BridgeplayApp/Model/GameSession.swift@@ -76,17 +76,45 @@ struct GameSession: Equatable, Sendable {GameSession(id: "by hand", started: nil, ended: now, exitStatus: 0, stoppedBySteam: false, byHand: true)}- // English on purpose: it goes into the public report.- func summary(wineLog: String?) -> String {+ // compat_run.sh's account of how this session ended, from its run block:+ // === exit summary: exit status 3 after 75s, the game quit by itself (abort() …) ===+ // === exit cause: wine: Unhandled page fault on read access to … ===+ func exitAccount(in log: String) -> (summary: String, cause: String?)? {+ guard !byHand, id.hasPrefix("=== "), let start = log.range(of: id, options: .backwards)?.lowerBound else { return nil }+ var block = log[start...]+ let rest = block.dropFirst(id.count)+ if let end = ["\n=== bridgeplay run ", "\n=== notproton run "].compactMap({ rest.range(of: $0)?.lowerBound }).min() {+ block = block[..<end]+ }+ func line(_ tag: String) -> String? {+ guard let found = block.range(of: "\n=== \(tag): ") else { return nil }+ let text = block[found.upperBound...].prefix { $0 != "\n" }+ return String(text.hasSuffix(" ===") ? text.dropLast(4) : text)+ }+ guard let summary = line("exit summary") else { return nil }+ return (summary: summary, cause: line("exit cause"))+ }++ // English on purpose: it goes into the public report. The exit summary and Wine's first+ // error line say why the game quit; logs from before the summary give the bare status.+ func summary(log: String? = nil, wineLog: String?) -> String {if byHand { return "Reported from the Prefixes page" }var parts: [String] = []if let seconds { parts.append("Session \(seconds / 60) min") }- if stoppedBySteam {- parts.append("stopped from Steam")+ // The run script already searched the whole Wine log for the cause.+ let cause: String?+ if let account = log.flatMap({ exitAccount(in: $0) }) {+ parts.append(account.summary)+ cause = account.cause} else {- parts.append("exit status \(exitStatus)")+ parts.append(stoppedBySteam ? "stopped from Steam" : "exit status \(exitStatus)")+ cause = wineLog.flatMap { GameReport.wineErrorLines(in: $0[...], limit: 1).first }+ }+ if let cause {+ parts.append("first Wine error: \(GameReport.redacted(cause))")+ } else if Self.wineCrashed(wineLog) {+ parts.append("Wine reported an unhandled exception")}- if Self.wineCrashed(wineLog) { parts.append("Wine reported an unhandled exception") }return parts.joined(separator: ", ")}}diff --git a/app/Sources/BridgeplayApp/Model/PlayReports.swift b/app/Sources/BridgeplayApp/Model/PlayReports.swiftindex c2bd70d..180e6b5 100644--- a/app/Sources/BridgeplayApp/Model/PlayReports.swift+++ b/app/Sources/BridgeplayApp/Model/PlayReports.swift@@ -35,7 +35,8 @@ struct ReportPayload: Codable, Equatable, Sendable {log: String?, wineLog: String?, machine: GameReport.Machine, install: String,note: String? = nil) -> ReportPayload {let launch: (engine: String?, backend: String?) = log.map(GameReport.lastLaunch) ?? (nil, nil)- var summary = session.summary(wineLog: wineLog)+ var summary = session.summary(log: log, wineLog: wineLog)+ if let newer = machine.newerRelease { summary += ". A newer Bridgeplay was out: \(newer)" }if source == .auto { summary += ". Status inferred from the log" }return ReportPayload(appid: appID, status: status, install: install, source: source, name: name,@@ -45,7 +46,7 @@ struct ReportPayload: Codable, Equatable, Sendable {note: note.map { $0.trimmingCharacters(in: .whitespacesAndNewlines) }.flatMap { $0.isEmpty ? nil : String($0.prefix(1000)) },setup: machine.setup.isEmpty ? nil : machine.setup,log: log.map { String(GameReport.redacted($0).suffix(logLimit)) },- wineLog: wineLog.map { String(GameReport.redacted($0).suffix(wineLogLimit)) })+ wineLog: wineLog.map { GameReport.wineTail(GameReport.redacted($0), limit: wineLogLimit) })}}diff --git a/app/Sources/BridgeplayApp/Support/AppUpdater.swift b/app/Sources/BridgeplayApp/Support/AppUpdater.swiftindex 8c142fa..3d0528c 100644--- a/app/Sources/BridgeplayApp/Support/AppUpdater.swift+++ b/app/Sources/BridgeplayApp/Support/AppUpdater.swift@@ -1,3 +1,4 @@+import Foundationimport Sparkle@MainActor@@ -7,6 +8,8 @@ final class AppUpdater {static let shared = AppUpdater()private let controller: SPUStandardUpdaterController+ // Sparkle holds its delegate weakly.+ private let finder: ReleaseFinderinit() {#if DEBUG@@ -14,9 +17,10 @@ final class AppUpdater {#elselet scheduling = true#endif+ finder = ReleaseFinder()controller = SPUStandardUpdaterController(startingUpdater: scheduling,- updaterDelegate: nil,+ updaterDelegate: finder,userDriverDelegate: nil)}@@ -28,3 +32,30 @@ final class AppUpdater {}}++@MainActor+private final class ReleaseFinder: NSObject, SPUUpdaterDelegate {+ func updater(_ updater: SPUUpdater, didFindValidUpdate item: SUAppcastItem) {+ LatestRelease.record(build: item.versionString, version: item.displayVersionString)+ }+}++// The newest release Sparkle has found, so a play report can say the player was behind.+enum LatestRelease {+ static let buildKey = "LatestReleaseBuild"+ static let versionKey = "LatestReleaseVersion"++ static func record(build: String, version: String, defaults: UserDefaults = .standard) {+ defaults.set(build, forKey: buildKey)+ defaults.set(version, forKey: versionKey)+ }++ // "0.7.38 (55)" when the release found is newer than `build`; releases are ordered by+ // build, never by the version label.+ static func newer(than build: String?, defaults: UserDefaults = .standard) -> String? {+ guard let found = defaults.string(forKey: buildKey), let foundBuild = Int(found),+ let build = build.flatMap({ Int($0) }), foundBuild > build else { return nil }+ let version = defaults.string(forKey: versionKey) ?? ""+ return version.isEmpty ? "build \(found)" : "\(version) (\(found))"+ }+}diff --git a/app/Tests/BridgeplayAppTests/GameReportTests.swift b/app/Tests/BridgeplayAppTests/GameReportTests.swiftindex da118b6..4250092 100644--- a/app/Tests/BridgeplayAppTests/GameReportTests.swift+++ b/app/Tests/BridgeplayAppTests/GameReportTests.swift@@ -83,4 +83,22 @@ struct GameReportTests {#expect(text.contains("C:/users/crossover/AppData"))#expect(text.contains("~/Library/x.lock"))}++ @Test("A home folder that isn't spelled like this one's is hidden too")+ func otherHomes() {+ let raw = """+ === exit cause: wine: could not load /Users/josé/Library/x.dll ===+ lsof: /Users/other/Library/y.lock and /Users/tester/z+ STEAM_COMPAT_LIBRARY_PATHS=/Users/Shared/SteamLibrary+ accounts named like it: /Users/Shared-jane/a /Users/Shared.work/b+ only the folder: /Users/Shared+ """+ let text = GameReport.redacted(raw, home: "/Users/tester", user: "tester", computerNames: [])+ #expect(!text.contains("jos") && !text.contains("other") && !text.contains("jane") && !text.contains("work"))+ #expect(text.contains("like it: /Users/<user>/a /Users/<user>/b"))+ #expect(text.contains("only the folder: /Users/Shared"))+ #expect(text.contains("load /Users/<user>/Library/x.dll"))+ #expect(text.contains("lsof: /Users/<user>/Library/y.lock and ~/z"))+ #expect(text.contains("=/Users/Shared/SteamLibrary"))+ }}diff --git a/app/Tests/BridgeplayAppTests/PlayReportsTests.swift b/app/Tests/BridgeplayAppTests/PlayReportsTests.swiftindex def25fe..99996b6 100644--- a/app/Tests/BridgeplayAppTests/PlayReportsTests.swift+++ b/app/Tests/BridgeplayAppTests/PlayReportsTests.swift@@ -109,6 +109,113 @@ struct PlayReportsTests {#expect(make(String(repeating: "x", count: 3000)).note?.count == 1000)#expect(make(nil).setup?["lowPower"] == "off")}++ @Test("The run script's exit summary says why the game quit")+ func exitSummary() throws {+ let ended = Self.local("Wed Oct 21 20:01:15 2026")+ let quit = Self.log("""+ === game exited status=3, killing wine prefix ===+ === exit summary: exit status 3 after 75s, the game quit by itself (likely abort() in the C runtime or a breakpoint, usually after the game's own error message) ===+ === session health: healthy after 75s ===+ """)+ let session = try #require(GameSession.last(in: quit, modified: ended))+ #expect(session.summary(log: quit, wineLog: nil)+ == "Session 1 min, exit status 3 after 75s, the game quit by itself (likely abort() in the C runtime or a breakpoint, usually after the game's own error message)")++ let crashed = Self.log("""+ === game exited status=5, killing wine prefix ===+ === exit summary: exit status 5 after 12s, the game quit by itself (likely 0xc0000005, an access violation: the game crashed) ===+ === exit cause: wine: Unhandled page fault on read access to 0000000000000000 at address 0000000140001234 (thread 0124), starting debugger... ===+ === exit cause: Unhandled exception: page fault on read access to 0x00000000 in 64-bit code (0x0000000140001234). ===+ """)+ let crash = try #require(GameSession.last(in: crashed, modified: ended))+ #expect(crash.summary(log: crashed, wineLog: "no error lines left in this tail")+ == "Session 1 min, exit status 5 after 12s, the game quit by itself (likely 0xc0000005, an access violation: the game crashed), first Wine error: wine: Unhandled page fault on read access to 0000000000000000 at address 0000000140001234 (thread 0124), starting debugger...")+ }++ @Test("Without an exit summary the status stands, and Wine's first error is redacted")+ func exitWithoutSummary() throws {+ // An earlier run's summary is not this session's.+ let log = """+ === bridgeplay run Tue Oct 20 21:00:00 WIB 2026 ===+ === game exited status=0, killing wine prefix ===+ === exit summary: exit status 0 after 30 min, the game quit normally ===+ === bridgeplay run Wed Oct 21 20:00:00 WIB 2026 ===+ === game exited status=53, killing wine prefix ===++ """+ let session = try #require(GameSession.last(in: log, modified: Self.local("Wed Oct 21 20:00:10 2026")))+ #expect(session.exitAccount(in: log) == nil)+ let wineLog = "fixme:a\n0024:err:module:import_dll Library MSVCP140.dll (which is needed by L\"Z:\\\\Users\\\\someone\\\\Game.exe\") not found\n"+ #expect(session.summary(log: log, wineLog: wineLog)+ == "Session 0 min, exit status 53, first Wine error: 0024:err:module:import_dll Library MSVCP140.dll (which is needed by L\"Z:\\\\Users\\\\<user>\\\\Game.exe\") not found")+ #expect(session.summary(log: log, wineLog: "wine: Unhandled exception, no details") == "Session 0 min, exit status 53, first Wine error: wine: Unhandled exception, no details")+ #expect(session.summary(log: log, wineLog: nil) == "Session 0 min, exit status 53")+ }++ @Test("Wine's error lines are found anywhere in the log, once each")+ func wineErrorLines() {+ let log = """+ wine: configuration in L"\\\\??\\\\C:\\\\users\\\\steamuser" has been updated.+ 0118:err:kerberos:kerberos_LsaApInitializePackage no Kerberos support, expect problems+ wine: Call from 00006FFFFFC3A2B8 to unimplemented function api-ms-win-core-foo.dll.Bar, aborting+ wine: Call from 00006FFFFFC3A2B8 to unimplemented function api-ms-win-core-foo.dll.Bar, aborting+ wine client error:3f4: write: Bad file descriptor+ """+ #expect(GameReport.wineErrorLines(in: log[...], limit: 5) == [+ "wine: Call from 00006FFFFFC3A2B8 to unimplemented function api-ms-win-core-foo.dll.Bar, aborting",+ "wine client error:3f4: write: Bad file descriptor",+ ])+ #expect(GameReport.wineErrorLines(in: log[...], limit: 1).count == 1)+ }++ @Test("A crash early in a long Wine log still reaches the report")+ func wineTail() {+ let early = "wine: Unhandled page fault on read access to 0000000000000000 at address 0000000140001234 (thread 0124), starting debugger...\n"+ let log = "fixme:a\n" + early + String(repeating: "trace line\n", count: 50_000) + "last line\n"+ let tail = GameReport.wineTail(log, limit: 1000)+ #expect(tail.count == 1000)+ #expect(tail.hasPrefix("--- Wine error lines from earlier in this log ---\n" + early + "--- end of the log ---\n"))+ #expect(tail.hasSuffix("trace line\nlast line\n"))+ #expect(GameReport.wineTail("short\n", limit: 1000) == "short\n")+ let quiet = String(repeating: "x\n", count: 1000)+ #expect(GameReport.wineTail(quiet, limit: 100) == String(quiet.suffix(100)))++ // A second error just inside the last 1000 characters gives way to the heading, so+ // it moves up into it.+ let late = "wine: could not load late.dll\n"+ let filler = String(repeating: "f", count: 1000 - late.count - 20) + "\n"+ let two = "fixme:a\n" + early + String(repeating: "trace line\n", count: 500) + late + filler+ + String(repeating: "t\n", count: 10)+ let both = GameReport.wineTail(two, limit: 1000)+ #expect(both.count <= 1000)+ #expect(both.contains("wine: could not load late.dll"))+ #expect(both.hasPrefix("--- Wine error lines from earlier in this log ---\n" + early))+ #expect(both.hasSuffix("t\nt\n"))+ }++ @Test("A report says when a newer Bridgeplay was out")+ func newerRelease() throws {+ let name = "latest-release-\(UUID().uuidString)"+ let defaults = try #require(UserDefaults(suiteName: name))+ defer { defaults.removePersistentDomain(forName: name) }+ #expect(LatestRelease.newer(than: "44", defaults: defaults) == nil)+ LatestRelease.record(build: "55", version: "0.7.38", defaults: defaults)+ #expect(LatestRelease.newer(than: "44", defaults: defaults) == "0.7.38 (55)")+ #expect(LatestRelease.newer(than: "55", defaults: defaults) == nil)+ #expect(LatestRelease.newer(than: "56", defaults: defaults) == nil)+ #expect(LatestRelease.newer(than: nil, defaults: defaults) == nil, "an unstamped build")++ var machine = GameReport.Machine(chip: "Apple M2", memoryBytes: 8 * 1_073_741_824,+ macOS: "macOS 27.0.1", bridgeplay: "0.7.0 (44)")+ machine.newerRelease = "0.7.38 (55)"+ let session = GameSession(id: "x", started: Date().addingTimeInterval(-27 * 60), ended: Date(),+ exitStatus: 0, stoppedBySteam: false)+ let payload = ReportPayload.make(name: "Roboquest", appID: "692890", status: .bronze, source: .tap,+ session: session, log: nil, wineLog: nil, machine: machine,+ install: "0F8FAD5B-D9CB-469F-A165-70867728950E")+ #expect(payload.session == "Session 27 min, exit status 0. A newer Bridgeplay was out: 0.7.38 (55)")+ }}// Answers https://report.invalid/<status> with that status; /offline fails like no network.diff --git a/dylib/AGENTS.md b/dylib/AGENTS.mdindex 22a7156..12807a9 100644--- a/dylib/AGENTS.md+++ b/dylib/AGENTS.md@@ -22,7 +22,7 @@ down for the user. The constructor in `core/loader.c` only does work in `steam_oallow-list in `gamefix_reason`, a row in [docs/GAMEFIXES.md](../docs/GAMEFIXES.md), anda passing `make gamefixescheck`.- Checks for the run script: `runcheck`, `envcheck`, `settingscheck`, `routecheck`,- `gamedrivecheck`, `prefixnotecheck`, `powernotecheck`, `launchercheck`, `gamefixescheck`.+ `gamedrivecheck`, `prefixnotecheck`, `powernotecheck`, `exitcheck`, `launchercheck`, `gamefixescheck`.- **Tests** live in `dylib/tests/`. They run without Steam or Dobby; several `#include` the`.c` file under test for that reason. Add a new check as a Makefile target and to thecheck list in `.github/workflows/app.yml`.diff --git a/dylib/feats/compat_run.sh b/dylib/feats/compat_run.shindex e66abcd..1b2297a 100755--- a/dylib/feats/compat_run.sh+++ b/dylib/feats/compat_run.sh@@ -1320,6 +1320,83 @@ record_session() {esac}+# Wine exits with the low byte of the Windows exit code, so 0xc0000005 arrives as 5 and+# 0xc0000135 as 53. A game can also exit with that number itself, so the summary says+# "likely". Codes not listed stay raw.+exit_meaning() {+ case "$1" in+ 1) echo "a generic failure, from the game or from Wine starting it" ;;+ 3) echo "abort() in the C runtime or a breakpoint, usually after the game's own error message" ;;+ 5) echo "0xc0000005, an access violation: the game crashed" ;;+ 9) echo "0xc0000409, the game stopped itself on a fatal error (fail fast or stack buffer overrun)" ;;+ 23) echo "0xc0000417, an invalid parameter to the C runtime" ;;+ 29) echo "0xc000001d, an illegal instruction, often a CPU feature the Mac does not have" ;;+ 53) echo "0xc0000135, a DLL the game needs was not found" ;;+ 66) echo "0xc0000142, a DLL failed to initialize" ;;+ 99) echo "0xe06d7363, a C++ exception nothing caught" ;;+ 116) echo "0xc0000374, heap corruption" ;;+ 253) echo "0xc00000fd, a stack overflow" ;;+ 255) echo "exit code -1, a failure the game reported itself" ;;+ esac+}++# The launcher is a shell, so a Wine process killed by signal N ends with 128+N. Wine+# handles the signals Windows code raises, so these come from the Mac side.+exit_signal() {+ case "$1" in+ 129) echo "SIGHUP" ;;+ 130) echo "SIGINT" ;;+ 132) echo "SIGILL, an illegal instruction in Mac-side code" ;;+ 133) echo "SIGTRAP, a trap in Mac-side code such as Wine, D3DMetal or a macOS framework" ;;+ 134) echo "SIGABRT, an abort in Mac-side code such as Wine, D3DMetal or a macOS framework" ;;+ 136) echo "SIGFPE, an arithmetic error in Mac-side code" ;;+ 137) echo "SIGKILL, killed by macOS or another process; running out of memory is a common cause" ;;+ 138) echo "SIGBUS, a crash in Mac-side code such as Wine, D3DMetal or MoltenVK" ;;+ 139) echo "SIGSEGV, a crash in Mac-side code such as Wine, D3DMetal or MoltenVK" ;;+ 143) echo "SIGTERM, asked to quit from outside Steam" ;;+ esac+}++# The lines Wine prints when a process dies or cannot start. iconv drops invalid bytes, so+# the run log stays UTF-8 for the app, and keeps a home folder with an accented name whole for+# the report's redaction to match.+exit_crash_lines() {+ [ -f "$1" ] || return 0+ grep -a -E -m 3 'Unhandled (page fault|exception|illegal instruction|stack overflow)|^wine: (Call from|could not|cannot|failed)|err:module:(import_dll|LdrInitializeThunk)|wine client error' \+ "$1" 2>/dev/null | LC_ALL=C tr -d '\0-\10\13-\37\177' | LC_ALL=C cut -b 1-300 | iconv -c -f UTF-8 -t UTF-8 2>/dev/null || true+}++# How the game ended, in one line, plus Wine's crash lines. GameSession.swift reads these+# into play reports. Arguments: exit status, seconds, 1 if Steam stopped it, the Wine log.+exit_summary() {+ if [ "$2" -ge 120 ]; then es_took="$(($2 / 60)) min"; else es_took="${2}s"; fi+ es_signal=$(exit_signal "$1")+ es_meaning=$(exit_meaning "$1")+ if [ "$3" = 1 ]; then+ es_how="stopped from Steam"+ elif [ "${NOTPROTON_LAUNCH_SERVICES:-0}" = 1 ]; then+ es_how="started through Launch Services, so the status is open's and not the game's"+ elif [ -n "$es_signal" ]; then+ es_how="Wine was likely killed by $es_signal"+ elif [ "$1" = 0 ] && [ "$2" -lt 60 ]; then+ es_how="the game quit by itself within a minute without an error code, usually after its own error message"+ elif [ "$1" = 0 ]; then+ es_how="the game quit normally"+ elif [ -n "$es_meaning" ]; then+ es_how="the game quit by itself (likely $es_meaning)"+ else+ es_how="the game quit by itself"+ fi+ printf '=== exit summary: exit status %s after %s, %s ===\n' "$1" "$es_took" "$es_how"+ exit_crash_lines "$4" | while IFS= read -r es_line; do+ printf '=== exit cause: %s ===\n' "$es_line"+ done+ # winedbg's "has encountered a serious problem" dialog holds the game open until closed.+ if grep -a -q -E 'starting debugger|exe=winedbg' "$4" 2>/dev/null; then+ echo "=== exit note: Wine started its crash handler, whose error dialog can sit behind the game ==="+ fi+}+# Asked once per switch, at the next launch after the crash.offer_switch_rebuild() {switch="$STEAM_COMPAT_DATA_PATH/notproton-switch"@@ -2814,9 +2891,12 @@ open_pid=$!/usr/bin/caffeinate -d -i -w "$open_pid" >> "$log" 2>&1 &status=0wait "$open_pid" || status=$?+np_ran=$(($(date +%s) - np_started))echo "=== game exited status=$status, killing wine prefix ===" >> "$log" 2>&1 || truekill_wine_prefix[ -z "$STEAM_COMPAT_DATA_PATH" ] \|| record_session "$loader_root/bridgeplay-wine.log" "$(($(date +%s) - np_started))" "$np_terminated"+# After the teardown, so reading a long Wine log never holds the prefix up.+exit_summary "$status" "$np_ran" "$np_terminated" "$loader_root/bridgeplay-wine.log" >> "$log" 2>&1 || trueecho "=== wine prefix killed, session ending ===" >> "$log" 2>&1 || trueexit $statusdiff --git a/dylib/tests/exitcheck.sh b/dylib/tests/exitcheck.shnew file mode 100644index 0000000..f3ac167--- /dev/null+++ b/dylib/tests/exitcheck.sh@@ -0,0 +1,104 @@+#!/bin/sh+# exitcheck: the run script's account of how a game ended (exit_summary in compat_run.sh),+# which play reports quote.+set -e+SRC="${1:-$(dirname "$0")/../feats/compat_run.sh}"+[ -f "$SRC" ] || { echo "exitcheck: $SRC not present, skipped"; exit 0; }++extract() { sed -n "/^$1() {\$/,/^}\$/p" "$SRC"; }+functions=""+for name in exit_meaning exit_signal exit_crash_lines exit_summary; do+ body=$(extract "$name")+ [ -n "$body" ] || { echo "FAIL: $name not found in $SRC"; exit 1; }+ functions="$functions+$body"+done+eval "$functions"++work=$(mktemp -d)+trap 'rm -rf "$work"' EXIT++fails=0+ok() { printf ' ok %s\n' "$1"; }+bad() { printf ' FAIL %s\n want [%s]\n got [%s]\n' "$1" "$2" "$3"; fails=$((fails + 1)); }+is() { if [ "$2" = "$3" ]; then ok "$1"; else bad "$1" "$2" "$3"; fi; }++clean="$work/clean.log"+printf '0118:err:kerberos:kerberos_LsaApInitializePackage no Kerberos support, expect problems\n' > "$clean"+unset NOTPROTON_LAUNCH_SERVICES+summary() { exit_summary "$1" "$2" "$3" "${4:-$clean}"; }++echo "== how the game ended =="+is "abort() after the game's own dialog (Mewgenics)" \+ "=== exit summary: exit status 3 after 75s, the game quit by itself (likely abort() in the C runtime or a breakpoint, usually after the game's own error message) ===" \+ "$(summary 3 75 0)"+is "exit -1 (SCP: Containment Breach)" \+ "=== exit summary: exit status 255 after 19s, the game quit by itself (likely exit code -1, a failure the game reported itself) ===" \+ "$(summary 255 19 0)"+is "a quick clean quit is suspicious (Plants vs. Zombies)" \+ "=== exit summary: exit status 0 after 24s, the game quit by itself within a minute without an error code, usually after its own error message ===" \+ "$(summary 0 24 0)"+is "a long session that ends cleanly, in minutes (Roboquest)" \+ "=== exit summary: exit status 0 after 27 min, the game quit normally ===" \+ "$(summary 0 1642 0)"+is "Steam's Exit Game wins over the status" \+ "=== exit summary: exit status 143 after 6s, stopped from Steam ===" \+ "$(summary 143 6 1)"+is "SIGTERM from outside Steam" \+ "=== exit summary: exit status 143 after 30s, Wine was likely killed by SIGTERM, asked to quit from outside Steam ===" \+ "$(summary 143 30 0)"+is "a Mac-side crash is a signal, not a Windows code" \+ "=== exit summary: exit status 139 after 5s, Wine was likely killed by SIGSEGV, a crash in Mac-side code such as Wine, D3DMetal or MoltenVK ===" \+ "$(summary 139 5 0)"+is "the low byte of 0xc0000135" \+ "=== exit summary: exit status 53 after 2s, the game quit by itself (likely 0xc0000135, a DLL the game needs was not found) ===" \+ "$(summary 53 2 0)"+is "an unknown code stays raw" \+ "=== exit summary: exit status 42 after 10s, the game quit by itself ===" \+ "$(summary 42 10 0)"+is "Launch Services hides the game's status" \+ "=== exit summary: exit status 0 after 10s, started through Launch Services, so the status is open's and not the game's ===" \+ "$(export NOTPROTON_LAUNCH_SERVICES=1; summary 0 10 0)"+is "a missing Wine log adds nothing" \+ "=== exit summary: exit status 5 after 3s, the game quit by itself (likely 0xc0000005, an access violation: the game crashed) ===" \+ "$(summary 5 3 0 "$work/none.log")"++echo "== Wine's crash lines =="+crash="$work/crash.log"+{+ printf 'overlay_shim_load: pid=91135 exe=wine layer_hooks=3 overlay=present\n'+ printf '0024:err:module:import_dll Library MSVCP140.dll (which is needed by L"Z:\\\\Users\\\\someone\\\\Game.exe") not found\n'+ printf 'wine: Unhandled page fault on read access to 0000000000000000 at address 0000000140001234 (thread 0124), starting debugger...\n'+ printf 'overlay_shim_load: pid=91140 exe=winedbg layer_hooks=3 overlay=present\n'+ printf 'Unhandled exception: page fault on read access to 0x00000000 in 64-bit code (0x0000000140001234).\n'+ printf 'wine: Unhandled page fault again\n'+} > "$crash"+is "the first three crash lines follow the summary, then the crash handler" \+ "=== exit summary: exit status 5 after 12s, the game quit by itself (likely 0xc0000005, an access violation: the game crashed) ===+=== exit cause: 0024:err:module:import_dll Library MSVCP140.dll (which is needed by L\"Z:\\\\Users\\\\someone\\\\Game.exe\") not found ===+=== exit cause: wine: Unhandled page fault on read access to 0000000000000000 at address 0000000140001234 (thread 0124), starting debugger... ===+=== exit cause: Unhandled exception: page fault on read access to 0x00000000 in 64-bit code (0x0000000140001234). ===+=== exit note: Wine started its crash handler, whose error dialog can sit behind the game ===" \+ "$(summary 5 12 0 "$crash")"++odd="$work/odd.log"+long=$(printf '%0400d' 0)+{+ printf 'wine: could not load /Users/jos\303\251/Library/\377x.dll\r\n'+ printf 'wine: cannot find %s\n' "$long"+ printf 'wine: configuration in L"\\\\??\\\\C:\\\\users" has been updated.\n'+ # The cut falls inside the two bytes of the last character.+ printf 'wine: failed %s\303\251\n' "$(printf '%0286d' 0)"+} > "$odd"+lines=$(exit_crash_lines "$odd")+is "a home folder keeps its accents for redaction; invalid bytes and carriage returns go" \+ "wine: could not load /Users/josé/Library/x.dll" "$(printf '%s\n' "$lines" | sed -n 1p)"+is "a long line is cut" 300 "$(printf '%s\n' "$lines" | sed -n 2p | tr -d '\n' | wc -c | tr -d ' ')"+is "only crash lines are kept" 3 "$(printf '%s\n' "$lines" | wc -l | tr -d ' ')"+is "what is kept is valid UTF-8" yes "$(printf '%s\n' "$lines" | iconv -f UTF-8 -t UTF-8 >/dev/null 2>&1 && echo yes || echo no)"++if [ "$fails" -ne 0 ]; then+ echo "exitcheck: $fails failure(s)"+ exit 1+fi+echo "==> exitcheck: exit summaries read as expected"diff --git a/dylib/tests/launchercheck.sh b/dylib/tests/launchercheck.shindex 1f1b374..35947c8 100644--- a/dylib/tests/launchercheck.sh+++ b/dylib/tests/launchercheck.sh@@ -274,8 +274,9 @@ session_wait=$(sed -n '/^if \[ "\${NOTPROTON_LAUNCH_SERVICES:-0}" = "1" \]; then{printf 'log=%s\nopen() { sleep "$1"; return "$2"; }\n' "$T/session.log"printf 'kill_wine_prefix() { echo kill >> "%s"; }\n' "$T/session.ev"+ printf 'exit_summary() { echo "summary $1 $3" >> "%s"; }\n' "$T/session.ev"printf '%s\n' "$session_trap"- printf 'set -- "$1" "$2"\nloader_app=x\nNOTPROTON_LAUNCH_SERVICES=1\n'+ printf 'set -- "$1" "$2"\nloader_app=x\nnp_terminated=0\nNOTPROTON_LAUNCH_SERVICES=1\n'printf '%s\n' "$session_wait" | sed 's/open -n -W -a "\$loader_app" "\$@"/open "$@"/'} > "$T/session.sh"grep -q '^ *open "\$@"' "$T/session.sh" || { echo "FAIL: session launch line not rewritten"; exit 1; }@@ -284,7 +285,8 @@ start=$(date +%s)rc=0; sh "$T/session.sh" 3 7 || rc=$?is "the shim's exit status is the session's" 7 "$rc"is "the session waits for the shim" yes "$([ $(($(date +%s) - start)) -ge 3 ] && echo yes || echo no)"-is "the prefix is torn down once" kill "$(cat "$T/session.ev")"+is "the prefix is torn down once, then the exit is summed up" "kill+summary 7 0" "$(cat "$T/session.ev")": > "$T/session.ev"start=$(date +%s)sh "$T/session.sh" 30 0 & sp=$!@@ -294,6 +296,7 @@ rc=0; wait "$sp" || rc=$?is "exit game ends the session" 143 "$rc"is "exit game does not wait out the shim" yes "$([ $(($(date +%s) - start)) -lt 5 ] && echo yes || echo no)"is "exit game tears the prefix down" yes "$(grep -q kill "$T/session.ev" && echo yes || echo no)"+is "exit game is summed up as stopped from Steam" "summary 143 1" "$(grep summary "$T/session.ev")"[ "$fails" -eq 0 ] || { echo "launchercheck: $fails failed"; exit 1; }echo "launchercheck: all passed"