Skip to content

Commit 09c2499

Browse files
committed
Allow bypass poisoned mutex. This is ok because sandbox is single-threaded
Signed-off-by: Ludvig Liljenberg <[email protected]>
1 parent 2700f47 commit 09c2499

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/hyperlight_host/src/func/host_functions.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,25 @@ macro_rules! impl_host_function {
179179
let func = Mutex::new(func);
180180
HostFunction {
181181
func: Arc::new(move |args: ($($P,)*)| {
182-
func.try_lock()
183-
.map_err(|e| new_error!("Error locking at {}:{}: {}", file!(), line!(), e))?
184-
(args)
182+
match func.try_lock() {
183+
Ok(mut guard) => {
184+
let result = guard(args);
185+
drop(guard);
186+
result
187+
},
188+
Err(poison_err) => {
189+
match poison_err {
190+
// The previous call to this host function panicked, poisoning the lock.
191+
// We can clear the poison safely.
192+
std::sync::TryLockError::Poisoned(guard) => {
193+
guard.into_inner()(args)
194+
}
195+
std::sync::TryLockError::WouldBlock => {
196+
Err(new_error!("Error locking at {}:{}: mutex would block", file!(), line!()))
197+
}
198+
}
199+
}
200+
}
185201
})
186202
}
187203
}

0 commit comments

Comments
 (0)