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:
parent
549d9bd3ea
commit
f40ee1b03f
12 changed files with 371 additions and 200 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue