1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:54:58 +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

@ -452,19 +452,24 @@ int main(int argc, char** argv)
int fd = open(path, O_RDONLY);
if (fd < 0) {
outln(String::formatted("Unable to open file {}", path).characters());
outln("Unable to open file {}", path);
return 1;
}
auto loader = ELF::DynamicLoader::try_create(fd, path);
if (!loader || !loader->is_valid()) {
outln(String::formatted("{} is not a valid ELF dynamic shared object!", path));
auto result = ELF::DynamicLoader::try_create(fd, path);
if (result.is_error()) {
outln("{}", result.error().text);
return 1;
}
auto& loader = result.value();
if (!loader->is_valid()) {
outln("{} is not a valid ELF dynamic shared object!", path);
return 1;
}
object = loader->map();
if (!object) {
outln(String::formatted("Failed to map dynamic ELF object {}", path));
outln("Failed to map dynamic ELF object {}", path);
return 1;
}
}