underhill_entry/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! The entry point for the underhill environment.
5
6#![forbid(unsafe_code)]
7#![cfg(target_os = "linux")]
8
9// Use mimalloc instead of the system malloc for performance.
10// For memory profiling, DHAT allocator is needed.
11#[global_allocator]
12#[cfg(not(feature = "mem-profile-tracing"))]
13static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
14#[global_allocator]
15#[cfg(feature = "mem-profile-tracing")]
16static GLOBAL: dhat::Alloc = dhat::Alloc;
17
18// musl's memcpy implementation is slow on x86_64, so we use memcpy crate to
19// provide an optimized implementation.
20//
21// xtask-fmt allow-target-arch sys-crate
22#[cfg(target_arch = "x86_64")]
23use fast_memcpy as _;
24
25// OpenVMM-HCL only needs libcrypto from openssl, not libssl.
26#[cfg(target_os = "linux")]
27openssl_crypto_only::openssl_crypto_only!();
28
29/// Entry point into the underhill multi-binary, dispatching between various
30/// entrypoints based on argv0.
31pub fn underhill_main() -> anyhow::Result<()> {
32    let argv0 = std::path::PathBuf::from(std::env::args_os().next().unwrap());
33    match argv0.file_name().unwrap().to_str().unwrap() {
34        "underhill-init" => underhill_init::main(),
35        "underhill-crash" => underhill_crash::main(),
36        "underhill-dump" => underhill_dump::main(),
37        _ => underhill_core::main(),
38    }
39}