Run Windows games on Apple Silicon — free, open source, with an open compatibility database that tells you what actually works.
Swift apple-silicond3dmetaldxmtdxvkfexgame-porting-toolkitgamingmac-gamingmacosmetalmoltenvksteamswiftuivkd3d-protonwhisky-alternativewindows-gameswinewine-wrapper
launch: restart an idle environment whose Windows services were booted under another stack (highball#124)
Gauthier Piarrette7688c00d352c
diff --git a/Sources/HighballKit/ProcessTable.swift b/Sources/HighballKit/ProcessTable.swiftindex 84b13e3..caf08f5 100644--- a/Sources/HighballKit/ProcessTable.swift+++ b/Sources/HighballKit/ProcessTable.swift@@ -119,6 +119,39 @@ public enum ProcessTable {return SyncMode(environment: env)}+ /// The environment a running wineserver was started with, nil when none runs. Wine's+ /// `services.exe` and every Windows service it starts inherit exactly this environment,+ /// however the service was later asked for, because the prefix boots them once from the+ /// first process that started the server.+ public static func liveServerEnvironment(forPrefix prefix: URL) -> [String: String]? {+ guard let pid = liveServer(forPrefix: prefix) else { return nil }+ return commandLineAndEnvironment(of: pid)?.environment+ }++ /// Whether nothing but Wine's own plumbing and Windows services runs in the prefix, so the+ /// server can be restarted without ending anything a person started.+ ///+ /// The tell is the working directory: `services.exe`, `winedevice.exe`, `plugplay.exe`,+ /// `rpcss.exe`, `svchost.exe` and `explorer.exe` work in `drive_c/windows`, and services.exe+ /// starts every Windows service there too (Rockstar's, EA's, anti-cheat services; measured+ /// 2026-09-18). Programs Highball or a launcher started work in their own folder. Pure, so+ /// it is tested without processes.+ public static func isIdle(workingDirectories: [String], prefix: String, serverDirectory: String?) -> Bool {+ let root = prefix.hasSuffix("/") ? prefix : prefix + "/"+ let windows = root + "drive_c/windows"+ return workingDirectories.allSatisfy { cwd in+ if let server = serverDirectory, cwd == server || cwd.hasPrefix(server + "/") { return true }+ return cwd == windows || cwd.hasPrefix(windows + "/")+ }+ }++ public static func isIdle(prefix: URL) -> Bool {+ let root = canonical(prefix.path)+ let server = serverDirectory(forPrefix: prefix).map { canonical($0.path) }+ let cwds = processes(ofPrefix: prefix).compactMap { workingDirectory(of: $0) }.map(canonical)+ return isIdle(workingDirectories: cwds, prefix: root, serverDirectory: server)+ }+/// Ends the given processes: SIGTERM, a grace period, then SIGKILL for whatever is left./// Returns the ids that had to be killed the hard way.@discardableResultdiff --git a/Sources/HighballKit/WineRunner.swift b/Sources/HighballKit/WineRunner.swiftindex bb60d59..b2c7aa0 100644--- a/Sources/HighballKit/WineRunner.swift+++ b/Sources/HighballKit/WineRunner.swift@@ -229,7 +229,42 @@ public struct WineRunner: Sendable {public func start(_ executable: URL, arguments: [String] = [], renderer: Renderer? = nil, extraEnvironment: [String: String] = [:], workingDirectory: URL? = nil, headerNote: String? = nil, onOutput: (@Sendable (String) -> Void)? = nil) async throws -> LaunchResult {await syncDllOverridesRegistry()await syncKeyboardRegistry()- return try await run([executable.path] + arguments, renderer: renderer, extraEnvironment: extraEnvironment, label: executable.lastPathComponent, workingDirectory: workingDirectory, headerNote: headerNote, onOutput: onOutput)+ var note = headerNote+ if let rebooted = try await rebootIdleEnvironmentIfMismatched(renderer: renderer, extraEnvironment: extraEnvironment) {+ onOutput?("note: \(rebooted)")+ note = [headerNote, rebooted].compactMap { $0 }.joined(separator: "; ")+ }+ return try await run([executable.path] + arguments, renderer: renderer, extraEnvironment: extraEnvironment, label: executable.lastPathComponent, workingDirectory: workingDirectory, headerNote: note, onOutput: onOutput)+ }++ /// Restarts the environment's Wine server before a program launch when the server, and so+ /// every Windows service in it, was booted under a different stack than this launch gets,+ /// and nothing a person started is running. Returns the note for the log, nil when the+ /// server serves as is or does not run.+ ///+ /// A prefix boots `services.exe` once, from whichever process starts the server, and every+ /// service it later starts inherits that first environment, not the launching program's.+ /// On a fresh environment that process is a setup step (the first boot, a registry write,+ /// an installer), all of which run without a renderer overlay. The Rockstar launcher's+ /// self-update then restarts it through its own service, so the restarted launcher and its+ /// browser ran under wined3d and the Sign In window stayed empty on every first launch+ /// after install (highball#124, measured 2026-09-18: `services.exe` and the restarted+ /// launcher had no WINEDLLPATH_PREPEND while the launch that started it did). A stop and a+ /// second Play fixed it, which is what this does on its own. Never while something a+ /// person started is running: a wrong stack for the services beats ending their program,+ /// and that case is noted instead.+ func rebootIdleEnvironmentIfMismatched(renderer: Renderer?, extraEnvironment: [String: String]) async throws -> String? {+ guard let live = ProcessTable.liveServerEnvironment(forPrefix: bottle.url) else { return nil }+ let wanted = try bottle.environment(engine: engine, renderer: renderer, extra: extraEnvironment)+ guard let why = SteamRestart.reason(live: live, wanted: wanted,+ wantedRenderer: (renderer ?? bottle.settings.renderer).rawValue,+ custom: Array(bottle.settings.environment.keys)) else { return nil }+ guard ProcessTable.isIdle(prefix: bottle.url) else {+ return "the environment's Windows services keep the stack they started with (\(why)); a program is still running, so the environment was not restarted"+ }+ _ = try kill()+ try? await Task.sleep(for: .seconds(2))+ return "restarted the environment before the launch so its Windows services get this stack: \(why)"}/// Runs the pinned program, honouring its own renderer/env/args.diff --git a/Tests/HighballKitTests/ProcessTableIdleTests.swift b/Tests/HighballKitTests/ProcessTableIdleTests.swiftnew file mode 100644index 0000000..bbaead0--- /dev/null+++ b/Tests/HighballKitTests/ProcessTableIdleTests.swift@@ -0,0 +1,40 @@+import XCTest+@testable import HighballKit++final class ProcessTableIdleTests: XCTestCase {+ private let prefix = "/Users/me/Library/Application Support/Highball/bottles/games"+ private let server = "/private/tmp/.wine-501/server-100000f-1db1d89"++ func testWinePlumbingAndServicesAreIdle() {+ // services.exe, winedevice, plugplay, rpcss, svchost work in drive_c/windows, explorer in+ // system32, a Windows service (RockstarService.exe) in drive_c/windows too (measured).+ let cwds = [server, prefix + "/drive_c/windows", prefix + "/drive_c/windows",+ prefix + "/drive_c/windows/system32", prefix + "/drive_c/windows"]+ XCTAssertTrue(ProcessTable.isIdle(workingDirectories: cwds, prefix: prefix, serverDirectory: server))+ }++ func testNoProcessesIsIdle() {+ XCTAssertTrue(ProcessTable.isIdle(workingDirectories: [], prefix: prefix, serverDirectory: server))+ }++ func testAProgramInItsOwnFolderIsNotIdle() {+ let cwds = [server, prefix + "/drive_c/windows", prefix + "/drive_c/Program Files/Rockstar Games/Launcher"]+ XCTAssertFalse(ProcessTable.isIdle(workingDirectories: cwds, prefix: prefix, serverDirectory: server))+ }++ func testASteamClientIsNotIdle() {+ let cwds = [server, prefix + "/drive_c/windows", prefix + "/drive_c/Program Files (x86)/Steam"]+ XCTAssertFalse(ProcessTable.isIdle(workingDirectories: cwds, prefix: prefix, serverDirectory: server))+ }++ func testAFolderNamedLikeWindowsOutsideItIsNotIdle() {+ // "drive_c/windowsgame" must not pass as "drive_c/windows".+ let cwds = [prefix + "/drive_c/windowsgame"]+ XCTAssertFalse(ProcessTable.isIdle(workingDirectories: cwds, prefix: prefix, serverDirectory: server))+ }++ func testServerWithoutDirectoryStillClassifies() {+ XCTAssertTrue(ProcessTable.isIdle(workingDirectories: [prefix + "/drive_c/windows"], prefix: prefix, serverDirectory: nil))+ XCTAssertFalse(ProcessTable.isIdle(workingDirectories: [server], prefix: prefix, serverDirectory: nil))+ }+}