This will allow go program to get the vdso library address.

Signed-off-by: Benoît Canet <[email protected]>
---
 core/app.cc        | 21 ++++++++++++++++++---
 include/osv/app.hh |  7 ++++++-
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/core/app.cc b/core/app.cc
index ad8018c..a8cf4b2 100644
--- a/core/app.cc
+++ b/core/app.cc
@@ -173,7 +173,7 @@ application::application(const std::string& command,
         }
 
         merge_in_environ(new_program, env);
-       prepare_argv();
+       prepare_argv(current_program);
         std::vector<std::string> extra_path;
         _lib = current_program->get_library(_command, extra_path, true);
     } catch(const std::exception &e) {
@@ -297,7 +297,7 @@ void application::main()
     // _entry_point() doesn't return
 }
 
-void application::prepare_argv()
+void application::prepare_argv(elf::program *program)
 {
     // Prepare program_* variable used by the libc
     char *c_path = (char *)(_command.c_str());
@@ -324,7 +324,7 @@ void application::prepare_argv()
     }
 
     // Allocate the continuous buffer for argv[] and envp[]
-    _argv.reset(new char*[_args.size() + 1 + envcount + 1]);
+    _argv.reset(new char*[_args.size() + 1 + envcount + 1 + 
sizeof(Elf64_auxv_t) * 2]);
 
     // Fill the argv part of these buffers
     char *ab = _argv_buf.get();
@@ -343,6 +343,21 @@ void application::prepare_argv()
         contig_argv[_args.size() + 1 + i] = environ[i];
     }
     contig_argv[_args.size() + 1 + envcount] = nullptr;
+
+    _libvdso = program->get_library("libvdso.so");
+    if (!_libvdso) {
+        abort("could not load libvdso.so\n");
+        return;
+    }
+
+    // Pass the VDSO library to the application.
+    Elf64_auxv_t* _auxv =
+        reinterpret_cast<Elf64_auxv_t *>(&contig_argv[_args.size() + 1 + 
envcount + 1]);
+    _auxv[0].a_type = AT_SYSINFO_EHDR;
+    _auxv[0].a_un.a_val = reinterpret_cast<uint64_t>(_libvdso->base());
+
+    _auxv[1].a_type = AT_NULL;
+    _auxv[1].a_un.a_val = 0;
 }
 
 void application::run_main()
diff --git a/include/osv/app.hh b/include/osv/app.hh
index 62fd406..423e34d 100644
--- a/include/osv/app.hh
+++ b/include/osv/app.hh
@@ -22,6 +22,10 @@
 #include <unordered_map>
 #include <string>
 
+#include "musl/include/elf.h"
+#undef AT_UID // prevent collisions
+#undef AT_GID
+
 extern "C" void __libc_start_main(int(*)(int, char**), int, char**, void(*)(),
     void(*)(), void(*)(), void*);
 
@@ -194,7 +198,7 @@ private:
     void start_and_join(waiter* setup_waiter);
     void main();
     void run_main(std::string path, int argc, char** argv);
-    void prepare_argv();
+    void prepare_argv(elf::program *program);
     void run_main();
     friend void ::__libc_start_main(int(*)(int, char**), int, char**, 
void(*)(),
         void(*)(), void(*)(), void*);
@@ -211,6 +215,7 @@ private:
     mutex _termination_mutex;
     std::shared_ptr<elf::object> _lib;
     std::shared_ptr<elf::object> _libenviron;
+    std::shared_ptr<elf::object> _libvdso;
     main_func_t* _main;
     void (*_entry_point)();
     static app_registry apps;
-- 
2.7.4

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to