@@ -268,25 +268,18 @@ struct rust_closure_env {
268
268
type_desc *td;
269
269
};
270
270
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
+ };
277
275
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 ;
286
281
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);
290
283
291
284
rust_closure_env* env = (rust_closure_env*)a->a3 ;
292
285
if (env) {
@@ -313,6 +306,29 @@ void task_start_wrapper(spawn_args *a)
313
306
A (task->sched , false , " Shouldn't happen" );
314
307
#endif
315
308
}
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
+
316
332
task->ctx .next ->swap (task->ctx );
317
333
}
318
334
0 commit comments