Skip to content

Commit cd38377

Browse files
committed
Add asserts to check fail_sched_loop() only once
1 parent 1c0b457 commit cd38377

File tree

4 files changed

+15
-3
lines changed

4 files changed

+15
-3
lines changed

src/rt/rust_builtin.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,12 @@ rust_task_kill_other(rust_task *task) { /* Used for linked failure */
864864
}
865865

866866
extern "C" void
867-
rust_task_kill_all(rust_task *task) {
867+
rust_task_kill_all(rust_task *task) { /* Used for linked failure */
868868
task->fail_sched_loop();
869+
// This must not happen twice.
870+
static bool main_taskgroup_failed = false;
871+
assert(!main_taskgroup_failed);
872+
main_taskgroup_failed = true;
869873
}
870874

871875
extern "C" rust_cond_lock*

src/rt/rust_globals.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ extern "C" int check_claims;
9090
// This accounts for logging buffers.
9191
static size_t const BUF_BYTES = 2048;
9292

93+
#define INIT_TASK_ID 1
94+
9395
// The error status to use when the process fails
9496
#define PROC_FAIL_CODE 101
9597

src/rt/rust_kernel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
rust_kernel::rust_kernel(rust_env *env) :
1616
_region(env, true),
1717
_log(NULL),
18-
max_task_id(1),
18+
max_task_id(INIT_TASK_ID-1), // sync_add_and_fetch increments first
1919
max_port_id(1),
2020
rval(0),
2121
max_sched_id(1),

src/rt/rust_task.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,17 @@ cleanup_task(cleanup_args *args) {
129129
// assert(task->task_local_data != NULL);
130130
task->task_local_data_cleanup(task->task_local_data);
131131
task->task_local_data = NULL;
132-
} else if (threw_exception) {
132+
} else if (threw_exception && task->id == INIT_TASK_ID) {
133133
// Edge case: If main never spawns any tasks, but fails anyway, TLS
134134
// won't be around to take down the kernel (task.rs:kill_taskgroup,
135135
// rust_task_kill_all). Do it here instead.
136+
// (Note that children tasks can not init their TLS if they were
137+
// killed too early, so we need to check main's task id too.)
136138
task->fail_sched_loop();
139+
// This must not happen twice.
140+
static bool main_task_failed_without_spawning = false;
141+
assert(!main_task_failed_without_spawning);
142+
main_task_failed_without_spawning = true;
137143
}
138144

139145
// FIXME (#2676): For performance we should do the annihilator

0 commit comments

Comments
 (0)