From 1f22b9b982a4eed72f8c626e34662c0b82774794 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 17 Mar 2026 20:04:48 +0200 Subject: [PATCH] DynamicLinker: Implement RTLD_NOLOAD --- userspace/libraries/LibC/include/dlfcn.h | 1 + userspace/programs/DynamicLoader/main.cpp | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/userspace/libraries/LibC/include/dlfcn.h b/userspace/libraries/LibC/include/dlfcn.h index efc7da73..734a0097 100644 --- a/userspace/libraries/LibC/include/dlfcn.h +++ b/userspace/libraries/LibC/include/dlfcn.h @@ -11,6 +11,7 @@ __BEGIN_DECLS #define RTLD_NOW 0x1 #define RTLD_GLOBAL 0x0 #define RTLD_LOCAL 0x2 +#define RTLD_NOLOAD 0x4 #define _RTLD_LAZY_NOW_MASK 0x1 #define _RTLD_GLOBAL_LOCAL_MASK 0x2 diff --git a/userspace/programs/DynamicLoader/main.cpp b/userspace/programs/DynamicLoader/main.cpp index c8a67968..85d0e02b 100644 --- a/userspace/programs/DynamicLoader/main.cpp +++ b/userspace/programs/DynamicLoader/main.cpp @@ -1591,6 +1591,21 @@ void* __dlopen(const char* file, int mode) return nullptr; } + if (mode & RTLD_NOLOAD) + { + lock_global_lock(); + for (size_t i = 0; i < s_loaded_file_count; i++) + { + if (strcmp(s_loaded_files[i].path, path_buffer) == 0) + { + unlock_global_lock(); + return &s_loaded_files[i]; + } + } + unlock_global_lock(); + return nullptr; + } + const size_t old_loaded_count = s_loaded_file_count; init_random(); @@ -1609,12 +1624,16 @@ void* __dlopen(const char* file, int mode) syscall(SYS_CLOSE, elf.fd); } +#if DEBUG_DLOPEN + print(STDERR_FILENO, "\e[31m-> success\e[m\n"); +#endif + return &elf; } void* __dlsym(void* __restrict handle, const char* __restrict name) { - if (handle == nullptr) + if (handle == RTLD_DEFAULT) { for (size_t i = 0; i < s_loaded_file_count; i++) if (auto* sym = __dlsym(&s_loaded_files[i], name))