#![warn(clippy::pedantic, clippy::cargo, unsafe_op_in_unsafe_fn)]
#![allow(
clippy::missing_safety_doc,
clippy::missing_errors_doc,
clippy::missing_panics_doc,
clippy::module_name_repetitions,
clippy::multiple_crate_versions,
clippy::doc_markdown,
non_camel_case_types,
dead_code
)]
#![cfg_attr(all(feature = "doc-cfg", nightly), feature(doc_cfg))]
pub use dlopen2;
use core::{ffi::c_void, mem};
use coreclr_hosting_shared::{char_t, size_t};
pub const UNMANAGED_CALLERS_ONLY_METHOD: *const char_t = usize::MAX as *const _;
#[cfg(windows)]
pub const PATH_LIST_SEPARATOR: char_t = b';' as char_t;
#[cfg(not(windows))]
pub const PATH_LIST_SEPARATOR: char_t = b':' as char_t;
#[repr(i32)]
pub enum hostfxr_delegate_type {
hdt_com_activation = 0,
hdt_load_in_memory_assembly = 1,
hdt_winrt_activation = 2,
hdt_com_register = 3,
hdt_com_unregister = 4,
hdt_load_assembly_and_get_function_pointer = 5,
hdt_get_function_pointer = 6,
}
pub type hostfxr_error_writer_fn = extern "C" fn(message: *const char_t);
#[allow(non_upper_case_globals)]
pub mod hostfxr_resolve_sdk2_flags_t {
pub const none: i32 = 0x0;
pub const disallow_prerelease: i32 = 0x1;
}
#[repr(i32)]
pub enum hostfxr_resolve_sdk2_result_key_t {
resolved_sdk_dir = 0,
global_json_path = 1,
}
pub type hostfxr_resolve_sdk2_result_fn =
extern "C" fn(key: hostfxr_resolve_sdk2_result_key_t, value: *const char_t);
pub type hostfxr_get_available_sdks_result_fn =
extern "C" fn(sdk_count: i32, sdk_dirs: *const *const char_t);
pub type hostfxr_handle = *const c_void;
pub type load_assembly_and_get_function_pointer_fn = unsafe extern "system" fn(
assembly_path: *const char_t,
type_name: *const char_t,
method_name: *const char_t,
delegate_type_name: *const char_t,
reserved: *const c_void,
delegate: *mut *const c_void,
) -> i32;
pub type get_function_pointer_fn = unsafe extern "system" fn(
type_name: *const char_t,
method_name: *const char_t,
delegate_type_name: *const char_t,
load_context: *const c_void,
reserved: *const c_void,
delegate: *mut *const c_void,
) -> i32;
pub type component_entry_point_fn = unsafe extern "system" fn(*const c_void, size_t) -> i32;
#[repr(C)]
pub struct hostfxr_initialize_parameters {
pub size: size_t,
pub host_path: *const char_t,
pub dotnet_root: *const char_t,
}
impl hostfxr_initialize_parameters {
#[must_use]
pub fn with_host_path(host_path: *const char_t) -> hostfxr_initialize_parameters {
hostfxr_initialize_parameters {
size: mem::size_of::<hostfxr_initialize_parameters>(),
host_path,
dotnet_root: core::ptr::null(),
}
}
#[must_use]
pub fn with_dotnet_root(dotnet_root: *const char_t) -> hostfxr_initialize_parameters {
hostfxr_initialize_parameters {
size: mem::size_of::<hostfxr_initialize_parameters>(),
host_path: core::ptr::null(),
dotnet_root,
}
}
}
macro_rules! derive_apis {
(
$( #[$struct_attrs:meta] )*
$visibility:vis struct $name:ident {
$(
$( #[$field_attrs:meta] )*
$field:ident : $field_type:ty,
)*
}) => {
$visibility mod symbor {
#[allow(unused_imports)]
use super::*;
use dlopen2::symbor::{Symbol, SymBorApi};
$( #[$struct_attrs] )*
#[derive(SymBorApi)]
$visibility struct $name <'lib> {
#[cfg(not(feature = "netcore1_0"))]
_dummy: Option<Symbol<'lib, fn()>>,
$(
$( #[$field_attrs] )*
pub $field : Symbol<'lib, $field_type>
),*
}
}
$visibility mod wrapper {
#[allow(unused_imports)]
use super::*;
use dlopen2::wrapper::WrapperApi;
$( #[$struct_attrs] )*
#[derive(WrapperApi)]
$visibility struct $name {
$(
$( #[$field_attrs] )*
$field : $field_type
),*
}
}
}
}
derive_apis! {
pub struct Hostfxr {
#[cfg(feature = "netcore1_0")]
#[cfg_attr(all(feature = "doc-cfg", nightly), doc(cfg(feature = "netcore1_0")))]
hostfxr_main: unsafe extern "C" fn(argc: i32, argv: *const *const char_t) -> i32,
#[deprecated(note = "Use `hostfxr_resolve_sdk2` instead.")]
#[cfg(feature = "netcore2_0")]
#[cfg_attr(all(feature = "doc-cfg", nightly), doc(cfg(feature = "netcore2_0")))]
hostfxr_resolve_sdk: unsafe extern "C" fn(
exe_dir: *const char_t,
working_dir: *const char_t,
buffer: *mut char_t,
buffer_size: i32,
) -> i32,
#[cfg(feature = "netcore2_1")]
#[cfg_attr(all(feature = "doc-cfg", nightly), doc(cfg(feature = "netcore2_1")))]
hostfxr_main_startupinfo: unsafe extern "C" fn(
argc: i32,
argv: *const *const char_t,
host_path: *const char_t,
dotnet_root: *const char_t,
app_path: *const char_t,
) -> i32,
#[cfg(all(feature = "netcore2_1", feature = "undocumented"))]
#[cfg_attr(
all(feature = "doc-cfg", nightly),
doc(cfg(feature = "netcore2_1", feature = "undocumented"))
)]
hostfxr_main_bundle_startupinfo: unsafe extern "C" fn(
argc: i32,
argv: *const *const char_t,
host_path: *const char_t,
dotnet_root: *const char_t,
app_path: *const char_t,
bundle_header_offset: i64,
) -> i32,
#[cfg(feature = "netcore2_1")]
#[cfg_attr(all(feature = "doc-cfg", nightly), doc(cfg(feature = "netcore2_1")))]
hostfxr_resolve_sdk2: unsafe extern "C" fn(
exe_dir: *const char_t,
working_dir: *const char_t,
flags: i32,
result: hostfxr_resolve_sdk2_result_fn,
) -> i32,
#[cfg(feature = "netcore2_1")]
#[cfg_attr(all(feature = "doc-cfg", nightly), doc(cfg(feature = "netcore2_1")))]
hostfxr_get_available_sdks: unsafe extern "C" fn(
exe_dir: *const char_t,
result: hostfxr_get_available_sdks_result_fn,
) -> i32,
#[cfg(feature = "netcore2_1")]
#[cfg_attr(all(feature = "doc-cfg", nightly), doc(cfg(feature = "netcore2_1")))]
hostfxr_get_native_search_directories: unsafe extern "C" fn(
argc: i32,
argv: *const *const char_t,
buffer: *mut char_t,
buffer_size: i32,
required_buffer_size: *mut i32,
) -> i32,
#[cfg(feature = "netcore3_0")]
#[cfg_attr(all(feature = "doc-cfg", nightly), doc(cfg(feature = "netcore3_0")))]
hostfxr_set_error_writer:
unsafe extern "C" fn(error_writer: hostfxr_error_writer_fn) -> hostfxr_error_writer_fn,
#[cfg(feature = "netcore3_0")]
#[cfg_attr(all(feature = "doc-cfg", nightly), doc(cfg(feature = "netcore3_0")))]
hostfxr_initialize_for_dotnet_command_line: unsafe extern "C" fn(
argc: i32,
argv: *const *const char_t,
parameters: *const hostfxr_initialize_parameters,
/*out*/ host_context_handle: *mut hostfxr_handle,
) -> i32,
#[cfg(feature = "netcore3_0")]
#[cfg_attr(all(feature = "doc-cfg", nightly), doc(cfg(feature = "netcore3_0")))]
hostfxr_initialize_for_runtime_config: unsafe extern "C" fn(
runtime_config_path: *const char_t,
parameters: *const hostfxr_initialize_parameters,
/*out*/ host_context_handle: *mut hostfxr_handle,
) -> i32,
#[cfg(feature = "netcore3_0")]
#[cfg_attr(all(feature = "doc-cfg", nightly), doc(cfg(feature = "netcore3_0")))]
hostfxr_get_runtime_property_value: unsafe extern "C" fn(
host_context_handle: hostfxr_handle,
name: *const char_t,
/*out*/ value: *mut *const char_t,
) -> i32,
#[cfg(feature = "netcore3_0")]
#[cfg_attr(all(feature = "doc-cfg", nightly), doc(cfg(feature = "netcore3_0")))]
hostfxr_set_runtime_property_value: unsafe extern "C" fn(
host_context_handle: hostfxr_handle,
name: *const char_t,
value: *const char_t,
) -> i32,
#[cfg(feature = "netcore3_0")]
#[cfg_attr(all(feature = "doc-cfg", nightly), doc(cfg(feature = "netcore3_0")))]
hostfxr_get_runtime_properties: unsafe extern "C" fn(
host_context_handle: hostfxr_handle,
/*inout*/ count: *mut size_t,
/*out*/ keys: *mut *const char_t,
/*out*/ values: *mut *const char_t,
) -> i32,
#[cfg(feature = "netcore3_0")]
#[cfg_attr(all(feature = "doc-cfg", nightly), doc(cfg(feature = "netcore3_0")))]
hostfxr_run_app: unsafe extern "C" fn(host_context_handle: hostfxr_handle) -> i32,
#[cfg(feature = "netcore3_0")]
#[cfg_attr(all(feature = "doc-cfg", nightly), doc(cfg(feature = "netcore3_0")))]
hostfxr_get_runtime_delegate: unsafe extern "C" fn(
host_context_handle: hostfxr_handle,
r#type: hostfxr_delegate_type,
/*out*/ delegate: *mut *const (),
) -> i32,
#[cfg(feature = "netcore3_0")]
#[cfg_attr(all(feature = "doc-cfg", nightly), doc(cfg(feature = "netcore3_0")))]
hostfxr_close: unsafe extern "C" fn(host_context_handle: hostfxr_handle) -> i32,
}
}