summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorWilliam Marlow <william.marlow@lux01.co.uk>2020-12-30 21:48:42 +0000
committerAndreas Kling <kling@serenityos.org>2020-12-31 00:52:02 +0100
commit146fac24816651cfc8bb3420f015a43acc6593fc (patch)
treeb65b84dde4e8a3a5cbf9895f7be06d6a809a8c56 /Userland
parenta7c014125fcf82be8c3cb39398e439babe21c99f (diff)
downloadserenity-146fac24816651cfc8bb3420f015a43acc6593fc.zip
DynamicLoader: Handle Loader.so being invoked directly as an executable
Loader.so is an actual executable, as well as the interpreter for dynamic libraries. Currently launching Loader.so as a standalone executable results in an obsucre crash as it tries to load itself over itself. Now we at least print a helpful message saying that you're doing the wrong thing and exit gracefully. In future we may wish to allow users to specify additional options to learn more about what's going on during dynamic linking, such as ld-linux.so.2 on Linux.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/DynamicLoader/main.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/Userland/DynamicLoader/main.cpp b/Userland/DynamicLoader/main.cpp
index f5fca108e9..65ef19c4b7 100644
--- a/Userland/DynamicLoader/main.cpp
+++ b/Userland/DynamicLoader/main.cpp
@@ -250,6 +250,20 @@ static void clear_temporary_objects_mappings()
g_loaders.clear();
}
+static void display_help()
+{
+ const char message[] =
+ R"(You have invoked `Loader.so'. This is the helper program for programs that
+use shared libraries. Special directives embedded in executables tell the
+kernel to load this program.
+
+This helper program loads the shared libraries needed by the program,
+prepares the program to run, and runs it. You do not need to invoke
+this helper program directly.
+)";
+ write(1, message, sizeof(message));
+}
+
static FlatPtr loader_main(auxv_t* auxvp)
{
int main_program_fd = -1;
@@ -265,6 +279,15 @@ static FlatPtr loader_main(auxv_t* auxvp)
ASSERT(main_program_fd >= 0);
ASSERT(!main_program_name.is_null());
+ if (main_program_name == "/usr/lib/Loader.so") {
+ // We've been invoked directly as an executable rather than as the
+ // ELF interpreter for some other binary. In the future we may want
+ // to support launching a program directly from the dynamic loader
+ // like ld.so on Linux.
+ display_help();
+ _exit(1);
+ }
+
map_library(main_program_name, main_program_fd);
map_dependencies(main_program_name);