1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 04:37:44 +00:00

LibC+LibELF: Implement more fully-features dlfcn functionality

This implements more of the dlfcn functionality. Most notably:

* It's now possible to dlopen() libraries which were already
  loaded at program startup time. This does not cause those
  libraries to be loaded twice.
* Errors are reported via dlerror() rather than by crashing
  the program.
* Calls to the dl*() functions are thread-safe.
This commit is contained in:
Gunnar Beutner 2021-04-24 20:39:58 +02:00 committed by Andreas Kling
parent 549d9bd3ea
commit f40ee1b03f
12 changed files with 371 additions and 200 deletions

View file

@ -12,6 +12,7 @@
#include <AK/RefCounted.h>
#include <AK/String.h>
#include <LibC/elf.h>
#include <LibDl/dlfcn_integration.h>
#include <LibELF/DynamicObject.h>
#include <LibELF/Image.h>
#include <sys/mman.h>
@ -41,7 +42,7 @@ enum class ShouldInitializeWeak {
class DynamicLoader : public RefCounted<DynamicLoader> {
public:
static RefPtr<DynamicLoader> try_create(int fd, String filename);
static Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> try_create(int fd, String filename);
~DynamicLoader();
const String& filename() const { return m_filename; }
@ -59,14 +60,11 @@ public:
bool load_stage_2(unsigned flags, size_t total_tls_size);
// Stage 3 of loading: lazy relocations
RefPtr<DynamicObject> load_stage_3(unsigned flags, size_t total_tls_size);
Result<NonnullRefPtr<DynamicObject>, DlErrorMessage> load_stage_3(unsigned flags, size_t total_tls_size);
// Stage 4 of loading: initializers
void load_stage_4();
// Intended for use by dlsym or other internal methods
void* symbol_for_name(const StringView&);
void set_tls_offset(size_t offset) { m_tls_offset = offset; };
size_t tls_size() const { return m_tls_size; }
size_t tls_offset() const { return m_tls_offset; }