2 * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <launchpad_hydra.h>
27 #include "launcher_env.h"
29 const char* __coreclr_lib = "/usr/share/dotnet.tizen/netcoreapp/libcoreclr.so";
30 const char* __dotnet_launcher = "/usr/bin/dotnet-launcher";
32 typedef int (*coreclr_preload_assembly_ptr)(const char* assemblyPath);
33 typedef int (*launcher_real_main_ptr)(int argc, char *argv[], const char* mode);
35 static std::string absolutePath(const std::string& path)
38 char realPath[PATH_MAX];
39 if (realpath(path.c_str(), realPath) != nullptr && realPath[0] != '\0')
40 absPath.assign(realPath);
45 static void preloadAssemblies()
47 #ifdef USE_DEFAULT_BASE_ADDR
48 putenv(const_cast<char *>("COMPlus_UseDefaultBaseAddr=1"));
49 #endif // USE_DEFAULT_BASE_ADDR
51 void* coreclrLib = dlopen(__coreclr_lib, RTLD_NOW | RTLD_GLOBAL);
52 if (coreclrLib == nullptr) {
53 _DBG("dlopen failed to open libcoreclr.so");
57 coreclr_preload_assembly_ptr preloadAssembly;
58 preloadAssembly = (coreclr_preload_assembly_ptr)dlsym(coreclrLib, "coreclr_preload_assembly");
59 if (preloadAssembly == nullptr) {
60 _DBG("coreclr_preload_assembly is not found in the libcoreclr.so");
64 std::ifstream preloadList(AOT_PRELOAD_PATH);
67 while (getline(preloadList, path)) {
68 int st = preloadAssembly(absolutePath(path).c_str());
70 _DBG("preload of %s failed! (0x%08x)", path.c_str(), st);
72 _DBG("preload of %s succeded", path.c_str());
78 int main(int argc, char** argv)
80 hydra_lifecycle_callback_s hydra_callback;
82 hydra_callback.precreate = [](void* user_data) {
83 _INFO("hydra : precreate");
87 hydra_callback.create = [](void* user_data) {
88 _INFO("hydra : create");
91 hydra_callback.fork = [](int argc, char **argv, void* user_data) -> int {
92 _INFO("hydra : fork");
93 void* launcher_h = dlopen(__dotnet_launcher, RTLD_NOW | RTLD_GLOBAL);
94 if (launcher_h == nullptr) {
95 _DBG("dlopen failed to open dotnet-launcher");
99 launcher_real_main_ptr realMain = (launcher_real_main_ptr)dlsym(launcher_h, "realMain");
100 if (realMain == nullptr) {
101 _DBG("realMain is not found in the dotnet-launcher");
105 return realMain(argc, argv, "default");
108 hydra_callback.terminate = [](void* user_data)-> int {
109 _INFO("hydra : terminate");
113 return launchpad_hydra_main(argc, argv, &hydra_callback, nullptr);