mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-12-06 21:15:43 +00:00
fix(bionic): link the libraries Steam's Android client needs before it, so system libraries keep their own symbols
This commit is contained in:
1 parent
2365b77d42
commit
723d78cc63
2 files changed
+147
No files matched your search
@@ -8,6 +8,7 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <dirent.h>
|
||||
#include <dlfcn.h>
|
||||
#include <elf.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
@@ -547,3 +548,55 @@ EXPORT uid_t getuid(void)
|
||||
}
|
||||
return (uid_t)raw_getuid();
|
||||
}
|
||||
|
||||
static bool read_at(int fd, void *buf, size_t n, off_t at)
|
||||
{
|
||||
return pread(fd, buf, n, at) == (ssize_t)n;
|
||||
}
|
||||
|
||||
static void load_needed_of(const char *path)
|
||||
{
|
||||
Elf64_Ehdr e;
|
||||
Elf64_Phdr ph[32];
|
||||
Elf64_Dyn dyn[128];
|
||||
uint64_t strtab = 0, strsz = 0, needed[32];
|
||||
size_t n_dyn = 0, n_needed = 0;
|
||||
off_t names_at = -1;
|
||||
char *names = NULL;
|
||||
int fd = open(path, O_RDONLY | O_CLOEXEC);
|
||||
if (fd < 0) return;
|
||||
if (!read_at(fd, &e, sizeof e, 0) || memcmp(e.e_ident, ELFMAG, SELFMAG) || e.e_ident[EI_CLASS] != ELFCLASS64 ||
|
||||
e.e_phentsize != sizeof *ph || e.e_phnum > 32 || !read_at(fd, ph, e.e_phnum * sizeof *ph, (off_t)e.e_phoff))
|
||||
goto out;
|
||||
for (int i = 0; i < e.e_phnum; i++) {
|
||||
if (ph[i].p_type != PT_DYNAMIC) continue;
|
||||
n_dyn = ph[i].p_filesz / sizeof *dyn;
|
||||
if (n_dyn > 128) n_dyn = 128;
|
||||
if (!read_at(fd, dyn, n_dyn * sizeof *dyn, (off_t)ph[i].p_offset)) goto out;
|
||||
break;
|
||||
}
|
||||
for (size_t i = 0; i < n_dyn && dyn[i].d_tag != DT_NULL; i++) {
|
||||
if (dyn[i].d_tag == DT_STRTAB) strtab = dyn[i].d_un.d_ptr;
|
||||
else if (dyn[i].d_tag == DT_STRSZ) strsz = dyn[i].d_un.d_val;
|
||||
else if (dyn[i].d_tag == DT_NEEDED && n_needed < 32) needed[n_needed++] = dyn[i].d_un.d_val;
|
||||
}
|
||||
for (int i = 0; i < e.e_phnum; i++)
|
||||
if (ph[i].p_type == PT_LOAD && strtab >= ph[i].p_vaddr && strtab - ph[i].p_vaddr + strsz <= ph[i].p_filesz)
|
||||
names_at = (off_t)(ph[i].p_offset + strtab - ph[i].p_vaddr);
|
||||
if (names_at < 0 || !strsz || strsz > (16u << 20) || !(names = malloc(strsz + 1)) ||
|
||||
!read_at(fd, names, strsz, names_at))
|
||||
goto out;
|
||||
names[strsz] = 0;
|
||||
for (size_t i = 0; i < n_needed; i++)
|
||||
if (needed[i] < strsz && !dlopen(names + needed[i], RTLD_NOW))
|
||||
say("steamshm: %s, needed by %s, did not load: %s\n", names + needed[i], path, dlerror());
|
||||
out:
|
||||
free(names);
|
||||
close(fd);
|
||||
}
|
||||
|
||||
__attribute__((constructor)) static void link_steamclient_needs_before_it(void)
|
||||
{
|
||||
const char *path = getenv("WINESTEAMCLIENTPATH64");
|
||||
if (path && *path) load_needed_of(path);
|
||||
}
|
||||
Reference in new issue
Block a user