Skip to content

Commit 56ec9cb

Browse files
committed
rt: Run yet more task_start_wrapper cleanup on the C stack
1 parent 28b825d commit 56ec9cb

File tree

1 file changed

+33
-17
lines changed

1 file changed

+33
-17
lines changed

src/rt/rust_task.cpp

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -268,25 +268,18 @@ struct rust_closure_env {
268268
type_desc *td;
269269
};
270270

271-
// This runs on the Rust stack
272-
extern "C" CDECL
273-
void task_start_wrapper(spawn_args *a)
274-
{
275-
rust_task *task = a->task;
276-
int rval = 42;
271+
struct cleanup_args {
272+
spawn_args *spargs;
273+
bool failed;
274+
};
277275

278-
bool failed = false;
279-
try {
280-
a->f(&rval, a->a3, a->a4);
281-
} catch (rust_task *ex) {
282-
A(task->sched, ex == task,
283-
"Expected this task to be thrown for unwinding");
284-
failed = true;
285-
}
276+
void
277+
cleanup_task(cleanup_args *args) {
278+
spawn_args *a = args->spargs;
279+
bool failed = args->failed;
280+
rust_task *task = a->task;
286281

287-
// We're on the Rust stack and the cycle collector may recurse arbitrarily
288-
// deep, so switch to the C stack
289-
task->sched->c_context.call_shim_on_c_stack(task, (void*)cc::do_cc);
282+
cc::do_cc(task);
290283

291284
rust_closure_env* env = (rust_closure_env*)a->a3;
292285
if(env) {
@@ -313,6 +306,29 @@ void task_start_wrapper(spawn_args *a)
313306
A(task->sched, false, "Shouldn't happen");
314307
#endif
315308
}
309+
}
310+
311+
// This runs on the Rust stack
312+
extern "C" CDECL
313+
void task_start_wrapper(spawn_args *a)
314+
{
315+
rust_task *task = a->task;
316+
int rval = 42;
317+
318+
bool failed = false;
319+
try {
320+
a->f(&rval, a->a3, a->a4);
321+
} catch (rust_task *ex) {
322+
A(task->sched, ex == task,
323+
"Expected this task to be thrown for unwinding");
324+
failed = true;
325+
}
326+
327+
cleanup_args ca = {a, failed};
328+
329+
// The cleanup work needs lots of stack
330+
task->sched->c_context.call_shim_on_c_stack(&ca, (void*)cleanup_task);
331+
316332
task->ctx.next->swap(task->ctx);
317333
}
318334

0 commit comments

Comments
 (0)