mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-05 12:35:42 +00:00
fix(preload): Steam's overlay finds the robust list in Wine games without proot (#3577)
thread_robust_head() read the candidate list heads with process_vm_readv(getpid()).
In Wine games run without proot, and in any process whose first thread has exited,
that read fails with ESRCH, so the emulated get_robust_list answered ENOSYS and
Steam's arm64 gameoverlayrenderer.so aborted the game ("futex robust_list not
initialized by pthreads"). The read now goes through gettid().
This commit is contained in:
1 parent
e04e38b44c
commit
80dbec57d7
2 files changed
+88
-1
No files matched your search
@@ -140,7 +140,7 @@ static struct robust_list_head *thread_robust_head(void) {
|
||||
if ((uintptr_t)candidate & (sizeof(void *) - 1)) {
|
||||
continue;
|
||||
}
|
||||
if (process_vm_readv(getpid(), &local, 1, &remote, 1, 0) != (ssize_t)sizeof(copy)) {
|
||||
if (process_vm_readv(gettid(), &local, 1, &remote, 1, 0) != (ssize_t)sizeof(copy)) {
|
||||
continue;
|
||||
}
|
||||
uintptr_t entry = (uintptr_t)copy.list.next;
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
from pathlib import Path
|
||||
import os
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
PRELOAD = Path(__file__).resolve().parents[1] / "linuxfs/preload"
|
||||
|
||||
PROGRAM = r"""
|
||||
#define _GNU_SOURCE
|
||||
#include <errno.h>
|
||||
#include <linux/futex.h>
|
||||
#include <pthread.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static int ask(const char *name) {
|
||||
struct robust_list_head *head = NULL;
|
||||
size_t len = 0;
|
||||
errno = 0;
|
||||
long ret = syscall(SYS_get_robust_list, 0, &head, &len);
|
||||
int ok = ret == 0 && head != NULL && len == sizeof(*head) && head->futex_offset < 0;
|
||||
printf("%s %s ret=%ld errno=%d len=%zu\n", name, ok ? "ok" : "failed", ret, errno, len);
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int leader_gone(void) {
|
||||
char line[256];
|
||||
FILE *status = fopen("/proc/self/status", "r");
|
||||
int zombie = 0;
|
||||
while (status && fgets(line, sizeof line, status))
|
||||
if (!strncmp(line, "State:", 6)) zombie = strchr(line, 'Z') != NULL;
|
||||
if (status) fclose(status);
|
||||
return zombie;
|
||||
}
|
||||
|
||||
static void *after_leader(void *unused) {
|
||||
(void)unused;
|
||||
for (int i = 0; i < 200 && !leader_gone(); i++) usleep(10000);
|
||||
printf("leader %s\n", leader_gone() ? "zombie" : "alive");
|
||||
exit(ask("after-leader-exit") ? 0 : 1);
|
||||
}
|
||||
|
||||
static void *thread(void *unused) {
|
||||
(void)unused;
|
||||
return (void *)(long)ask("thread");
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
pthread_t t;
|
||||
void *ok;
|
||||
if (!ask("main")) return 1;
|
||||
pthread_create(&t, NULL, thread, NULL);
|
||||
pthread_join(t, &ok);
|
||||
if (!ok) return 1;
|
||||
pthread_create(&t, NULL, after_leader, NULL);
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
class RobustListAfterLeaderExit(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.tmp = Path(tempfile.mkdtemp())
|
||||
cls.lib = cls.tmp / "librobust.so"
|
||||
subprocess.run(["cc", "-O2", "-Wall", "-Werror", "-fPIC", "-shared", "-pthread", "-o", str(cls.lib),
|
||||
str(PRELOAD / "robust.c"), str(PRELOAD / "fsync.c"), str(PRELOAD / "noexec.c"),
|
||||
str(PRELOAD / "writewatch.c"), str(PRELOAD / "clockpause.c"), "-ldl"], check=True)
|
||||
source = cls.tmp / "robust.c"
|
||||
source.write_text(PROGRAM)
|
||||
subprocess.run(["cc", "-O2", "-Wall", "-Werror", "-pthread", "-o", str(cls.tmp / "robust"), str(source)],
|
||||
check=True)
|
||||
|
||||
def test_every_thread_gets_its_list_after_the_first_thread_exits(self):
|
||||
result = subprocess.run([str(self.tmp / "robust")], capture_output=True, text=True, timeout=30,
|
||||
env=dict(os.environ, LD_PRELOAD=str(self.lib)))
|
||||
self.assertIn("leader zombie", result.stdout)
|
||||
self.assertEqual(0, result.returncode, result.stdout + result.stderr)
|
||||
self.assertIn("after-leader-exit ok", result.stdout)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in new issue
Block a user