mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-19 04:46:08 +00:00
FEX: preload the fault report only where x86 loaders look (#551)
Preload the FEX fault report only where x86 loaders look droiddeck-fex put the x86 libfaultreport.so in LD_PRELOAD, which FEX's own arm64 loader reads too - and FEXServer's, and every child FEX's - so each x86 start printed "ERROR: ld.so: object '.../libfaultreport.so' from LD_PRELOAD cannot be preloaded", and an i386 child added "wrong ELF class". It is now listed in the x86 runtime's own /etc/ld.so.preload, which only the loaders inside FEX read, as /usr/$LIB/droiddeck/libfaultreport.so. faultreport.c builds for i386 too, so 32-bit programs get the report as well instead of an error.
This commit is contained in:
1 parent
2a06204eb4
commit
d45933e559
7 files changed
+104
-23
No files matched your search
@@ -26,9 +26,14 @@ for arch in x86_64 i386; do
|
||||
fi
|
||||
done
|
||||
done
|
||||
for name in faultreport thunkaudit; do
|
||||
lib=$out/x86_64/lib$name.so
|
||||
gcc -m64 -shared -fPIC -O2 -Wall -Wextra -nostdlib -fno-stack-protector -fno-builtin -fvisibility=hidden \
|
||||
for target in x86_64/faultreport i386/faultreport x86_64/thunkaudit; do
|
||||
arch=${target%/*} name=${target#*/}
|
||||
case $arch in
|
||||
x86_64) bits=-m64 ;;
|
||||
i386) bits=-m32 ;;
|
||||
esac
|
||||
lib=$out/$arch/lib$name.so
|
||||
gcc $bits -shared -fPIC -O2 -Wall -Wextra -nostdlib -fno-stack-protector -fno-builtin -fvisibility=hidden \
|
||||
-o "$lib" tools/linuxfs/fex/$name.c
|
||||
strip --strip-unneeded "$lib"
|
||||
if objdump -p "$lib" | grep -q NEEDED || [ -n "$(nm -D --undefined-only "$lib" 2>/dev/null)" ]; then
|
||||
|
||||
@@ -1,15 +1,30 @@
|
||||
#if !defined(__x86_64__)
|
||||
#error faultreport is built for x86_64 guests only
|
||||
#endif
|
||||
|
||||
#if defined(__x86_64__)
|
||||
#define SYS_read 0
|
||||
#define SYS_write 1
|
||||
#define SYS_close 3
|
||||
#define SYS_rt_sigaction 13
|
||||
#define SYS_rt_sigreturn "15"
|
||||
#define SYS_getpid 39
|
||||
#define SYS_gettid 186
|
||||
#define SYS_tgkill 234
|
||||
#define SYS_openat 257
|
||||
#define SI_ADDR 16
|
||||
#define TRAP "syscall"
|
||||
#elif defined(__i386__)
|
||||
#define SYS_read 3
|
||||
#define SYS_write 4
|
||||
#define SYS_close 6
|
||||
#define SYS_rt_sigaction 174
|
||||
#define SYS_rt_sigreturn "173"
|
||||
#define SYS_getpid 20
|
||||
#define SYS_gettid 224
|
||||
#define SYS_tgkill 270
|
||||
#define SYS_openat 295
|
||||
#define SI_ADDR 12
|
||||
#define TRAP "int $0x80"
|
||||
#else
|
||||
#error faultreport is built for x86 guests only
|
||||
#endif
|
||||
#define AT_FDCWD (-100)
|
||||
#define SIGILL 4
|
||||
#define SA_SIGINFO 0x4UL
|
||||
@@ -21,14 +36,18 @@ struct kernel_sigaction {
|
||||
void (*handler)(int, void *, void *);
|
||||
unsigned long flags;
|
||||
void (*restorer)(void);
|
||||
unsigned long mask;
|
||||
unsigned long long mask;
|
||||
};
|
||||
|
||||
static long sys(long n, long a, long b, long c, long d)
|
||||
{
|
||||
long r;
|
||||
#if defined(__x86_64__)
|
||||
register long r10 __asm__("r10") = d;
|
||||
__asm__ volatile("syscall" : "=a"(r) : "a"(n), "D"(a), "S"(b), "d"(c), "r"(r10) : "rcx", "r11", "memory");
|
||||
#else
|
||||
__asm__ volatile("int $0x80" : "=a"(r) : "a"(n), "b"(a), "c"(b), "d"(c), "S"(d) : "memory");
|
||||
#endif
|
||||
return r;
|
||||
}
|
||||
|
||||
@@ -100,7 +119,7 @@ static int find_mapping(unsigned long addr, const char **line, unsigned long *le
|
||||
static void report(int sig, void *info, void *context)
|
||||
{
|
||||
(void)context;
|
||||
unsigned long addr = *(unsigned long *)((char *)info + 16);
|
||||
unsigned long addr = *(unsigned long *)((char *)info + SI_ADDR);
|
||||
int code = *(int *)((char *)info + 8);
|
||||
used = 0;
|
||||
put("droiddeck-fex: SIGILL at 0x");
|
||||
@@ -135,7 +154,7 @@ static void report(int sig, void *info, void *context)
|
||||
}
|
||||
|
||||
void faultreport_restore(void);
|
||||
__asm__(".text\n.type faultreport_restore,@function\nfaultreport_restore:\nmov $15, %eax\nsyscall\nhlt\n");
|
||||
__asm__(".text\n.type faultreport_restore,@function\nfaultreport_restore:\nmov $" SYS_rt_sigreturn ", %eax\n" TRAP "\nhlt\n");
|
||||
|
||||
__attribute__((constructor)) static void install(void)
|
||||
{
|
||||
|
||||
@@ -34,7 +34,6 @@ LAYOUT = 1
|
||||
GUEST_LIBDIRS = (("x86_64", "lib/x86_64-linux-gnu"), ("i386", "lib/i386-linux-gnu"))
|
||||
PRELOAD_NAMES = ("libblsession.so", "libfakeinput.so")
|
||||
FAULT_REPORT = "libfaultreport.so"
|
||||
FAULT_REPORT_GUEST = "/usr/lib/x86_64-linux-gnu/droiddeck/" + FAULT_REPORT
|
||||
THUNK_AUDIT = "libthunkaudit.so"
|
||||
THUNK_AUDIT_GUEST = "/usr/lib/x86_64-linux-gnu/droiddeck/" + THUNK_AUDIT
|
||||
VULKAN_PIN = "libvulkan-thunk.so"
|
||||
@@ -241,18 +240,23 @@ def host_preloads():
|
||||
|
||||
|
||||
def install_preloads(root):
|
||||
shipped = set()
|
||||
shipped = {}
|
||||
for arch, libdir in GUEST_LIBDIRS:
|
||||
for name in PRELOAD_NAMES:
|
||||
for name in PRELOAD_NAMES + (FAULT_REPORT,):
|
||||
source = os.path.join(PRELOADS, arch, name)
|
||||
if os.path.isfile(source):
|
||||
copy_if_changed(source, os.path.join(root, libdir, "droiddeck", name))
|
||||
shipped.add(name)
|
||||
for name in (FAULT_REPORT, THUNK_AUDIT, VULKAN_PIN):
|
||||
shipped.setdefault(name, set()).add(arch)
|
||||
for name in (THUNK_AUDIT, VULKAN_PIN):
|
||||
source = os.path.join(PRELOADS, "x86_64", name)
|
||||
if os.path.isfile(source):
|
||||
copy_if_changed(source, os.path.join(root, "lib/x86_64-linux-gnu/droiddeck", name))
|
||||
wanted = [name for name in host_preloads() if name in shipped]
|
||||
# The fault report is preloaded from the runtime's own list, which only x86 loaders read: through
|
||||
# LD_PRELOAD it reached FEX's own loader too, and every FEX after it, which could not open it and
|
||||
# said so at each start. Listed only with both builds, or i386 programs would say so instead.
|
||||
if len(shipped.get(FAULT_REPORT, ())) == len(GUEST_LIBDIRS):
|
||||
wanted.append(FAULT_REPORT)
|
||||
write_if_changed(os.path.join(root, "etc", "ld.so.preload"), "".join("/usr/$LIB/droiddeck/%s\n" % name for name in wanted))
|
||||
|
||||
|
||||
@@ -502,8 +506,6 @@ def launch(command, env, mode, decide=None):
|
||||
return 126
|
||||
guest = guest_environment(fex, env)
|
||||
x86_64 = elf_arch(program) != "i386"
|
||||
if os.path.isfile(os.path.join(PRELOADS, "x86_64", FAULT_REPORT)) and x86_64:
|
||||
guest["LD_PRELOAD"] = ":".join([FAULT_REPORT_GUEST] + split_paths(guest.get("LD_PRELOAD")))
|
||||
thunks = "on" if "FEX_THUNKCONFIG" in guest else "off"
|
||||
folder = decide if decide and os.path.isdir(decide) else os.path.dirname(program)
|
||||
if thunks == "on" and x86_64 and all(os.path.isfile(os.path.join(PRELOADS, "x86_64", name)) for name in (THUNK_AUDIT, VULKAN_PIN)) \
|
||||
|
||||
Reference in new issue
Block a user