Skip to content
Snippets Groups Projects
Commit d9aa9d63 authored by Glauber Costa's avatar Glauber Costa
Browse files

Allow NULL arguments for dlopen

From dlopen man page:
"If filename  is  NULL,  then the returned handle is for the main program."

What I do in this patch is exactly this
parent 81f42426
No related branches found
No related tags found
No related merge requests found
...@@ -5,6 +5,14 @@ ...@@ -5,6 +5,14 @@
void* dlopen(const char* filename, int flags) void* dlopen(const char* filename, int flags)
{ {
if (!filename) {
// It is strange that we are returning a program while
// dlsym will always try to open an object. We may have to
// revisit this later, specially if this affect the ordering
// semantics of lookups. But for now this will work
return elf::get_program();
}
auto prog = elf::get_program(); auto prog = elf::get_program();
elf::object* obj = prog->add_object(filename); elf::object* obj = prog->add_object(filename);
// FIXME: handle flags etc. // FIXME: handle flags etc.
...@@ -20,8 +28,9 @@ int dlclose(void* handle) ...@@ -20,8 +28,9 @@ int dlclose(void* handle)
void* dlsym(void* handle, const char* name) void* dlsym(void* handle, const char* name)
{ {
elf::symbol_module sym; elf::symbol_module sym;
if (handle == RTLD_DEFAULT) { auto program = elf::get_program();
sym = elf::get_program()->lookup(name); if ((program == handle) || (handle == RTLD_DEFAULT)) {
sym = program->lookup(name);
} else if (handle == RTLD_NEXT) { } else if (handle == RTLD_NEXT) {
// FIXME: implement // FIXME: implement
abort(); abort();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment