Skip to content

Commit 9bd2384

Browse files
authored
Revert "Implement a reflection API in WASIX"
1 parent bc7dce5 commit 9bd2384

File tree

7 files changed

+16
-277
lines changed

7 files changed

+16
-277
lines changed

lib/wasi-types/src/wasi/bindings.rs

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2466,56 +2466,6 @@ impl core::fmt::Debug for WasmValueType {
24662466
}
24672467
}
24682468

2469-
// TODO: if necessary, must be implemented in wit-bindgen
2470-
unsafe impl ValueType for WasmValueType {
2471-
#[inline]
2472-
fn zero_padding_bytes(&self, _bytes: &mut [MaybeUninit<u8>]) {}
2473-
}
2474-
2475-
impl TryFrom<wasmer::Type> for WasmValueType {
2476-
type Error = ();
2477-
fn try_from(value: wasmer::Type) -> Result<Self, Self::Error> {
2478-
match value {
2479-
wasmer::Type::I32 => Ok(Self::I32),
2480-
wasmer::Type::I64 => Ok(Self::I64),
2481-
wasmer::Type::F32 => Ok(Self::F32),
2482-
wasmer::Type::F64 => Ok(Self::F64),
2483-
wasmer::Type::V128 => Ok(Self::V128),
2484-
_ => Err(()),
2485-
}
2486-
}
2487-
}
2488-
impl From<WasmValueType> for wasmer::Type {
2489-
fn from(value: WasmValueType) -> Self {
2490-
match value {
2491-
WasmValueType::I32 => Self::I32,
2492-
WasmValueType::I64 => Self::I64,
2493-
WasmValueType::F32 => Self::F32,
2494-
WasmValueType::F64 => Self::F64,
2495-
WasmValueType::V128 => Self::V128,
2496-
}
2497-
}
2498-
}
2499-
2500-
#[doc = " A structure representing the reflection information for a function signature"]
2501-
#[repr(C)]
2502-
#[derive(Debug, Copy, Clone)]
2503-
pub struct ReflectionResult {
2504-
#[doc = " Whether the result is cacheable"]
2505-
pub cacheable: Bool,
2506-
#[doc = " Number of arguments the function takes"]
2507-
pub arguments: u16,
2508-
#[doc = " Number of results the function returns"]
2509-
pub results: u16,
2510-
}
2511-
2512-
unsafe impl wasmer_types::ValueType for ReflectionResult {
2513-
#[inline]
2514-
fn zero_padding_bytes(&self, bytes: &mut [MaybeUninit<u8>]) {
2515-
bytes[1].write(0);
2516-
}
2517-
}
2518-
25192469
#[repr(C)]
25202470
#[derive(Copy, Clone)]
25212471
pub struct AddrUnspec {

lib/wasix/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,6 @@ fn wasix_exports_32(mut store: &mut impl AsStoreMut, env: &FunctionEnv<WasiEnv>)
510510
"args_get" => Function::new_typed_with_env(&mut store, env, args_get::<Memory32>),
511511
"args_sizes_get" => Function::new_typed_with_env(&mut store, env, args_sizes_get::<Memory32>),
512512
"call_dynamic" => Function::new_typed_with_env(&mut store, env, call_dynamic::<Memory32>),
513-
"reflect_signature" => Function::new_typed_with_env(&mut store, env, reflect_signature::<Memory32>),
514513
"clock_res_get" => Function::new_typed_with_env(&mut store, env, clock_res_get::<Memory32>),
515514
"clock_time_get" => Function::new_typed_with_env(&mut store, env, clock_time_get::<Memory32>),
516515
"clock_time_set" => Function::new_typed_with_env(&mut store, env, clock_time_set),
@@ -650,7 +649,6 @@ fn wasix_exports_64(mut store: &mut impl AsStoreMut, env: &FunctionEnv<WasiEnv>)
650649
"args_get" => Function::new_typed_with_env(&mut store, env, args_get::<Memory64>),
651650
"args_sizes_get" => Function::new_typed_with_env(&mut store, env, args_sizes_get::<Memory64>),
652651
"call_dynamic" => Function::new_typed_with_env(&mut store, env, call_dynamic::<Memory64>),
653-
"reflect_signature" => Function::new_typed_with_env(&mut store, env, reflect_signature::<Memory64>),
654652
"clock_res_get" => Function::new_typed_with_env(&mut store, env, clock_res_get::<Memory64>),
655653
"clock_time_get" => Function::new_typed_with_env(&mut store, env, clock_time_get::<Memory64>),
656654
"clock_time_set" => Function::new_typed_with_env(&mut store, env, clock_time_set),

lib/wasix/src/state/handles/mod.rs

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -217,32 +217,6 @@ pub enum WasiModuleTreeHandles {
217217
},
218218
}
219219

220-
#[derive(thiserror::Error, Debug, Clone)]
221-
pub enum FunctionLookupError {
222-
#[error("No function found at the requested index `{0}`")]
223-
/// Function not found at the index
224-
Empty(u32),
225-
#[error("Table index `{0}` out of bounds")]
226-
/// Table index out of bounds
227-
OutOfBounds(u32),
228-
#[error("The table does not contain functions")]
229-
/// The table does not contain functions
230-
NotAFunctionTable,
231-
#[error("No indirect function table available")]
232-
/// No indirect function table available
233-
NoIndirectFunctionTable,
234-
}
235-
impl From<FunctionLookupError> for Errno {
236-
fn from(e: FunctionLookupError) -> Self {
237-
match e {
238-
FunctionLookupError::Empty(_) => Errno::Inval,
239-
FunctionLookupError::OutOfBounds(_) => Errno::Inval,
240-
FunctionLookupError::NotAFunctionTable => Errno::Inval,
241-
FunctionLookupError::NoIndirectFunctionTable => Errno::Notsup,
242-
}
243-
}
244-
}
245-
246220
impl WasiModuleTreeHandles {
247221
/// Can be used to get the `WasiModuleInstanceHandles` of the main module.
248222
/// If access to the side modules' instance handles is required, one must go
@@ -323,48 +297,32 @@ impl WasiModuleTreeHandles {
323297
}
324298
}
325299

326-
/// Helper function to look up a function in the indirect function table
327-
///
328-
/// * Returns an Errno if an error occurred.
329-
/// * Returns `Ok(None)` if the index is out of bounds.
330-
/// * Returns `Ok(Some(None))` if there is no function at the index.
331-
/// * Returns `Ok(Some(Some(function)))` if there is a function at the index.
332300
pub fn indirect_function_table_lookup(
333301
&self,
334302
store: &mut impl AsStoreMut,
335303
index: u32,
336-
) -> Result<Function, FunctionLookupError> {
304+
) -> Result<Option<Function>, Errno> {
337305
let value = self
338306
.main_module_instance_handles()
339307
.indirect_function_table
340308
.as_ref()
341-
.ok_or(FunctionLookupError::NoIndirectFunctionTable)?
309+
.ok_or(Errno::Notsup)?
342310
.get(store, index);
343311
let Some(value) = value else {
344312
trace!(
345313
function_id = index,
346314
"Function not found in indirect function table"
347315
);
348-
return Err(FunctionLookupError::OutOfBounds(index));
316+
return Ok(None);
349317
};
350318
let Value::FuncRef(funcref) = value else {
351319
error!("Function table contains something other than a funcref");
352-
return Err(FunctionLookupError::NotAFunctionTable);
320+
return Err(Errno::Inval);
353321
};
354322
let Some(funcref) = funcref else {
355323
trace!(function_id = index, "No function at the supplied index");
356-
return Err(FunctionLookupError::Empty(index));
324+
return Ok(None);
357325
};
358-
Ok(funcref)
359-
}
360-
361-
/// Check if an indirect_function_table entry is reserved for closures.
362-
///
363-
/// Returns false if the entry is not reserved for closures.
364-
pub fn is_closure(&self, function_id: u32) -> bool {
365-
match self {
366-
WasiModuleTreeHandles::Static(_) => false,
367-
WasiModuleTreeHandles::Dynamic { linker, .. } => linker.is_closure(function_id),
368-
}
326+
Ok(Some(funcref))
369327
}
370328
}

lib/wasix/src/state/linker.rs

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@
260260

261261
use std::{
262262
borrow::Cow,
263-
collections::{BTreeMap, HashMap},
263+
collections::{BTreeMap, BTreeSet, HashMap},
264264
ffi::OsStr,
265265
ops::{Deref, DerefMut},
266266
path::{Path, PathBuf},
@@ -817,9 +817,7 @@ struct LinkerState {
817817
heap_base: u64,
818818

819819
/// Tracks which slots in the function table are currently used for closures
820-
///
821-
/// True if the closure is currently in use, false otherwise.
822-
allocated_closure_functions: BTreeMap<u32, bool>,
820+
used_closure_functions: BTreeSet<u32>,
823821
/// Slots in the indirect function table that were allocated for closures but are currently not in use.
824822
/// These can be given out without needing to lock all threads.
825823
available_closure_functions: Vec<u32>,
@@ -851,7 +849,7 @@ pub struct Linker {
851849
}
852850

853851
// This macro exists to ensure we don't get into a deadlock with another pending
854-
// DL operation. The linker state must be locked for write *ONLY THROUGH THIS
852+
// DL operation. the linker state must be locked for write *ONLY THROUGH THIS
855853
// MACRO*. Bad things happen otherwise.
856854
// We also need a lock on the specific group's state here, because if there is a
857855
// pending DL operation we need to apply, that'll require mutable access to the
@@ -1065,7 +1063,7 @@ impl Linker {
10651063
side_modules_by_name: HashMap::new(),
10661064
next_module_handle: MAIN_MODULE_HANDLE.0 + 1,
10671065
memory_allocator: MemoryAllocator::new(),
1068-
allocated_closure_functions: BTreeMap::new(),
1066+
used_closure_functions: BTreeSet::new(),
10691067
available_closure_functions: Vec::new(),
10701068
heap_base: stack_high,
10711069
symbol_resolution_records: HashMap::new(),
@@ -1430,9 +1428,7 @@ impl Linker {
14301428

14311429
// Use a previously allocated slot if possible
14321430
if let Some(function_index) = linker_state.available_closure_functions.pop() {
1433-
linker_state
1434-
.allocated_closure_functions
1435-
.insert(function_index, true);
1431+
linker_state.used_closure_functions.insert(function_index);
14361432
return Ok(function_index);
14371433
}
14381434

@@ -1450,13 +1446,8 @@ impl Linker {
14501446
linker_state
14511447
.available_closure_functions
14521448
.push(function_index + i);
1453-
linker_state
1454-
.allocated_closure_functions
1455-
.insert(function_index + i, false);
14561449
}
1457-
linker_state
1458-
.allocated_closure_functions
1459-
.insert(function_index, true);
1450+
linker_state.used_closure_functions.insert(function_index);
14601451

14611452
self.synchronize_link_operation(
14621453
DlOperation::AllocateFunctionTable {
@@ -1488,32 +1479,13 @@ impl Linker {
14881479
);
14891480
write_linker_state!(linker_state, self, group_state, ctx);
14901481

1491-
let Some(entry) = linker_state
1492-
.allocated_closure_functions
1493-
.get_mut(&function_id)
1494-
else {
1495-
// Not allocated
1496-
return Ok(());
1497-
};
1498-
if !*entry {
1499-
// Not used
1482+
if !linker_state.used_closure_functions.remove(&function_id) {
1483+
// Not used, nothing to do
15001484
return Ok(());
15011485
}
1502-
1503-
*entry = false;
15041486
linker_state.available_closure_functions.push(function_id);
1505-
Ok(())
1506-
}
15071487

1508-
/// Check if an indirect_function_table entry is reserved for closures.
1509-
///
1510-
/// Returns false if the entry is not reserved for closures.
1511-
pub fn is_closure(&self, function_id: u32) -> bool {
1512-
// TODO: Check if this can result in a deadlock
1513-
let linker = self.linker_state.read().unwrap();
1514-
linker
1515-
.allocated_closure_functions
1516-
.contains_key(&function_id)
1488+
Ok(())
15171489
}
15181490

15191491
/// Loads a side module from the given path, linking it against the existing module tree

lib/wasix/src/syscalls/wasix/call_dynamic.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ pub fn call_dynamic<M: MemorySize>(
139139
let function = wasi_try_ok!(env
140140
.inner()
141141
.indirect_function_table_lookup(&mut store, function_id)
142-
.map_err(Errno::from));
142+
.and_then(|f| f.ok_or(Errno::Inval)));
143143

144144
let function_type = function.ty(&store);
145145

lib/wasix/src/syscalls/wasix/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ mod proc_signals_sizes_get;
4545
mod proc_snapshot;
4646
mod proc_spawn;
4747
mod proc_spawn2;
48-
mod reflect_signature;
4948
mod resolve;
5049
mod sched_yield;
5150
mod sock_accept;
@@ -132,7 +131,6 @@ pub use proc_signals_sizes_get::*;
132131
pub use proc_snapshot::*;
133132
pub use proc_spawn::*;
134133
pub use proc_spawn2::*;
135-
pub use reflect_signature::*;
136134
pub use resolve::*;
137135
pub use sched_yield::*;
138136
pub use sock_accept::*;

0 commit comments

Comments
 (0)