mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-25 07:46:01 +00:00
fix(preload): apps that reload libudev no longer crash in the input wrappers (#3180)
fix(preload): keep libudev loaded while the input wrappers use it Programs that close libudev and open it again crashed in the next wrapped udev call: the wrappers kept function pointers into the unmapped copy. Pin libudev with RTLD_NODELETE when it is opened so those pointers and the stored handle stay valid.
This commit is contained in:
1 parent
906e66e3cf
commit
238ef76c5c
3 files changed
+45
-5
No files matched your search
@@ -419,9 +419,11 @@ static void *real_dlsym(void);
|
||||
* searches, so the handle the program opened is the only way back to the real implementation. */
|
||||
static _Atomic(void *) udev_handle;
|
||||
|
||||
__attribute__((visibility("hidden"))) void bl_inputudev_note_dlopen(const char *path, void *handle) {
|
||||
if (handle != NULL && path != NULL && strstr(path, "libudev") != NULL)
|
||||
atomic_store_explicit(&udev_handle, handle, memory_order_release);
|
||||
__attribute__((visibility("hidden"))) void bl_inputudev_note_dlopen(const char *path, void *handle,
|
||||
void *(*open)(const char *, int)) {
|
||||
if (handle == NULL || path == NULL || strstr(path, "libudev") == NULL) return;
|
||||
if (open(path, RTLD_LAZY | RTLD_NOLOAD | RTLD_NODELETE) == NULL) return;
|
||||
atomic_store_explicit(&udev_handle, handle, memory_order_release);
|
||||
}
|
||||
|
||||
static void *next_symbol(const char *name) {
|
||||
|
||||
@@ -100,7 +100,8 @@ static long path_statx(int dirfd, const char *path, int flags, unsigned int mask
|
||||
return next_statx(dirfd, path, flags, mask, out);
|
||||
}
|
||||
|
||||
void bl_inputudev_note_dlopen(const char *path, void *handle) __attribute__((weak, visibility("hidden")));
|
||||
void bl_inputudev_note_dlopen(const char *path, void *handle, void *(*open)(const char *, int))
|
||||
__attribute__((weak, visibility("hidden")));
|
||||
|
||||
void *dlopen(const char *filename, int flags) {
|
||||
void *handle;
|
||||
@@ -114,7 +115,7 @@ void *dlopen(const char *filename, int flags) {
|
||||
flags &= ~RTLD_DEEPBIND;
|
||||
}
|
||||
handle = real_dlopen != NULL ? real_dlopen(filename, flags) : NULL;
|
||||
if (handle != NULL && bl_inputudev_note_dlopen != NULL) bl_inputudev_note_dlopen(filename, handle);
|
||||
if (handle != NULL && bl_inputudev_note_dlopen != NULL) bl_inputudev_note_dlopen(filename, handle, real_dlopen);
|
||||
return handle;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user