Skip to content

Commit 2a77f42

Browse files
authored
Strengthen the scheduler against applets crashing during init (#926)
1 parent 3e430e4 commit 2a77f42

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

crates/scheduler/CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
## 0.5.1-git
44

5-
### Patch
5+
### Minor
66

7+
- Fix panic when the applet crashes during init
78
- Fix callbacks accessing memory when no threads are running
9+
10+
### Patch
11+
812
- Update dependencies
913

1014
## 0.5.0

crates/scheduler/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,10 @@ impl<B: Board> Scheduler<B> {
369369
#[cfg(feature = "internal-debug")]
370370
self.perf.record(perf::Slot::Platform);
371371
self.call("init", &[]);
372-
while let Some(call) = self.applet.get().unwrap().store_mut().last_call() {
372+
loop {
373+
// The applet may have trapped in call() above or in process_applet() below.
374+
let Some(applet) = self.applet.get() else { return Ok(()) };
375+
let Some(call) = applet.store_mut().last_call() else { break };
373376
match self.host_funcs[call.id].descriptor().name {
374377
"dp" => (),
375378
x => {
@@ -378,9 +381,6 @@ impl<B: Board> Scheduler<B> {
378381
}
379382
}
380383
self.process_applet();
381-
if self.applet.get().is_none() {
382-
return Ok(()); // applet trapped in process_applet()
383-
}
384384
}
385385
assert!(matches!(self.applet.get().unwrap().pop(), EventAction::Reply));
386386
#[cfg(feature = "internal-debug")]
@@ -424,7 +424,10 @@ impl<B: Board> Scheduler<B> {
424424
#[cfg(feature = "internal-debug")]
425425
self.perf.record(perf::Slot::Platform);
426426
self.call(inst, "init", &[]);
427-
while let Some(call) = self.applet.get().unwrap().store_mut().last_call() {
427+
loop {
428+
// The applet may have trapped in call() above or in process_applet() below.
429+
let Some(applet) = self.applet.get() else { return Ok(()) };
430+
let Some(call) = applet.store_mut().last_call() else { break };
428431
match self.host_funcs[call.index()].descriptor().name {
429432
"dp" => (),
430433
x => {
@@ -433,9 +436,6 @@ impl<B: Board> Scheduler<B> {
433436
}
434437
}
435438
self.process_applet();
436-
if self.applet.get().is_none() {
437-
return Ok(()); // applet trapped in process_applet()
438-
}
439439
}
440440
assert!(matches!(self.applet.get().unwrap().pop(), EventAction::Reply));
441441
#[cfg(feature = "internal-debug")]

0 commit comments

Comments
 (0)