#![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(feature = "doc-cfg", feature(doc_cfg))]
pub use dlopen2;
use core::{ffi::c_void, mem};
use coreclr_hosting_shared::{char_t, size_t};
#[cfg(feature = "net5_0")]
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "net5_0")))]
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))]
#[allow(clippy::cast_possible_wrap)]
pub const PATH_LIST_SEPARATOR: char_t = b':' as char_t;
#[cfg(feature = "netcore3_0")]
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "netcore3_0")))]
#[cfg_attr(feature = "enum-map", derive(enum_map::Enum))]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(i32)]
#[non_exhaustive]
pub enum hostfxr_delegate_type {
hdt_com_activation = 0,
hdt_load_in_memory_assembly = 1,
#[cfg(all(feature = "netcore3_0", not(feature = "net5_0")))]
#[cfg_attr(
feature = "doc-cfg",
doc(cfg(all(feature = "netcore3_0", not(feature = "net5_0"))))
)]
hdt_winrt_activation = 2,
hdt_com_register = 3,
hdt_com_unregister = 4,
hdt_load_assembly_and_get_function_pointer = 5,
#[cfg(feature = "net5_0")]
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "net5_0")))]
hdt_get_function_pointer = 6,
#[cfg(feature = "net8_0")]
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "net8_0")))]
hdt_load_assembly = 7,
#[cfg(feature = "net8_0")]
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "net8_0")))]
hdt_load_assembly_bytes = 8,
}
#[cfg(feature = "netcore3_0")]
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "netcore3_0")))]
pub type hostfxr_error_writer_fn = extern "C" fn(message: *const char_t);
#[allow(non_upper_case_globals)]
#[cfg(feature = "netcore2_1")]
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "netcore2_1")))]
#[cfg_attr(feature = "enum-map", derive(enum_map::Enum))]
#[repr(i32)]
#[non_exhaustive]
pub enum hostfxr_resolve_sdk2_flags_t {
none = 0x0,
disallow_prerelease = 0x1,
}
#[cfg(feature = "netcore2_1")]
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "netcore2_1")))]
#[cfg_attr(feature = "enum-map", derive(enum_map::Enum))]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[repr(i32)]
#[non_exhaustive]
pub enum hostfxr_resolve_sdk2_result_key_t {
resolved_sdk_dir = 0,
global_json_path = 1,
requested_version = 2,
global_json_state = 3,
}
#[cfg(feature = "netcore2_1")]
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "netcore2_1")))]
pub mod hostfxr_resolve_sdk2_global_json_state {
pub const NOT_FOUND: &str = "not_found";
pub const VALID: &str = "valid";
pub const INVALID_JSON: &str = "invalid_json";
pub const INVALID_DATA: &str = "invalid_data";
}
#[cfg(feature = "netcore2_1")]
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "netcore2_1")))]
pub type hostfxr_resolve_sdk2_result_fn =
extern "C" fn(key: hostfxr_resolve_sdk2_result_key_t, value: *const char_t);
#[cfg(feature = "netcore2_1")]
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "netcore2_1")))]
pub type hostfxr_get_available_sdks_result_fn =
extern "C" fn(sdk_count: i32, sdk_dirs: *const *const char_t);
#[cfg(all(feature = "net6_0", feature = "undocumented"))]
#[cfg_attr(
feature = "doc-cfg",
doc(cfg(all(feature = "net6_0", feature = "undocumented")))
)]
pub type hostfxr_get_dotnet_environment_info_result_fn =
unsafe extern "C" fn(info: *const hostfxr_dotnet_environment_info, result_context: *mut c_void);
#[cfg(all(feature = "net6_0", feature = "undocumented"))]
#[cfg_attr(
feature = "doc-cfg",
doc(cfg(all(feature = "net6_0", feature = "undocumented")))
)]
#[derive(Clone, Copy, Debug)]
#[repr(C)]
pub struct hostfxr_dotnet_environment_sdk_info {
pub size: size_t,
pub version: *const char_t,
pub path: *const char_t,
}
#[cfg(all(feature = "net6_0", feature = "undocumented"))]
#[cfg_attr(
feature = "doc-cfg",
doc(cfg(all(feature = "net6_0", feature = "undocumented")))
)]
#[derive(Clone, Copy, Debug)]
#[repr(C)]
pub struct hostfxr_dotnet_environment_framework_info {
pub size: size_t,
pub name: *const char_t,
pub version: *const char_t,
pub path: *const char_t,
}
#[cfg(all(feature = "net6_0", feature = "undocumented"))]
#[cfg_attr(
feature = "doc-cfg",
doc(cfg(all(feature = "net6_0", feature = "undocumented")))
)]
#[derive(Clone, Copy, Debug)]
#[repr(C)]
pub struct hostfxr_dotnet_environment_info {
pub size: size_t,
pub hostfxr_version: *const char_t,
pub hostfxr_commit_hash: *const char_t,
pub sdk_count: size_t,
pub sdks: *const hostfxr_dotnet_environment_sdk_info,
pub framework_count: size_t,
pub frameworks: *const hostfxr_dotnet_environment_framework_info,
}
pub type hostfxr_handle = *const c_void;
#[cfg(feature = "netcore3_0")]
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "netcore3_0")))]
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;
#[cfg(feature = "net5_0")]
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "net5_0")))]
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;
#[cfg(feature = "netcore3_0")]
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "netcore3_0")))]
pub type component_entry_point_fn = unsafe extern "system" fn(*const c_void, i32) -> i32;
#[cfg(feature = "net8_0")]
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "net8_0")))]
pub type load_assembly_fn = unsafe extern "system" fn(
assembly_path: *const char_t,
load_context: *const c_void,
reserved: *const c_void,
) -> i32;
#[cfg(feature = "net8_0")]
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "net8_0")))]
pub type load_assembly_bytes_fn = unsafe extern "system" fn(
assembly_bytes: *const u8,
assembly_bytes_len: usize,
symbols_bytes: *const u8,
symbols_bytes_len: usize,
load_context: *const c_void,
reserved: *const c_void,
) -> i32;
#[derive(Clone, Copy, Debug)]
#[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) -> Self {
Self {
size: mem::size_of::<Self>(),
host_path,
dotnet_root: core::ptr::null(),
}
}
#[must_use]
pub fn with_dotnet_root(dotnet_root: *const char_t) -> Self {
Self {
size: mem::size_of::<Self>(),
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,
)*
}) => {
#[cfg(feature = "symbor")]
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "symbor")))]
$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>
),*
}
}
#[cfg(all(feature = "symbor", feature = "optional-apis"))]
#[cfg_attr(feature = "doc-cfg", doc(cfg(all(feature = "symbor", feature = "optional-apis"))))]
$visibility mod symbor_option {
#[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 : Option<Symbol<'lib, $field_type>>
),*
}
}
#[cfg(feature = "wrapper")]
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "wrapper")))]
$visibility mod wrapper {
#[allow(unused_imports)]
use super::*;
use dlopen2::wrapper::WrapperApi;
$( #[$struct_attrs] )*
#[derive(WrapperApi)]
$visibility struct $name {
$(
$( #[$field_attrs] )*
$field : $field_type
),*
}
}
/// [`dlopen2::wrapper`] abstraction for the hostfxr library, with all symbols marked as optional.
#[cfg(all(feature = "wrapper", feature = "optional-apis"))]
#[cfg_attr(feature = "doc-cfg", doc(cfg(all(feature = "wrapper", feature = "optional-apis"))))]
$visibility mod wrapper_option {
#[allow(unused_imports)]
use super::*;
use dlopen2::wrapper::WrapperApi;
$( #[$struct_attrs] )*
#[derive(WrapperApi)]
$visibility struct $name {
$(
$( #[$field_attrs] )*
$field : Option<$field_type>
),*
}
}
}
}
derive_apis! {
#[allow(clippy::struct_field_names)]
pub struct Hostfxr {
#[cfg(feature = "netcore1_0")]
#[cfg_attr(feature = "doc-cfg", 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(feature = "doc-cfg", 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(feature = "doc-cfg", 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(
feature = "doc-cfg",
doc(cfg(all(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(feature = "doc-cfg", doc(cfg(feature = "netcore2_1")))]
hostfxr_resolve_sdk2: unsafe extern "C" fn(
exe_dir: *const char_t,
working_dir: *const char_t,
flags: hostfxr_resolve_sdk2_flags_t,
result: hostfxr_resolve_sdk2_result_fn,
) -> i32,
#[cfg(feature = "netcore2_1")]
#[cfg_attr(feature = "doc-cfg", 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(feature = "doc-cfg", 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(feature = "doc-cfg", doc(cfg(feature = "netcore3_0")))]
hostfxr_set_error_writer:
unsafe extern "C" fn(error_writer: Option<hostfxr_error_writer_fn>) -> Option<hostfxr_error_writer_fn>,
#[cfg(feature = "netcore3_0")]
#[cfg_attr(feature = "doc-cfg", 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(feature = "doc-cfg", 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(feature = "doc-cfg", 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(feature = "doc-cfg", 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(feature = "doc-cfg", 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(feature = "doc-cfg", doc(cfg(feature = "netcore3_0")))]
hostfxr_run_app: unsafe extern "C" fn(host_context_handle: hostfxr_handle) -> i32,
#[cfg(feature = "netcore3_0")]
#[cfg_attr(feature = "doc-cfg", 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(feature = "doc-cfg", doc(cfg(feature = "netcore3_0")))]
hostfxr_close: unsafe extern "C" fn(host_context_handle: hostfxr_handle) -> i32,
#[cfg(all(feature = "net6_0", feature = "undocumented"))]
#[cfg_attr(feature = "doc-cfg", doc(cfg(all(feature = "net6_0", feature = "undocumented"))))]
hostfxr_get_dotnet_environment_info: unsafe extern "C" fn(
dotnet_root: *const char_t,
reserved: *mut c_void,
result: hostfxr_get_dotnet_environment_info_result_fn,
result_context: *mut c_void
) -> i32,
}
}