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 = realpath(path.c_str(), NULL);
40 absPath.assign(realPath);
47 static void preloadAssemblies()
49 #ifdef USE_DEFAULT_BASE_ADDR
50 putenv(const_cast<char *>("COMPlus_UseDefaultBaseAddr=1"));
51 #endif // USE_DEFAULT_BASE_ADDR
53 void* coreclrLib = dlopen(__coreclr_lib, RTLD_NOW | RTLD_GLOBAL);
54 if (coreclrLib == nullptr) {
55 _DBG("dlopen failed to open libcoreclr.so");
59 coreclr_preload_assembly_ptr preloadAssembly;
60 preloadAssembly = (coreclr_preload_assembly_ptr)dlsym(coreclrLib, "coreclr_preload_assembly");
61 if (preloadAssembly == nullptr) {
62 _DBG("coreclr_preload_assembly is not found in the libcoreclr.so");
66 std::ifstream preloadList(AOT_PRELOAD_PATH);
69 while (getline(preloadList, path)) {
70 int st = preloadAssembly(absolutePath(path).c_str());
72 _DBG("preload of %s failed! (0x%08x)", path.c_str(), st);
74 _DBG("preload of %s succeded", path.c_str());
80 int main(int argc, char** argv)
82 hydra_lifecycle_callback_s hydra_callback;
84 hydra_callback.precreate = [](void* user_data) {
85 _INFO("hydra : precreate");
89 hydra_callback.create = [](void* user_data) {
90 _INFO("hydra : create");
93 hydra_callback.fork = [](int argc, char **argv, void* user_data) -> int {
94 _INFO("hydra : fork");
95 void* launcher_h = dlopen(__dotnet_launcher, RTLD_NOW | RTLD_GLOBAL);
96 if (launcher_h == nullptr) {
97 _DBG("dlopen failed to open dotnet-launcher");
101 launcher_real_main_ptr realMain = (launcher_real_main_ptr)dlsym(launcher_h, "realMain");
102 if (realMain == nullptr) {
103 _DBG("realMain is not found in the dotnet-launcher");
107 return realMain(argc, argv, "default");
110 hydra_callback.terminate = [](void* user_data)-> int {
111 _INFO("hydra : terminate");
115 return launchpad_hydra_main(argc, argv, &hydra_callback, nullptr);