Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does corehost load coreclr

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces how corehost loads coreclr, the content is very detailed, interested friends can refer to, hope to be helpful to you.

In exploring how dotnet run runs .NET Core applications, driven by curiosity, I explored dotnet run and discovered the mysterious corehost-the hero behind running .NET Core applications. Sometimes mystery is a temptation, and the mysterious corehost arouses new curiosity-how does corehost load coreclr? As a result, the ".NET Cross-platform Journey" begins a new journey-- with this question, visit cli/src/corehost/.

The entrance to corehost is main () of corehost.cpp, and the next avenue leads to corehost.run ().

In corehost.run (), the first call is detect_operating_mode () in libhost.cpp, which determines the running mode of corehost according to the path where coreclr is located. There are three running modes: muxer, standalone, and split-fx. If corehost and coreclr are not in the same folder, the running mode is muxer. If corehost and coreclr are in the same folder, and the .deps.json file exists under the folder or the .runtimeconfig.json file does not exist, it is standalone mode; otherwise, it is split-fx mode.

Return ((pal::file_exists (own_deps_json) | |! pal::file_exists (own_config_filename)) & & pal::file_exists (own_dll))? Host_mode_t::standalone: host_mode_t::split_fx

The default mode used by dotent cli is split-fx mode, which is also used by our sample site about.cnblogs.com, which can be seen in the following tracing information (export COREHOST_TRACE=2):

Checking if CoreCLR path exists= [/ usr/share/dotnet-nightly/bin/libcoreclr.so] Detecting mode... CoreCLR present in own dir [/ usr/share/dotnet-nightly/bin] and checking if [corehost.deps.json] file present= [0] Host operating in split mode; own dir= [/ usr/share/dotnet-nightly/bin]

Therefore, the tour route of "split-fx mode" is chosen for this trip.

For the split-fx pattern, corehost.run () then calls the run () method of hostpolicy.cpp (via corehost_init_t), which calls resolve_coreclr_dir () of deps_resolver.cpp to resolve the path where coreclr is located, and then calls the bind () and initialize () methods of coreclr.cpp to load coreclr.

In the bind () method, according to the previously parsed coreclr path, call load_library () of pal.unix.cpp (for the Linux runtime environment) to open the library file libcoreclr.so of coreclr (actually calling the C function dlopen () of Linux), and get the handles of the three functions (coreclr_initialize, coreclr_shutdown,coreclr_execute_assembly) in coreclr.

In the initialize () method, the coreclr_initialize () method of coreclr is called based on the handle obtained in bind () to start coreclr, and the work of loading coreclr is done.

Find the location of the coreclr library file, open it, and call its coreclr_initialize () method. Corehost loads coreclr as simple as that. If you are interested, you can write your own corehost using C++.

About how corehost loads coreclr is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report