mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 04:55:44 +00:00
Keep Windows games out of their own Android process
Wine's loader was handed to a worker for every Windows program, so a game ran as an app process of its own and Android sampled its whole RSS alone. ZTE's ROM (DefendManagerService) SIGKILLs a background non-system app process whose last two RSS samples are past 3.2 GB on a 16 GB device, foreground service or not: Like a Dragon: Pirate Yakuza in Hawaii (3.6 GB) died six minutes after the screen went off during sleep, and the session found it gone on wake. Hand Wine's loader off only for Wine's own programs, whose command line starts with C:\windows\. A game, its launcher and its tools stay children of the Wine process that started them.
This commit is contained in:
1 parent
b072cedd16
commit
3211c91e30
3 files changed
+70
No files matched your search
@@ -289,6 +289,14 @@ vfork-safe (Python's subprocess execs under `vfork`). Details that mattered:
|
||||
Default list: the portals, at-spi, `python3`, PipeWire, WirePlumber, Decky's PluginLoader, the log's
|
||||
`gnudd`, `xprop -spy`, the web helper's renderers, `wine`, `wine-preloader`, `wineserver`.
|
||||
|
||||
Wine's loader is handed off only for Wine's own programs, those whose command line starts with
|
||||
`C:\windows\` (its services, `explorer.exe`, Proton's `steam.exe`). A game, its launcher and its
|
||||
tools stay children of the Wine process that started them and are counted. Android samples a
|
||||
worker's RSS as an app process's own, and ZTE's ROM (`DefendManagerService`, on Nubia and
|
||||
Red Magic devices) SIGKILLs a non-system app's process whose last two samples, five minutes apart, are
|
||||
past a size set by the device's RAM (3.2 GB at 16 GB) while the app shows no window, foreground
|
||||
service or not. A game in a worker died that way six minutes after the screen went off.
|
||||
|
||||
Measured on the Thor, same session and game as above:
|
||||
|
||||
| | counted children, idle | counted, Bully (Proton) running |
|
||||
|
||||
@@ -1132,9 +1132,37 @@ static int ddh_all_utf8(char *const v[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
// A Wine loader starting a Windows program from outside C:\windows: a game, its launcher or its tools,
|
||||
// as opposed to Wine's own services and Proton's steam.exe. Wine execs its loader with the program's
|
||||
// command line after the loader paths (dlls/ntdll/unix/process.c), so the first argument that is not an
|
||||
// absolute Linux path names the program. Such a program stays a child of the Wine process that started
|
||||
// it: Android samples an app process's RSS on its own, and some ROMs kill a background app process past
|
||||
// a fixed size whatever its importance (ZTE's DefendManagerService: 3.2 GB on a 16 GB device, checked
|
||||
// every 5 minutes), while a child's memory is in no app process's sample.
|
||||
static int ddh_windows_program_outside_wine(const char *filename, char *const argv[]) {
|
||||
static const char *const loaders[] = {"wine", "wine64", "wine-preloader", "wine64-preloader"};
|
||||
static const char windir[] = "c:\\windows\\";
|
||||
const char *prog = ddh_base(filename);
|
||||
size_t k = 0;
|
||||
while (k < sizeof(loaders) / sizeof(loaders[0]) && (!prog || strcmp(prog, loaders[k]) != 0)) k++;
|
||||
if (k == sizeof(loaders) / sizeof(loaders[0])) return 0;
|
||||
for (int i = 1; argv && argv[i]; i++) {
|
||||
const char *arg = argv[i];
|
||||
if (arg[0] == '/') continue;
|
||||
for (size_t j = 0; j < sizeof(windir) - 1; j++) {
|
||||
char c = arg[j] >= 'A' && arg[j] <= 'Z' ? (char)(arg[j] - 'A' + 'a') : arg[j] == '/' ? '\\' : arg[j];
|
||||
if (c != windir[j]) return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ddh_program_listed(const char *list, const char *filename, char *const argv[]) {
|
||||
char shebang[256];
|
||||
const char *interp;
|
||||
if (ddh_windows_program_outside_wine(filename, argv) || ddh_windows_program_outside_wine(argv ? argv[0] : NULL, argv))
|
||||
return 0;
|
||||
// "python3 SCRIPT" and "sh SCRIPT" are matched by the script's name too (and only an
|
||||
// interpreter's: "pidof wineserver" is not wineserver)
|
||||
const char *prog = ddh_base(filename);
|
||||
@@ -1248,6 +1276,8 @@ static int ddh_waiter(pid_t pid) {
|
||||
// (droiddeck-seed-redists alone about 17 within a second), and each would be an app process of its own,
|
||||
// a zygote fork and a bind, for a few milliseconds of work while the game starts. Counted for those
|
||||
// milliseconds instead. Only tools that end on their own: not tail (-f), tee, sleep, timeout or env.
|
||||
//
|
||||
// Nor a Windows program from outside C:\windows (ddh_windows_program_outside_wine).
|
||||
static int ddh_pressure_keeps(const char *filename, char *const argv[]) {
|
||||
static const char *const kept[] = {"steam", "steam.sh", "steamwebhelper", "droiddeck-steam-x64", "reaper",
|
||||
"steam-launch-wrapper", "pw-audio-namespace", "gamescope", "gamescopereaper"};
|
||||
@@ -1255,6 +1285,7 @@ static int ddh_pressure_keeps(const char *filename, char *const argv[]) {
|
||||
"gawk", "grep", "head", "id", "jq", "ls", "mawk", "mkdir", "mktemp", "pgrep",
|
||||
"pidof", "printf", "ps", "readlink", "realpath", "rm", "sed", "seq", "sort",
|
||||
"stat", "touch", "tr", "uname", "uniq", "wc", "xprop"};
|
||||
if (ddh_windows_program_outside_wine(filename, argv)) return 1;
|
||||
if (filename) {
|
||||
for (size_t k = 0; k < sizeof(quick) / sizeof(quick[0]); k++) {
|
||||
if (strcmp(ddh_base(filename), quick[k]) == 0) return 1;
|
||||
|
||||
@@ -952,6 +952,11 @@ int main(int argc, char **argv) {
|
||||
execv("/bin/target", args);
|
||||
_exit(127);
|
||||
}
|
||||
if (strcmp(argv[1], "wine") == 0) {
|
||||
// as Wine starts a Windows program: its loader's path, then the program's command line
|
||||
execl("/bin/wine", "wine", "/opt/wine/bin/wine", argv[3], argv[2], (char *)NULL);
|
||||
_exit(127);
|
||||
}
|
||||
execl(argc > 3 ? argv[3] : "/bin/target", "target", argv[2], (char *)NULL);
|
||||
_exit(127);
|
||||
}
|
||||
@@ -1902,6 +1907,32 @@ class NativeHookHandoffTest(unittest.TestCase):
|
||||
self.assertEqual("1", result.get("same"), out.stdout)
|
||||
self.assertEqual(self.child_status, result.get("exit"), out.stdout)
|
||||
|
||||
def run_wine(self, command_line, **kwargs):
|
||||
wine = self.root / "bin/wine"
|
||||
if not wine.exists():
|
||||
shutil.copy(self.root / "bin/target", wine)
|
||||
return self.run_parent("wine", "7", command_line, handoff="wine", **kwargs)
|
||||
|
||||
def test_wines_own_program_is_handed_off(self):
|
||||
for command_line in ("C:\\windows\\system32\\services.exe", "c:\\windows\\system32\\steam.exe"):
|
||||
with self.subTest(command_line):
|
||||
result, requests, out = self.run_wine(command_line)
|
||||
self.assertEqual(1, len(requests), out.stderr)
|
||||
self.assertEqual(["wine", "/opt/wine/bin/wine", command_line, "7"], requests[0]["argv"])
|
||||
|
||||
def test_a_windows_program_from_outside_c_windows_is_not_handed_off(self):
|
||||
# a game: Android would sample its memory as an app process's own
|
||||
for command_line in ("LikeADragonPirates.exe", "S:\\steamapps\\common\\Game\\startup.exe",
|
||||
".\\crashreport\\crashpad_handler.exe", "C:\\windowsapps\\game.exe"):
|
||||
with self.subTest(command_line):
|
||||
result, requests, out = self.run_wine(command_line)
|
||||
self.assertEqual([], requests, out.stderr)
|
||||
self.assertEqual("1", result.get("same"), out.stdout)
|
||||
|
||||
def test_near_the_limit_a_windows_program_from_outside_c_windows_is_not_handed_off(self):
|
||||
result, requests, out = self.run_wine("LikeADragonPirates.exe", pressure=0, as_shell=True)
|
||||
self.assertEqual([], requests, out.stderr)
|
||||
|
||||
def test_a_wait_of_another_thread_with_wnothread_does_not_take_the_program(self):
|
||||
result, requests, out = self.run_parent("nothread", "7")
|
||||
self.assertEqual(1, len(requests), out.stderr)
|
||||
|
||||
Reference in new issue
Block a user