Merge main and compile and target Android API 36

This commit is contained in:
Kurt Himebauch committed 2026-10-23 10:32:35 -04:00
commit 28a5423629
123 files changed
+2639 -335

No files matched your search

@@ -21,6 +21,30 @@ unpack() {
{ rm -rf "$dir.new"; echo "droiddeck-pipewire: could not unpack $bundle" >&2; return 1; }
}
access_config() {
mkdir -p "$dir/share/pipewire/pipewire.conf.d" "$dir/share/wireplumber/wireplumber.conf.d" || return 1
cat > "$dir/share/pipewire/pipewire.conf.d/droiddeck-access.conf" <<'EOF' || return 1
context.properties = {
module.access = false
}
context.modules = [
{ name = libpipewire-module-access
args = {
access.socket = { pipewire-0 = "unrestricted", pipewire-0-manager = "unrestricted" }
}
}
]
EOF
cat > "$dir/share/wireplumber/wireplumber.conf.d/droiddeck-access.conf" <<'EOF' || return 1
access.rules = [
{
matches = [ { pipewire.access = "unrestricted" } ]
actions = { update-props = { default_permissions = "all" } }
}
]
EOF
}
stop() {
for pid in $(cat "$state/pids" 2>/dev/null); do kill "$pid" 2>/dev/null; done
rm -f "$state/pids"
@@ -32,6 +56,7 @@ env)
;;
start)
unpack || exit 1
access_config || { echo "droiddeck-pipewire: could not write the access settings" >&2; exit 1; }
stop
mkdir -p "$state"
eval "$(client_env)"
@@ -60,6 +60,9 @@ clear_stale_tmp() {
return 0
}
[ -z "${BL_INSIDE:-}" ] && clear_stale_tmp
if [ -z "${BL_INSIDE:-}" ]; then
if [ "${BL_ZRAM:-0}" = 1 ]; then printf 0 > /tmp/.bl-zram; else rm -f /tmp/.bl-zram; fi
fi
steam_update_stuck() {
[ "$1" -lt 60 ] || steam_updates=0
@@ -442,7 +445,6 @@ case $mode in
step "client cores: $BL_CLIENT_CPUS"
fi
if [ "${BL_ZRAM:-0}" = 1 ]; then
printf 0 > /tmp/.bl-zram
step "zRAM compression: on"
(
bl_zram_scan() {
@@ -491,8 +493,6 @@ case $mode in
nap 5
done
) &
else
rm -f /tmp/.bl-zram
fi
if [ "${BL_LAUNCHER_CORES:-1}" != 0 ] && [ -n "${BL_LAUNCH_DIR:-}" ] && [ -z "${BL_DESKTOP:-}" ] \
&& [ "${BL_STEAM_UI:-}" != desktop ] && [ -x /usr/local/bin/droiddeck-launcher-cores ]; then
+3
View File
@@ -409,6 +409,8 @@ int bl_drm_gem_close(int fd, unsigned long request, void *arg, int *rc) __attrib
int bl_venc_ioctl(int fd, unsigned long request, void *arg, int *rc) __attribute__((visibility("hidden")));
int bl_winebus_rumble_ioctl(int (*real)(int, unsigned long, void *), int fd, unsigned long request,
void *arg, void *caller, int *rc) __attribute__((visibility("hidden")));
int bl_writewatch_ioctl(int (*real)(int, unsigned long, void *), int fd, unsigned long request, void *arg,
int *rc) __attribute__((visibility("hidden")));
int ioctl(int fd, unsigned long request, ...) {
typedef int (*ioctl_fn)(int, unsigned long, void *);
@@ -424,6 +426,7 @@ int ioctl(int fd, unsigned long request, ...) {
if (bl_drm_gem_close(fd, request, arg, &rc)) return rc;
if (real == NULL) real = (ioctl_fn) dlsym(RTLD_NEXT, "ioctl");
if (bl_winebus_rumble_ioctl(real, fd, request, arg, __builtin_return_address(0), &rc)) return rc;
if (bl_writewatch_ioctl(real, fd, request, arg, &rc)) return rc;
if (!bl_kgsl_poll(real, fd, request, arg, &rc)) rc = quest_kgsl_ioctl(real, fd, request, arg);
bl_kgsl_chip_id_fixup(request, arg, rc);
if (arg == NULL || !is_link_query(request)) return rc;
+5
View File
@@ -329,6 +329,8 @@ static int execveat_is_execve(const long *args) {
return path[0] == '/' || (int)args[0] == AT_FDCWD;
}
int bl_writewatch_syscall(long number, const long *args, long (*real)(long, ...), long *rc) __attribute__((visibility("hidden")));
long syscall(long number, ...) {
va_list ap;
long args[6];
@@ -354,6 +356,9 @@ long syscall(long number, ...) {
if (!real_syscall) {
real_syscall = (long (*)(long, ...)) dlsym(RTLD_NEXT, "syscall");
}
if (bl_writewatch_syscall(number, args, real_syscall, &handled)) {
return handled;
}
if (number == SYS_openat2) {
if (!__atomic_load_n(&openat2_missing, __ATOMIC_RELAXED)) {
long fd = real_syscall(number, args[0], args[1], args[2], args[3]);
+4 -1
View File
@@ -16,6 +16,8 @@
#define STATUS_MAX 16384
#define TRACER_FIELD "\nTracerPid:\t"
int bl_from_ntdll(const void *caller) __attribute__((visibility("hidden")));
static const char *skip_digits(const char *s) {
const char *end = s;
while (isdigit((unsigned char)*end)) end++;
@@ -77,7 +79,8 @@ __attribute__((visibility("hidden"))) int bl_status_without_tracer(const char *p
int out = -1;
long pid;
if ((flags & O_ACCMODE) != O_RDONLY || (pid = status_pid(path)) < 0 || is_web_helper(caller)) return -1;
if ((flags & O_ACCMODE) != O_RDONLY || (pid = status_pid(path)) < 0 || is_web_helper(caller) || bl_from_ntdll(caller))
return -1;
int in = (int)syscall(SYS_openat, AT_FDCWD, path, O_RDONLY | O_CLOEXEC);
if (in < 0) goto done;
for (;;) {
+218
View File
@@ -0,0 +1,218 @@
#define _GNU_SOURCE
#include <dlfcn.h>
#include <link.h>
#include <signal.h>
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <sys/auxv.h>
#include <sys/syscall.h>
#include <ucontext.h>
#include <unistd.h>
static uintptr_t ntdll_lo, ntdll_hi;
static int find_ntdll(struct dl_phdr_info *info, size_t size, void *data) {
(void)size;
(void)data;
const char *slash = strrchr(info->dlpi_name, '/');
if (strcmp(slash ? slash + 1 : info->dlpi_name, "ntdll.so") != 0) return 0;
for (int i = 0; i < info->dlpi_phnum; i++) {
const ElfW(Phdr) *ph = &info->dlpi_phdr[i];
if (ph->p_type != PT_LOAD || !(ph->p_flags & PF_X)) continue;
uintptr_t lo = info->dlpi_addr + ph->p_vaddr;
__atomic_store_n(&ntdll_hi, lo + ph->p_memsz, __ATOMIC_RELAXED);
__atomic_store_n(&ntdll_lo, lo, __ATOMIC_RELEASE);
return 1;
}
return 0;
}
__attribute__((visibility("hidden"))) int bl_from_ntdll(const void *caller) {
uintptr_t pc = (uintptr_t)caller, lo = __atomic_load_n(&ntdll_lo, __ATOMIC_ACQUIRE);
if (!lo) {
dl_iterate_phdr(find_ntdll, NULL);
lo = __atomic_load_n(&ntdll_lo, __ATOMIC_ACQUIRE);
if (!lo) return 0;
}
return pc >= lo && pc < __atomic_load_n(&ntdll_hi, __ATOMIC_RELAXED);
}
#if defined(__aarch64__)
#include <asm/hwcap.h>
#include <asm/sigcontext.h>
#define BL_STR2(x) #x
#define BL_STR(x) BL_STR2(x)
#define BL_HWCAP_GCS (1UL << 32)
#define BL_FRAME_SIZE 4688
#define BL_REGS 312
#define BL_SP 560
#define BL_PC 568
#define BL_PSTATE 576
#define BL_FPSIMD 592
struct bl_sigframe {
siginfo_t info;
ucontext_t uc;
};
struct bl_kernel_sigaction {
void (*handler)(int, siginfo_t *, void *);
unsigned long flags;
void *restorer;
uint64_t mask;
};
struct bl_usr2_call {
void (*handler)(int, siginfo_t *, void *);
uint64_t old_mask;
};
_Static_assert(sizeof(struct bl_sigframe) == BL_FRAME_SIZE, "rt_sigframe size");
_Static_assert(offsetof(struct bl_sigframe, uc.uc_mcontext.regs) == BL_REGS, "regs offset");
_Static_assert(offsetof(struct bl_sigframe, uc.uc_mcontext.sp) == BL_SP, "sp offset");
_Static_assert(offsetof(struct bl_sigframe, uc.uc_mcontext.pc) == BL_PC, "pc offset");
_Static_assert(offsetof(struct bl_sigframe, uc.uc_mcontext.pstate) == BL_PSTATE, "pstate offset");
_Static_assert(offsetof(struct bl_sigframe, uc.uc_mcontext.__reserved) == BL_FPSIMD, "reserved offset");
_Static_assert(sizeof(struct fpsimd_context) + sizeof(struct _aarch64_ctx) <=
sizeof(((mcontext_t *)0)->__reserved), "reserved space");
__attribute__((visibility("hidden"))) void bl_usr2_frame(struct bl_usr2_call *call);
__attribute__((visibility("hidden"), used)) void bl_usr2_run(struct bl_usr2_call *call, struct bl_sigframe *frame);
__asm__(".text\n"
".p2align 2\n"
".type bl_usr2_frame, %function\n"
"bl_usr2_frame:\n"
" mov x16, #" BL_STR(BL_FRAME_SIZE) "\n"
" sub sp, sp, x16\n"
" add x17, sp, #" BL_STR(BL_REGS) "\n"
" stp x0, x1, [x17, #0]\n"
" stp x2, x3, [x17, #16]\n"
" stp x4, x5, [x17, #32]\n"
" stp x6, x7, [x17, #48]\n"
" stp x8, x9, [x17, #64]\n"
" stp x10, x11, [x17, #80]\n"
" stp x12, x13, [x17, #96]\n"
" stp x14, x15, [x17, #112]\n"
" stp xzr, xzr, [x17, #128]\n"
" stp x18, x19, [x17, #144]\n"
" stp x20, x21, [x17, #160]\n"
" stp x22, x23, [x17, #176]\n"
" stp x24, x25, [x17, #192]\n"
" stp x26, x27, [x17, #208]\n"
" stp x28, x29, [x17, #224]\n"
" str x30, [x17, #240]\n"
" str xzr, [x17, #0]\n"
" add x16, sp, x16\n"
" str x16, [sp, #" BL_STR(BL_SP) "]\n"
" adr x16, 1f\n"
" str x16, [sp, #" BL_STR(BL_PC) "]\n"
" mrs x16, nzcv\n"
" str x16, [sp, #" BL_STR(BL_PSTATE) "]\n"
" add x17, sp, #" BL_STR(BL_FPSIMD) "\n"
" mrs x16, fpsr\n"
" str w16, [x17, #8]\n"
" mrs x16, fpcr\n"
" str w16, [x17, #12]\n"
" stp q0, q1, [x17, #16]\n"
" stp q2, q3, [x17, #48]\n"
" stp q4, q5, [x17, #80]\n"
" stp q6, q7, [x17, #112]\n"
" stp q8, q9, [x17, #144]\n"
" stp q10, q11, [x17, #176]\n"
" stp q12, q13, [x17, #208]\n"
" stp q14, q15, [x17, #240]\n"
" stp q16, q17, [x17, #272]\n"
" stp q18, q19, [x17, #304]\n"
" stp q20, q21, [x17, #336]\n"
" stp q22, q23, [x17, #368]\n"
" stp q24, q25, [x17, #400]\n"
" stp q26, q27, [x17, #432]\n"
" stp q28, q29, [x17, #464]\n"
" stp q30, q31, [x17, #496]\n"
" mov x1, sp\n"
" bl bl_usr2_run\n"
" mov x8, #" BL_STR(__NR_rt_sigreturn) "\n"
" svc #0\n"
" brk #0\n"
"1:\n"
" ret\n"
".size bl_usr2_frame, .-bl_usr2_frame\n");
static int (*usr2_real_raise)(int);
static long usr2_sys(long nr, long a, long b, long c, long d) {
register long x8 __asm__("x8") = nr;
register long x0 __asm__("x0") = a;
register long x1 __asm__("x1") = b;
register long x2 __asm__("x2") = c;
register long x3 __asm__("x3") = d;
__asm__ volatile("svc #0" : "+r"(x0) : "r"(x8), "r"(x1), "r"(x2), "r"(x3) : "memory");
return x0;
}
static uint64_t usr2_ssbs(void) {
uint64_t value = 0;
if (getauxval(AT_HWCAP) & HWCAP_SSBS) __asm__ volatile("mrs %0, s3_3_c4_c2_6" : "=r"(value));
return value & (1UL << 12);
}
void bl_usr2_run(struct bl_usr2_call *call, struct bl_sigframe *frame) {
struct fpsimd_context *fp = (struct fpsimd_context *)frame->uc.uc_mcontext.__reserved;
struct _aarch64_ctx *end = (struct _aarch64_ctx *)(fp + 1);
memset(&frame->info, 0, sizeof(frame->info));
frame->info.si_signo = SIGUSR2;
frame->info.si_code = SI_TKILL;
frame->info.si_pid = (pid_t)usr2_sys(__NR_getpid, 0, 0, 0, 0);
frame->info.si_uid = (uid_t)usr2_sys(__NR_getuid, 0, 0, 0, 0);
frame->uc.uc_flags = 0;
frame->uc.uc_link = NULL;
if (usr2_sys(__NR_sigaltstack, 0, (long)&frame->uc.uc_stack, 0, 0) != 0) {
memset(&frame->uc.uc_stack, 0, sizeof(frame->uc.uc_stack));
frame->uc.uc_stack.ss_flags = SS_DISABLE;
}
memset(&frame->uc.uc_sigmask, 0, sizeof(frame->uc.uc_sigmask));
memcpy(&frame->uc.uc_sigmask, &call->old_mask, sizeof(call->old_mask));
frame->uc.uc_mcontext.fault_address = 0;
frame->uc.uc_mcontext.pstate |= usr2_ssbs();
fp->head.magic = FPSIMD_MAGIC;
fp->head.size = sizeof(*fp);
end->magic = 0;
end->size = 0;
call->handler(SIGUSR2, &frame->info, &frame->uc);
}
int raise(int sig) {
int (*real)(int) = __atomic_load_n(&usr2_real_raise, __ATOMIC_ACQUIRE);
if (!real) {
real = (int (*)(int))dlsym(RTLD_NEXT, "raise");
__atomic_store_n(&usr2_real_raise, real, __ATOMIC_RELEASE);
}
if (sig != SIGUSR2 || (getauxval(AT_HWCAP) & BL_HWCAP_GCS) || !bl_from_ntdll(__builtin_return_address(0))) {
return real(sig);
}
struct bl_kernel_sigaction action;
if (usr2_sys(__NR_rt_sigaction, SIGUSR2, 0, (long)&action, sizeof(action.mask)) != 0) return real(sig);
if (!(action.flags & SA_SIGINFO) || (action.flags & SA_RESETHAND) || (uintptr_t)action.handler <= 1) {
return real(sig);
}
uint64_t bit = 1ULL << (SIGUSR2 - 1);
uint64_t block = action.mask | ((action.flags & SA_NODEFER) ? 0 : bit);
struct bl_usr2_call call = {action.handler, 0};
if (usr2_sys(__NR_rt_sigprocmask, SIG_BLOCK, (long)&block, (long)&call.old_mask, sizeof(block)) != 0) {
return real(sig);
}
if (call.old_mask & bit) {
usr2_sys(__NR_rt_sigprocmask, SIG_SETMASK, (long)&call.old_mask, 0, sizeof(call.old_mask));
return real(sig);
}
bl_usr2_frame(&call);
return 0;
}
#endif
+113
View File
@@ -0,0 +1,113 @@
#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <linux/fs.h>
#include <linux/userfaultfd.h>
#include <stdint.h>
#include <sys/ioctl.h>
#include <sys/syscall.h>
#include <unistd.h>
#define WINE_ARM64_USERFAULTFD 374
#define PM_UFFD_WP (1ULL << 57)
#define PM_SWAP (1ULL << 62)
#define PM_PRESENT (1ULL << 63)
#if defined(PAGEMAP_SCAN) && defined(UFFD_USER_MODE_ONLY)
static int ww_uffd = -1;
static int scan_blocked;
#endif
__attribute__((visibility("hidden"))) int bl_writewatch_syscall(long number, const long *args, long (*real)(long, ...), long *rc) {
#if defined(__aarch64__) && defined(PAGEMAP_SCAN) && defined(UFFD_USER_MODE_ONLY)
if (number != WINE_ARM64_USERFAULTFD || (args[0] & ~(long)(O_CLOEXEC | O_NONBLOCK | UFFD_USER_MODE_ONLY))) return 0;
*rc = real(SYS_userfaultfd, args[0]);
if (*rc >= 0) __atomic_store_n(&ww_uffd, (int)*rc, __ATOMIC_RELEASE);
return 1;
#else
(void)number;
(void)args;
(void)real;
(void)rc;
return 0;
#endif
}
#if defined(PAGEMAP_SCAN) && defined(UFFD_USER_MODE_ONLY)
static int protect(int uffd, uint64_t start, uint64_t end) {
if (start == end) return 0;
struct uffdio_writeprotect wp = { .range = { start, end - start }, .mode = UFFDIO_WRITEPROTECT_MODE_WP };
return ioctl(uffd, UFFDIO_WRITEPROTECT, &wp);
}
static long emulate_scan(int fd, int uffd, struct pm_scan_arg *a) {
uint64_t page = (uint64_t)getpagesize();
if (a->size < sizeof(*a) || (a->flags & ~(uint64_t)PM_SCAN_WP_MATCHING) || a->category_inverted || a->category_anyof_mask
|| a->category_mask != PAGE_IS_WRITTEN || (a->return_mask & ~(uint64_t)PAGE_IS_WRITTEN) || a->end < a->start
|| ((a->start | a->end) & (page - 1)) || (a->vec_len && !a->vec)) {
errno = EINVAL;
return -1;
}
struct page_region *vec = (struct page_region *)(uintptr_t)a->vec;
uint64_t regions = 0, pages = 0, addr = a->start, wp_start = 0, wp_end = 0;
uint64_t entries[512];
int wp = (a->flags & PM_SCAN_WP_MATCHING) != 0;
while (addr < a->end) {
uint64_t want = (a->end - addr) / page;
if (want > 512) want = 512;
ssize_t got = pread(fd, entries, want * sizeof(entries[0]), (off_t)(addr / page * sizeof(entries[0])));
if (got < 0) return -1;
if (got == 0) break;
for (uint64_t i = 0; i < (uint64_t)got / sizeof(entries[0]); i++, addr += page) {
uint64_t e = entries[i];
if (!(e & (PM_PRESENT | PM_SWAP)) || (e & PM_UFFD_WP)) continue;
if (a->max_pages && pages >= a->max_pages) goto done;
if (a->vec_len) {
if (regions && vec[regions - 1].end == addr) {
vec[regions - 1].end += page;
} else {
if (regions == a->vec_len) goto done;
vec[regions].start = addr;
vec[regions].end = addr + page;
vec[regions].categories = PAGE_IS_WRITTEN & a->return_mask;
regions++;
}
}
pages++;
if (!wp) continue;
if (wp_end != addr) {
if (protect(uffd, wp_start, wp_end) < 0) return -1;
wp_start = addr;
}
wp_end = addr + page;
}
}
done:
if (wp && protect(uffd, wp_start, wp_end) < 0) return -1;
a->walk_end = addr < a->end ? addr : a->end;
return (long)regions;
}
#endif
__attribute__((visibility("hidden"))) int bl_writewatch_ioctl(int (*real)(int, unsigned long, void *), int fd, unsigned long request,
void *arg, int *rc) {
#if defined(PAGEMAP_SCAN) && defined(UFFD_USER_MODE_ONLY)
if (request != PAGEMAP_SCAN) return 0;
int uffd = __atomic_load_n(&ww_uffd, __ATOMIC_ACQUIRE);
if (uffd < 0) return 0;
if (!__atomic_load_n(&scan_blocked, __ATOMIC_RELAXED)) {
*rc = real(fd, request, arg);
if (*rc >= 0 || errno != EACCES) return 1;
__atomic_store_n(&scan_blocked, 1, __ATOMIC_RELAXED);
}
*rc = (int)emulate_scan(fd, uffd, (struct pm_scan_arg *)arg);
return 1;
#else
(void)real;
(void)fd;
(void)request;
(void)arg;
(void)rc;
return 0;
#endif
}
+21 -2
View File
@@ -126,6 +126,25 @@ static void zr_walk(int compress) {
zr_sys(SYS_close, maps);
}
// Before it stops a session for suspend, the app waits for <ZR_CTL>.ack.<pid> to appear (the handler
// runs here, not one a program installed over it) and then to hold a byte (the page-out finished).
static void zr_ack(int done) {
static const char suffix[] = ".ack.";
char path[sizeof(ZR_CTL) + sizeof(suffix) + 20];
char digits[20];
size_t n = 0, d = 0;
for (const char *p = ZR_CTL; *p; p++) path[n++] = *p;
for (const char *p = suffix; *p; p++) path[n++] = *p;
long pid = zr_sys(SYS_getpid);
do digits[d++] = (char)('0' + pid % 10); while ((pid /= 10) > 0);
while (d > 0) path[n++] = digits[--d];
path[n] = 0;
int fd = (int)zr_sys(SYS_openat, AT_FDCWD, path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0600);
if (fd < 0) return;
if (done) zr_sys(SYS_write, fd, "1", 1UL);
zr_sys(SYS_close, fd);
}
static void zr_handler(int sig, siginfo_t *info, void *context) {
(void)sig;
(void)context;
@@ -136,7 +155,9 @@ static void zr_handler(int sig, siginfo_t *info, void *context) {
&& !__atomic_exchange_n(&zr_busy, 1, __ATOMIC_SEQ_CST)) {
__atomic_store_n(&zr_pending, 0, __ATOMIC_SEQ_CST);
int mode = zr_mode();
if (mode == 1) zr_ack(0);
if (mode >= 0) zr_walk(mode);
if (mode == 1) zr_ack(1);
__atomic_store_n(&zr_busy, 0, __ATOMIC_SEQ_CST);
}
errno = saved;
@@ -148,8 +169,6 @@ static void zr_child(void) {
}
__attribute__((constructor)) static void zr_init(void) {
const char *name = program_invocation_short_name;
if (strcmp(name, "steam") != 0 && strcmp(name, "steamwebhelper") != 0) return;
void *libc = dlopen("libc.so.6", RTLD_LAZY | RTLD_NOLOAD);
if (libc == NULL) return;
zr_sys = (long (*)(long, ...))dlsym(libc, "syscall");