mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 14:26:00 +00:00
fix(input): fakeinput no longer aborts programs whose allocator calls a hooked function at startup (#2361)
* fix(input): fakeinput no longer aborts programs whose allocator calls a hooked function at startup * fix(ctl): screenshot finds display ids that the device name carries inline * fix(input): fakeinput registers its fork handlers before other threads see its config
This commit is contained in:
1 parent
75a0230304
commit
c85b84a964
4 files changed
+100
-17
No files matched your search
@@ -328,6 +328,15 @@ class DroiddeckctlTest(FakeAdbTest):
|
||||
self.assertEqual("222", out["displays"][1]["physicalId"])
|
||||
self.assertEqual([1080, 1240], out["displays"][1]["size"])
|
||||
|
||||
def test_displays_named_with_their_unique_id(self):
|
||||
text = DUMPSYS_DISPLAY.replace("mPrimaryDisplayDevice=Screen-2",
|
||||
"mPrimaryDisplayDevice=Screen-2(local:222)")
|
||||
self.configure({}, dumpsys_display=text)
|
||||
code, out = self.run_ctl("screenshot", str(self.dir / "shot.png"), "--display", "4")
|
||||
self.assertEqual(0, code)
|
||||
shot = [c for c in self.calls() if c["args"][:2] == ["exec-out", "screencap"]][0]
|
||||
self.assertEqual(["exec-out", "screencap", "-p", "-d", "222"], shot["args"])
|
||||
|
||||
def test_unknown_display_is_an_error(self):
|
||||
self.configure({}, dumpsys_display=DUMPSYS_DISPLAY)
|
||||
code, out = self.run_ctl("screenshot", str(self.dir / "x.png"), "--display", "9")
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
from pathlib import Path
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
SOURCE = Path(__file__).resolve().parents[2] / "app/src/main/cpp/fakeinput_steam.cpp"
|
||||
|
||||
# Stands in for an allocator like mimalloc that calls access() while it starts up (Claude Code
|
||||
# probes /sys/devices/system/node/node1 on its first allocation, which comes from fakeinput's
|
||||
# constructor when it is preloaded).
|
||||
PROGRAM = r"""
|
||||
#define _GNU_SOURCE
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
extern void *__libc_malloc(size_t);
|
||||
static int started;
|
||||
|
||||
void *malloc(size_t size) {
|
||||
if (!started) {
|
||||
started = 1;
|
||||
access("/sys/devices/system/node/node1", R_OK);
|
||||
}
|
||||
return __libc_malloc(size);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
puts("ok");
|
||||
return 0;
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
@unittest.skipUnless(sys.platform == "linux" and shutil.which("gcc") and shutil.which("g++"),
|
||||
"needs Linux, gcc and g++")
|
||||
class FakeinputReentryTest(unittest.TestCase):
|
||||
def test_allocator_calling_hooks_during_first_allocation_survives_preload(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
path = Path(tmp)
|
||||
(path / "program.c").write_text(PROGRAM)
|
||||
subprocess.run(["gcc", "-rdynamic", "-o", str(path / "program"), str(path / "program.c")], check=True)
|
||||
subprocess.run(["g++", "-shared", "-fPIC", "-O2", "-Wno-attributes", "-pthread",
|
||||
"-std=c++17", "-static-libstdc++", "-static-libgcc",
|
||||
"-Wl,--exclude-libs,ALL", "-o", str(path / "libfakeinput.so"),
|
||||
str(SOURCE), "-ldl"], check=True)
|
||||
result = subprocess.run([str(path / "program")],
|
||||
env=dict(os.environ, LD_PRELOAD=str(path / "libfakeinput.so")),
|
||||
capture_output=True, text=True, timeout=10)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(result.stdout, "ok\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user