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#[global_allocator]
11static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
12
13// musl's memcpy implementation is slow on x86_64, so we use memcpy crate to
14// provide an optimized implementation.
15//
16// xtask-fmt allow-target-arch sys-crate
17#[cfg(target_arch = "x86_64")]
18use fast_memcpy as _;
19
20// OpenVMM-HCL only needs libcrypto from openssl, not libssl.
21#[cfg(target_os = "linux")]
22openssl_crypto_only::openssl_crypto_only!();
23
24/// Entry point into the underhill multi-binary, dispatching between various
25/// entrypoints based on argv0.
26pub fn underhill_main() -> anyhow::Result<()> {
27    let argv0 = std::path::PathBuf::from(std::env::args_os().next().unwrap());
28    match argv0.file_name().unwrap().to_str().unwrap() {
29        "underhill-init" => underhill_init::main(),
30        "underhill-crash" => underhill_crash::main(),
31        "underhill-dump" => underhill_dump::main(),
32        _ => underhill_core::main(),
33    }
34}