Skip to content

Commit aef546c

Browse files
committed
Move the HostPrint Registration
Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
1 parent e798a92 commit aef546c

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

src/hyperlight_wasm/src/sandbox/proto_wasm_sandbox.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,7 @@ impl ProtoWasmSandbox {
7777
metrics::gauge!(METRIC_ACTIVE_PROTO_WASM_SANDBOXES).increment(1);
7878
metrics::counter!(METRIC_TOTAL_PROTO_WASM_SANDBOXES).increment(1);
7979

80-
// HostPrint is always registered by UninitializedSandbox, so include it by default
81-
let mut host_function_definitions = HashMap::new();
82-
host_function_definitions.insert(
83-
"HostPrint".to_string(),
84-
HostFunctionDefinition {
85-
function_name: "HostPrint".to_string(),
86-
parameter_types: Some(vec![ParameterType::String]),
87-
return_type: ReturnType::Int,
88-
},
89-
);
90-
80+
let host_function_definitions = HashMap::new();
9181
Ok(Self {
9282
inner: Some(inner),
9383
host_function_definitions,
@@ -170,8 +160,6 @@ impl ProtoWasmSandbox {
170160
&mut self,
171161
print_func: impl Into<HostFunction<i32, (String,)>>,
172162
) -> Result<()> {
173-
// HostPrint definition is already tracked from new() since
174-
// UninitializedSandbox always registers a default HostPrint.
175163
// This method only replaces the implementation, not the definition.
176164
self.inner
177165
.as_mut()

src/hyperlight_wasm_runtime/src/module.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,23 @@ fn init_wasm_runtime(function_call: FunctionCall) -> Result<Vec<u8>> {
155155
.map_err(|e| wasmtime::Error::msg(format!("{:?}", e)))
156156
},
157157
)?;
158+
159+
// Always register HostPrint
160+
let host_print_def = hostfuncs::HostFunctionDefinition {
161+
function_name: "HostPrint".to_string(),
162+
parameter_types: Some(alloc::vec![ParameterType::String]),
163+
return_type: ReturnType::Int,
164+
};
165+
let captured = host_print_def.clone();
166+
linker.func_new(
167+
"env",
168+
"HostPrint",
169+
hostfuncs::hostfunc_type(&host_print_def, &engine)?,
170+
move |c, ps, rs| {
171+
hostfuncs::call(&captured, c, ps, rs)
172+
.map_err(|e| wasmtime::Error::msg(format!("{:?}", e)))
173+
},
174+
)?;
158175
}
159176
*CUR_ENGINE.lock() = Some(engine);
160177
*CUR_LINKER.lock() = Some(linker);

0 commit comments

Comments
 (0)