diff mbox series

[RFC,05/11] elf: add hook, __libos_map_library to dl-open.c

Message ID 59087b506dde76e07ea9fba069d0d0a12c842881.1568219399.git.isaku.yamahata@gmail.com
State New
Headers show
Series Library OS support | expand

Commit Message

Isaku Yamahata Sept. 11, 2019, 9:04 p.m. UTC
This patch adds a hook on loading shared library.
The impact on traditional run-time is stub function call.
LibOS can inject its own symbol and interact with debugger.

Signed-off-by: Isaku Yamahata <isaku.yamahata@gmail.com>
---
 elf/dl-load.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/elf/dl-load.c b/elf/dl-load.c
index 5abeb867f1..6a811f41e0 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -72,6 +72,7 @@  struct filebuf
 #include <dl-sysdep-open.h>
 #include <dl-prop.h>
 #include <not-cancel.h>
+#include <libos.h>
 
 #include <endian.h>
 #if BYTE_ORDER == BIG_ENDIAN
@@ -1293,15 +1294,6 @@  cannot enable executable stack as shared object requires");
   if (l->l_tls_initimage != NULL)
     l->l_tls_initimage = (char *) l->l_tls_initimage + l->l_addr;
 
-  /* We are done mapping in the file.  We no longer need the descriptor.  */
-  if (__glibc_unlikely (__close_nocancel (fd) != 0))
-    {
-      errstring = N_("cannot close file descriptor");
-      goto call_lose_errno;
-    }
-  /* Signal that we closed the file.  */
-  fd = -1;
-
   /* If this is ET_EXEC, we should have loaded it as lt_executable.  */
   assert (type != ET_EXEC || l->l_type == lt_executable);
 
@@ -1397,6 +1389,18 @@  cannot enable executable stack as shared object requires");
     }
 #endif
 
+  /* register the library to libos */
+  __libos_map_library(fd, l->l_name, l->l_addr);
+
+  /* We are done mapping in the file.  We no longer need the descriptor.  */
+  if (__glibc_unlikely (__close_nocancel (fd) != 0))
+    {
+      errstring = N_("cannot close file descriptor");
+      goto call_lose_errno;
+    }
+  /* Signal that we closed the file.  */
+  fd = -1;
+
   return l;
 }