/* Runtime null guard for wl_proxy_add_listener — interposed via LD_PRELOAD. * Qt6 Wayland QPA passes NULL proxies during initialization on Redox. * This shim prevents the page fault at null+8 (proxy->object.implementation) * by returning an error code instead of crashing. * * Cross-referenced with libwayland wayland-client.c:649. */ #define _GNU_SOURCE #include #include #include /* Original function pointer */ static int (*real_wl_proxy_add_listener)(void *proxy, void (**implementation)(void), void *data) = NULL; static void *(*real_wl_proxy_get_display)(void *proxy) = NULL; static unsigned int (*real_wl_proxy_get_version)(void *proxy) = NULL; static void init(void) { real_wl_proxy_add_listener = dlsym(RTLD_NEXT, "wl_proxy_add_listener"); real_wl_proxy_get_display = dlsym(RTLD_NEXT, "wl_proxy_get_display"); real_wl_proxy_get_version = dlsym(RTLD_NEXT, "wl_proxy_get_version"); } int wl_proxy_add_listener(void *proxy, void (**implementation)(void), void *data) { if (!real_wl_proxy_add_listener) init(); if (!proxy) { fprintf(stderr, "wayland-guard: wl_proxy_add_listener(NULL) prevented crash\n"); return -1; } return real_wl_proxy_add_listener(proxy, implementation, data); } void *wl_proxy_get_display(void *proxy) { if (!real_wl_proxy_get_display) init(); if (!proxy) return NULL; return real_wl_proxy_get_display(proxy); } unsigned int wl_proxy_get_version(void *proxy) { if (!real_wl_proxy_get_version) init(); if (!proxy) return 0; return real_wl_proxy_get_version(proxy); }