Skip to content

Commit

Permalink
feat: Add the mangle-symbols feature (#1312)
Browse files Browse the repository at this point in the history
* feat: Add the `mangle-symbols` feature

* fix: Disable `mangle-symbols` by default, fix description
  • Loading branch information
xdoardo authored Nov 21, 2024
1 parent df0cd20 commit 37a8116
Show file tree
Hide file tree
Showing 26 changed files with 167 additions and 151 deletions.
1 change: 1 addition & 0 deletions crates/c_api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ doctest = false
[features]
default = ["std"]
std = []
mangle-symbols = []
26 changes: 13 additions & 13 deletions crates/c_api/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ wasmi_c_api_macros::declare_own!(wasm_config_t);
/// Wraps [`wasmi::Config::default`].
///
/// [`wasm_engine_new_with_config`]: crate::wasm_engine_new_with_config
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasm_config_new() -> Box<wasm_config_t> {
Box::new(wasm_config_t {
inner: Config::default(),
Expand All @@ -32,7 +32,7 @@ pub extern "C" fn wasm_config_new() -> Box<wasm_config_t> {
/// Wraps [`wasmi::Config::wasm_multi_value`]
///
/// [`mutable-global`]: <https://github.com/WebAssembly/mutable-global>
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasmi_config_wasm_mutable_globals_set(c: &mut wasm_config_t, enable: bool) {
c.inner.wasm_mutable_global(enable);
}
Expand All @@ -42,7 +42,7 @@ pub extern "C" fn wasmi_config_wasm_mutable_globals_set(c: &mut wasm_config_t, e
/// Wraps [`wasmi::Config::wasm_multi_value`]
///
/// [`multi-value`]: <https://github.com/WebAssembly/multi-value>
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasmi_config_wasm_multi_value_set(c: &mut wasm_config_t, enable: bool) {
c.inner.wasm_multi_value(enable);
}
Expand All @@ -52,7 +52,7 @@ pub extern "C" fn wasmi_config_wasm_multi_value_set(c: &mut wasm_config_t, enabl
/// Wraps [`wasmi::Config::wasm_sign_extension`]
///
/// [`sign-extension-ops`]: <https://github.com/WebAssembly/sign-extension-ops>
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasmi_config_wasm_sign_extension_set(c: &mut wasm_config_t, enable: bool) {
c.inner.wasm_sign_extension(enable);
}
Expand All @@ -62,7 +62,7 @@ pub extern "C" fn wasmi_config_wasm_sign_extension_set(c: &mut wasm_config_t, en
/// Wraps [`wasmi::Config::wasm_saturating_float_to_int`]
///
/// [`nontrapping-float-to-int-conversions`]: <https://github.com/WebAssembly/nontrapping-float-to-int-conversions>
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasmi_config_wasm_saturating_float_to_int_set(
c: &mut wasm_config_t,
enable: bool,
Expand All @@ -75,7 +75,7 @@ pub extern "C" fn wasmi_config_wasm_saturating_float_to_int_set(
/// Wraps [`wasmi::Config::wasm_bulk_memory`]
///
/// [`bulk-memory-operations`]: <https://github.com/WebAssembly/bulk-memory-operations>
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasmi_config_wasm_bulk_memory_set(c: &mut wasm_config_t, enable: bool) {
c.inner.wasm_bulk_memory(enable);
}
Expand All @@ -85,7 +85,7 @@ pub extern "C" fn wasmi_config_wasm_bulk_memory_set(c: &mut wasm_config_t, enabl
/// Wraps [`wasmi::Config::wasm_reference_types`]
///
/// [`reference-types`]: <https://github.com/WebAssembly/reference-types>
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasmi_config_wasm_reference_types_set(c: &mut wasm_config_t, enable: bool) {
c.inner.wasm_reference_types(enable);
}
Expand All @@ -95,7 +95,7 @@ pub extern "C" fn wasmi_config_wasm_reference_types_set(c: &mut wasm_config_t, e
/// Wraps [`wasmi::Config::wasm_tail_call`]
///
/// [`tail-call`]: <https://github.com/WebAssembly/tail-call>
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasmi_config_wasm_tail_call_set(c: &mut wasm_config_t, enable: bool) {
c.inner.wasm_tail_call(enable);
}
Expand All @@ -105,23 +105,23 @@ pub extern "C" fn wasmi_config_wasm_tail_call_set(c: &mut wasm_config_t, enable:
/// Wraps [`wasmi::Config::wasm_extended_const`]
///
/// [`extended-const`]: <https://github.com/WebAssembly/extended-const>
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasmi_config_wasm_extended_const_set(c: &mut wasm_config_t, enable: bool) {
c.inner.wasm_extended_const(enable);
}

/// Enables or disables support for floating point numbers for the config.
///
/// Wraps [`wasmi::Config::floats`]
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasmi_config_floats_set(config: &mut wasm_config_t, enable: bool) {
config.inner.floats(enable);
}

/// Enables or disables fuel consumption for the config.
///
/// Wraps [`wasmi::Config::consume_fuel`]
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasmi_config_consume_fuel_set(config: &mut wasm_config_t, enable: bool) {
config.inner.consume_fuel(enable);
}
Expand All @@ -140,7 +140,7 @@ pub enum wasmi_compilation_mode_t {
/// Sets the compilation mode for the config.
///
/// Wraps [`wasmi::Config::compilation_mode`]
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasmi_config_compilation_mode_set(
config: &mut wasm_config_t,
mode: wasmi_compilation_mode_t,
Expand All @@ -156,7 +156,7 @@ pub extern "C" fn wasmi_config_compilation_mode_set(
/// Enables or disables processing of Wasm custom sections.
///
/// Wraps [`wasmi::Config::ignore_custom_sections`]
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasmi_config_ignore_custom_sections_set(
config: &mut wasm_config_t,
enable: bool,
Expand Down
6 changes: 3 additions & 3 deletions crates/c_api/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ wasmi_c_api_macros::declare_own!(wasm_engine_t);
/// The returned [`wasm_engine_t`] must be freed using [`wasm_engine_delete`].
///
/// Wraps [`wasmi::Engine::default`].
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
Box::new(wasm_engine_t {
inner: Engine::default(),
Expand All @@ -30,7 +30,7 @@ pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
/// The returned [`wasm_engine_t`] must be freed using [`wasm_engine_delete`].
///
/// Wraps [`wasmi::Engine::new`].
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasm_engine_new_with_config(config: Box<wasm_config_t>) -> Box<wasm_engine_t> {
Box::new(wasm_engine_t {
inner: Engine::new(&config.inner),
Expand All @@ -42,7 +42,7 @@ pub extern "C" fn wasm_engine_new_with_config(config: Box<wasm_config_t>) -> Box
/// The cloned [`wasm_engine_t`] has to be freed with [`wasm_engine_delete`] after use.
///
/// Wraps [`wasmi::Engine::clone`].
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasmi_engine_clone(engine: &wasm_engine_t) -> Box<wasm_engine_t> {
Box::new(engine.clone())
}
20 changes: 10 additions & 10 deletions crates/c_api/src/extern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub struct wasm_extern_t {
wasmi_c_api_macros::declare_ref!(wasm_extern_t);

/// Returns the [`wasm_extern_kind`] of the [`wasm_extern_t`].
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasm_extern_kind(e: &wasm_extern_t) -> wasm_externkind_t {
match e.which {
Extern::Func(_) => wasm_externkind_t::WASM_EXTERN_FUNC,
Expand All @@ -38,7 +38,7 @@ pub extern "C" fn wasm_extern_kind(e: &wasm_extern_t) -> wasm_externkind_t {
///
/// It is the caller's responsibility not to alias the [`wasm_extern_t`]
/// with its underlying, internal [`WasmStoreRef`].
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub unsafe extern "C" fn wasm_extern_type(e: &wasm_extern_t) -> Box<wasm_externtype_t> {
Box::new(wasm_externtype_t::from_extern_type(
e.which.ty(e.store.context()),
Expand All @@ -48,63 +48,63 @@ pub unsafe extern "C" fn wasm_extern_type(e: &wasm_extern_t) -> Box<wasm_externt
/// Returns the [`wasm_extern_t`] as reference to mutable [`wasm_func_t`] if possible.
///
/// Returns `None` if `e` is not a [`wasm_func_t`].
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasm_extern_as_func(e: &mut wasm_extern_t) -> Option<&mut wasm_func_t> {
wasm_func_t::try_from_mut(e)
}

/// Returns the [`wasm_extern_t`] as reference to shared [`wasm_func_t`] if possible.
///
/// Returns `None` if `e` is not a [`wasm_func_t`].
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasm_extern_as_func_const(e: &wasm_extern_t) -> Option<&wasm_func_t> {
wasm_func_t::try_from(e)
}

/// Returns the [`wasm_extern_t`] as reference to mutable [`wasm_global_t`] if possible.
///
/// Returns `None` if `e` is not a [`wasm_global_t`].
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasm_extern_as_global(e: &mut wasm_extern_t) -> Option<&mut wasm_global_t> {
wasm_global_t::try_from_mut(e)
}

/// Returns the [`wasm_extern_t`] as reference to shared [`wasm_global_t`] if possible.
///
/// Returns `None` if `e` is not a [`wasm_global_t`].
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasm_extern_as_global_const(e: &wasm_extern_t) -> Option<&wasm_global_t> {
wasm_global_t::try_from(e)
}

/// Returns the [`wasm_extern_t`] as reference to mutable [`wasm_table_t`] if possible.
///
/// Returns `None` if `e` is not a [`wasm_table_t`].
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasm_extern_as_table(e: &mut wasm_extern_t) -> Option<&mut wasm_table_t> {
wasm_table_t::try_from_mut(e)
}

/// Returns the [`wasm_extern_t`] as reference to shared [`wasm_table_t`] if possible.
///
/// Returns `None` if `e` is not a [`wasm_table_t`].
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasm_extern_as_table_const(e: &wasm_extern_t) -> Option<&wasm_table_t> {
wasm_table_t::try_from(e)
}

/// Returns the [`wasm_extern_t`] as reference to mutable [`wasm_memory_t`] if possible.
///
/// Returns `None` if `e` is not a [`wasm_memory_t`].
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasm_extern_as_memory(e: &mut wasm_extern_t) -> Option<&mut wasm_memory_t> {
wasm_memory_t::try_from_mut(e)
}

/// Returns the [`wasm_extern_t`] as reference to shared [`wasm_memory_t`] if possible.
///
/// Returns `None` if `e` is not a [`wasm_memory_t`].
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasm_extern_as_memory_const(e: &wasm_extern_t) -> Option<&wasm_memory_t> {
wasm_memory_t::try_from(e)
}
2 changes: 1 addition & 1 deletion crates/c_api/src/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ wasmi_c_api_macros::declare_ref!(wasm_foreign_t);
/// # Note
///
/// This API is unsupported and will panic upon use.
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasm_foreign_new(_store: &crate::wasm_store_t) -> Box<wasm_foreign_t> {
unimplemented!("wasm_foreign_new")
}
10 changes: 5 additions & 5 deletions crates/c_api/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ wasmi_c_api_macros::declare_own!(wasm_frame_t);
/// # Note
///
/// This API is unsupported and will panic upon use.
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasm_frame_func_index(_frame: &wasm_frame_t<'_>) -> u32 {
unimplemented!("wasm_frame_func_index")
}
Expand All @@ -26,7 +26,7 @@ pub extern "C" fn wasm_frame_func_index(_frame: &wasm_frame_t<'_>) -> u32 {
/// # Note
///
/// This API is unsupported and will panic upon use.
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasm_frame_func_offset(_frame: &wasm_frame_t<'_>) -> usize {
unimplemented!("wasm_frame_func_offset")
}
Expand All @@ -36,7 +36,7 @@ pub extern "C" fn wasm_frame_func_offset(_frame: &wasm_frame_t<'_>) -> usize {
/// # Note
///
/// This API is unsupported and will panic upon use.
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasm_frame_instance(_arg1: *const wasm_frame_t<'_>) -> *mut wasm_instance_t {
unimplemented!("wasm_frame_instance")
}
Expand All @@ -46,7 +46,7 @@ pub extern "C" fn wasm_frame_instance(_arg1: *const wasm_frame_t<'_>) -> *mut wa
/// # Note
///
/// This API is unsupported and will panic upon use.
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasm_frame_module_offset(_frame: &wasm_frame_t<'_>) -> usize {
unimplemented!("wasm_frame_module_offset")
}
Expand All @@ -56,7 +56,7 @@ pub extern "C" fn wasm_frame_module_offset(_frame: &wasm_frame_t<'_>) -> usize {
/// # Note
///
/// This API is unsupported and will panic upon use.
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasm_frame_copy<'a>(_frame: &wasm_frame_t<'a>) -> Box<wasm_frame_t<'a>> {
unimplemented!("wasm_frame_copy")
}
16 changes: 8 additions & 8 deletions crates/c_api/src/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ unsafe fn create_function(
///
/// It is the caller's responsibility not to alias the [`wasm_functype_t`]
/// with its underlying, internal [`WasmStoreRef`](crate::WasmStoreRef).
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub unsafe extern "C" fn wasm_func_new(
store: &mut wasm_store_t,
ty: &wasm_functype_t,
Expand All @@ -140,7 +140,7 @@ pub unsafe extern "C" fn wasm_func_new(
///
/// It is the caller's responsibility not to alias the [`wasm_functype_t`]
/// with its underlying, internal [`WasmStoreRef`](crate::WasmStoreRef).
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub unsafe extern "C" fn wasm_func_new_with_env(
store: &mut wasm_store_t,
ty: &wasm_functype_t,
Expand Down Expand Up @@ -183,7 +183,7 @@ fn prepare_params_and_results(
///
/// It is the caller's responsibility not to alias the [`wasm_func_t`]
/// with its underlying, internal [`WasmStoreRef`](crate::WasmStoreRef).
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub unsafe extern "C" fn wasm_func_call(
func: &mut wasm_func_t,
params: *const wasm_val_vec_t,
Expand Down Expand Up @@ -247,7 +247,7 @@ fn error_from_panic(panic: Box<dyn Any + Send>) -> Error {
///
/// It is the caller's responsibility not to alias the [`wasm_func_t`]
/// with its underlying, internal [`WasmStoreRef`](crate::WasmStoreRef).
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub unsafe extern "C" fn wasm_func_type(f: &wasm_func_t) -> Box<wasm_functype_t> {
Box::new(wasm_functype_t::new(f.func().ty(f.inner.store.context())))
}
Expand All @@ -262,7 +262,7 @@ pub unsafe extern "C" fn wasm_func_type(f: &wasm_func_t) -> Box<wasm_functype_t>
/// with its underlying, internal [`WasmStoreRef`](crate::WasmStoreRef).
///
/// [`FuncType::params`]: wasmi::FuncType::params
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub unsafe extern "C" fn wasm_func_param_arity(f: &wasm_func_t) -> usize {
f.func().ty(f.inner.store.context()).params().len()
}
Expand All @@ -277,19 +277,19 @@ pub unsafe extern "C" fn wasm_func_param_arity(f: &wasm_func_t) -> usize {
/// with its underlying, internal [`WasmStoreRef`](crate::WasmStoreRef).
///
/// [`FuncType::results`]: wasmi::FuncType::results
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub unsafe extern "C" fn wasm_func_result_arity(f: &wasm_func_t) -> usize {
f.func().ty(f.inner.store.context()).results().len()
}

/// Returns the [`wasm_func_t`] as mutable reference to [`wasm_extern_t`].
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasm_func_as_extern(f: &mut wasm_func_t) -> &mut wasm_extern_t {
&mut f.inner
}

/// Returns the [`wasm_func_t`] as shared reference to [`wasm_extern_t`].
#[no_mangle]
#[cfg_attr(not(feature = "mangle-symbols"), no_mangle)]
pub extern "C" fn wasm_func_as_extern_const(f: &wasm_func_t) -> &wasm_extern_t {
&f.inner
}
Loading

0 comments on commit 37a8116

Please sign in to comment.