28
28
(task)->name, (task));
29
29
#endif
30
30
31
- #define UPCALL_SWITCH_STACK (A, F ) call_upcall_on_c_stack((void *)A, (void *)F)
31
+ #define UPCALL_SWITCH_STACK (T, A, F ) \
32
+ call_upcall_on_c_stack (T, (void *)A, (void *)F)
32
33
33
34
inline void
34
- call_upcall_on_c_stack (void *args, void *fn_ptr) {
35
- rust_task *task = rust_get_current_task ();
35
+ call_upcall_on_c_stack(rust_task *task, void *args, void *fn_ptr) {
36
36
task->call_on_c_stack (args, fn_ptr);
37
37
}
38
38
@@ -93,14 +93,15 @@ upcall_call_shim_on_rust_stack(void *args, void *fn_ptr) {
93
93
/* *********************************************************************/
94
94
95
95
struct s_fail_args {
96
+ rust_task *task;
96
97
char const *expr;
97
98
char const *file;
98
99
size_t line;
99
100
};
100
101
101
102
extern " C" CDECL void
102
103
upcall_s_fail (s_fail_args *args) {
103
- rust_task *task = rust_get_current_task () ;
104
+ rust_task *task = args-> task ;
104
105
LOG_UPCALL_ENTRY (task);
105
106
task->fail (args->expr , args->file , args->line );
106
107
}
@@ -109,19 +110,21 @@ extern "C" CDECL void
109
110
upcall_fail (char const *expr,
110
111
char const *file,
111
112
size_t line) {
112
- s_fail_args args = {expr,file,line};
113
- UPCALL_SWITCH_STACK (&args, upcall_s_fail);
113
+ rust_task *task = rust_get_current_task ();
114
+ s_fail_args args = {task,expr,file,line};
115
+ UPCALL_SWITCH_STACK (task, &args, upcall_s_fail);
114
116
}
115
117
116
118
struct s_trace_args {
119
+ rust_task *task;
117
120
char const *msg;
118
121
char const *file;
119
122
size_t line;
120
123
};
121
124
122
125
extern " C" CDECL void
123
126
upcall_s_trace (s_trace_args *args) {
124
- rust_task *task = rust_get_current_task () ;
127
+ rust_task *task = args-> task ;
125
128
LOG_UPCALL_ENTRY (task);
126
129
LOG (task, trace, " Trace %s:%d: %s" ,
127
130
args->file , args->line , args->msg );
@@ -131,8 +134,9 @@ extern "C" CDECL void
131
134
upcall_trace (char const *msg,
132
135
char const *file,
133
136
size_t line) {
134
- s_trace_args args = {msg,file,line};
135
- UPCALL_SWITCH_STACK (&args, upcall_s_trace);
137
+ rust_task *task = rust_get_current_task ();
138
+ s_trace_args args = {task,msg,file,line};
139
+ UPCALL_SWITCH_STACK (task, &args, upcall_s_trace);
136
140
}
137
141
138
142
/* *********************************************************************
@@ -158,61 +162,67 @@ exchange_malloc(rust_task *task, type_desc *td, uintptr_t size) {
158
162
159
163
// FIXME: remove after snapshot (6/13/12)
160
164
struct s_exchange_malloc_args {
165
+ rust_task *task;
161
166
uintptr_t retval;
162
167
type_desc *td;
163
168
};
164
169
165
170
extern " C" CDECL void
166
171
upcall_s_exchange_malloc (s_exchange_malloc_args *args) {
167
- rust_task *task = rust_get_current_task () ;
172
+ rust_task *task = args-> task ;
168
173
LOG_UPCALL_ENTRY (task);
169
174
170
175
args->retval = exchange_malloc (task, args->td , args->td ->size );
171
176
}
172
177
173
178
extern " C" CDECL uintptr_t
174
179
upcall_exchange_malloc (type_desc *td) {
175
- s_exchange_malloc_args args = {0 , td};
176
- UPCALL_SWITCH_STACK (&args, upcall_s_exchange_malloc);
180
+ rust_task *task = rust_get_current_task ();
181
+ s_exchange_malloc_args args = {task, 0 , td};
182
+ UPCALL_SWITCH_STACK (task, &args, upcall_s_exchange_malloc);
177
183
return args.retval ;
178
184
}
179
185
180
186
struct s_exchange_malloc_dyn_args {
187
+ rust_task *task;
181
188
uintptr_t retval;
182
189
type_desc *td;
183
190
uintptr_t size;
184
191
};
185
192
186
193
extern " C" CDECL void
187
194
upcall_s_exchange_malloc_dyn (s_exchange_malloc_dyn_args *args) {
188
- rust_task *task = rust_get_current_task () ;
195
+ rust_task *task = args-> task ;
189
196
LOG_UPCALL_ENTRY (task);
190
197
191
198
args->retval = exchange_malloc (task, args->td , args->size );
192
199
}
193
200
194
201
extern " C" CDECL uintptr_t
195
202
upcall_exchange_malloc_dyn (type_desc *td, uintptr_t size) {
196
- s_exchange_malloc_dyn_args args = {0 , td, size};
197
- UPCALL_SWITCH_STACK (&args, upcall_s_exchange_malloc_dyn);
203
+ rust_task *task = rust_get_current_task ();
204
+ s_exchange_malloc_dyn_args args = {task, 0 , td, size};
205
+ UPCALL_SWITCH_STACK (task, &args, upcall_s_exchange_malloc_dyn);
198
206
return args.retval ;
199
207
}
200
208
201
209
struct s_exchange_free_args {
210
+ rust_task *task;
202
211
void *ptr;
203
212
};
204
213
205
214
extern " C" CDECL void
206
215
upcall_s_exchange_free (s_exchange_free_args *args) {
207
- rust_task *task = rust_get_current_task () ;
216
+ rust_task *task = args-> task ;
208
217
LOG_UPCALL_ENTRY (task);
209
218
task->kernel ->free (args->ptr );
210
219
}
211
220
212
221
extern " C" CDECL void
213
222
upcall_exchange_free (void *ptr) {
214
- s_exchange_free_args args = {ptr};
215
- UPCALL_SWITCH_STACK (&args, upcall_s_exchange_free);
223
+ rust_task *task = rust_get_current_task ();
224
+ s_exchange_free_args args = {task,ptr};
225
+ UPCALL_SWITCH_STACK (task, &args, upcall_s_exchange_free);
216
226
}
217
227
218
228
/* *********************************************************************
@@ -241,43 +251,47 @@ shared_malloc(rust_task *task, type_desc *td, uintptr_t size) {
241
251
242
252
// FIXME: remove after snapshot (6/13/12)
243
253
struct s_malloc_args {
254
+ rust_task *task;
244
255
uintptr_t retval;
245
256
type_desc *td;
246
257
};
247
258
248
259
extern " C" CDECL void
249
260
upcall_s_malloc (s_malloc_args *args) {
250
- rust_task *task = rust_get_current_task () ;
261
+ rust_task *task = args-> task ;
251
262
LOG_UPCALL_ENTRY (task);
252
263
253
264
args->retval = shared_malloc (task, args->td , args->td ->size );
254
265
}
255
266
256
267
extern " C" CDECL uintptr_t
257
268
upcall_malloc (type_desc *td) {
258
- s_malloc_args args = {0 , td};
259
- UPCALL_SWITCH_STACK (&args, upcall_s_malloc);
269
+ rust_task *task = rust_get_current_task ();
270
+ s_malloc_args args = {task, 0 , td};
271
+ UPCALL_SWITCH_STACK (task, &args, upcall_s_malloc);
260
272
return args.retval ;
261
273
}
262
274
263
275
struct s_malloc_dyn_args {
276
+ rust_task *task;
264
277
uintptr_t retval;
265
278
type_desc *td;
266
279
uintptr_t size;
267
280
};
268
281
269
282
extern " C" CDECL void
270
283
upcall_s_malloc_dyn (s_malloc_dyn_args *args) {
271
- rust_task *task = rust_get_current_task () ;
284
+ rust_task *task = args-> task ;
272
285
LOG_UPCALL_ENTRY (task);
273
286
274
287
args->retval = shared_malloc (task, args->td , args->size );
275
288
}
276
289
277
290
extern " C" CDECL uintptr_t
278
291
upcall_malloc_dyn (type_desc *td, uintptr_t size) {
279
- s_malloc_dyn_args args = {0 , td, size};
280
- UPCALL_SWITCH_STACK (&args, upcall_s_malloc_dyn);
292
+ rust_task *task = rust_get_current_task ();
293
+ s_malloc_dyn_args args = {task, 0 , td, size};
294
+ UPCALL_SWITCH_STACK (task, &args, upcall_s_malloc_dyn);
281
295
return args.retval ;
282
296
}
283
297
@@ -287,12 +301,13 @@ upcall_malloc_dyn(type_desc *td, uintptr_t size) {
287
301
*/
288
302
289
303
struct s_free_args {
304
+ rust_task *task;
290
305
void *ptr;
291
306
};
292
307
293
308
extern " C" CDECL void
294
309
upcall_s_free (s_free_args *args) {
295
- rust_task *task = rust_get_current_task () ;
310
+ rust_task *task = args-> task ;
296
311
LOG_UPCALL_ENTRY (task);
297
312
298
313
rust_sched_loop *sched_loop = task->sched_loop ;
@@ -308,8 +323,9 @@ upcall_s_free(s_free_args *args) {
308
323
309
324
extern " C" CDECL void
310
325
upcall_free (void * ptr) {
311
- s_free_args args = {ptr};
312
- UPCALL_SWITCH_STACK (&args, upcall_s_free);
326
+ rust_task *task = rust_get_current_task ();
327
+ s_free_args args = {task,ptr};
328
+ UPCALL_SWITCH_STACK (task, &args, upcall_s_free);
313
329
}
314
330
315
331
/* *********************************************************************
@@ -330,44 +346,48 @@ upcall_validate_box(rust_opaque_box* ptr) {
330
346
/* *********************************************************************/
331
347
332
348
struct s_str_new_uniq_args {
349
+ rust_task *task;
333
350
const char *cstr;
334
351
size_t len;
335
352
rust_str *retval;
336
353
};
337
354
338
355
extern " C" CDECL void
339
356
upcall_s_str_new_uniq (s_str_new_uniq_args *args) {
340
- rust_task *task = rust_get_current_task () ;
357
+ rust_task *task = args-> task ;
341
358
LOG_UPCALL_ENTRY (task);
342
359
args->retval = make_str (task->kernel , args->cstr , args->len ,
343
360
" str_new_uniq" );
344
361
}
345
362
346
363
extern " C" CDECL rust_str*
347
364
upcall_str_new_uniq (const char *cstr, size_t len) {
348
- s_str_new_uniq_args args = { cstr, len, 0 };
349
- UPCALL_SWITCH_STACK (&args, upcall_s_str_new_uniq);
365
+ rust_task *task = rust_get_current_task ();
366
+ s_str_new_uniq_args args = { task, cstr, len, 0 };
367
+ UPCALL_SWITCH_STACK (task, &args, upcall_s_str_new_uniq);
350
368
return args.retval ;
351
369
}
352
370
353
371
extern " C" CDECL rust_str*
354
372
upcall_str_new (const char *cstr, size_t len) {
355
- s_str_new_uniq_args args = { cstr, len, 0 };
356
- UPCALL_SWITCH_STACK (&args, upcall_s_str_new_uniq);
373
+ rust_task *task = rust_get_current_task ();
374
+ s_str_new_uniq_args args = { task, cstr, len, 0 };
375
+ UPCALL_SWITCH_STACK (task, &args, upcall_s_str_new_uniq);
357
376
return args.retval ;
358
377
}
359
378
360
379
361
380
362
381
struct s_str_new_shared_args {
382
+ rust_task *task;
363
383
const char *cstr;
364
384
size_t len;
365
385
rust_opaque_box *retval;
366
386
};
367
387
368
388
extern " C" CDECL void
369
389
upcall_s_str_new_shared (s_str_new_shared_args *args) {
370
- rust_task *task = rust_get_current_task () ;
390
+ rust_task *task = args-> task ;
371
391
LOG_UPCALL_ENTRY (task);
372
392
373
393
size_t str_fill = args->len + 1 ;
@@ -384,32 +404,36 @@ upcall_s_str_new_shared(s_str_new_shared_args *args) {
384
404
385
405
extern " C" CDECL rust_opaque_box*
386
406
upcall_str_new_shared (const char *cstr, size_t len) {
387
- s_str_new_shared_args args = { cstr, len, 0 };
388
- UPCALL_SWITCH_STACK (&args, upcall_s_str_new_shared);
407
+ rust_task *task = rust_get_current_task ();
408
+ s_str_new_shared_args args = { task, cstr, len, 0 };
409
+ UPCALL_SWITCH_STACK (task, &args, upcall_s_str_new_shared);
389
410
return args.retval ;
390
411
}
391
412
392
413
393
414
struct s_vec_grow_args {
415
+ rust_task *task;
394
416
rust_vec_box** vp;
395
417
size_t new_sz;
396
418
};
397
419
398
420
extern " C" CDECL void
399
421
upcall_s_vec_grow (s_vec_grow_args *args) {
400
- rust_task *task = rust_get_current_task () ;
422
+ rust_task *task = args-> task ;
401
423
LOG_UPCALL_ENTRY (task);
402
424
reserve_vec (task, args->vp , args->new_sz );
403
425
(*args->vp )->body .fill = args->new_sz ;
404
426
}
405
427
406
428
extern " C" CDECL void
407
429
upcall_vec_grow (rust_vec_box** vp, size_t new_sz) {
408
- s_vec_grow_args args = {vp, new_sz};
409
- UPCALL_SWITCH_STACK (&args, upcall_s_vec_grow);
430
+ rust_task *task = rust_get_current_task ();
431
+ s_vec_grow_args args = {task, vp, new_sz};
432
+ UPCALL_SWITCH_STACK (task, &args, upcall_s_vec_grow);
410
433
}
411
434
412
435
struct s_str_concat_args {
436
+ rust_task *task;
413
437
rust_vec_box* lhs;
414
438
rust_vec_box* rhs;
415
439
rust_vec_box* retval;
@@ -419,7 +443,7 @@ extern "C" CDECL void
419
443
upcall_s_str_concat (s_str_concat_args *args) {
420
444
rust_vec *lhs = &args->lhs ->body ;
421
445
rust_vec *rhs = &args->rhs ->body ;
422
- rust_task *task = rust_get_current_task () ;
446
+ rust_task *task = args-> task ;
423
447
size_t fill = lhs->fill + rhs->fill - 1 ;
424
448
rust_vec_box* v = (rust_vec_box*)
425
449
task->kernel ->malloc (fill + sizeof (rust_vec_box),
@@ -433,8 +457,9 @@ upcall_s_str_concat(s_str_concat_args *args) {
433
457
434
458
extern " C" CDECL rust_vec_box*
435
459
upcall_str_concat (rust_vec_box* lhs, rust_vec_box* rhs) {
436
- s_str_concat_args args = {lhs, rhs, 0 };
437
- UPCALL_SWITCH_STACK (&args, upcall_s_str_concat);
460
+ rust_task *task = rust_get_current_task ();
461
+ s_str_concat_args args = {task, lhs, rhs, 0 };
462
+ UPCALL_SWITCH_STACK (task, &args, upcall_s_str_concat);
438
463
return args.retval ;
439
464
}
440
465
@@ -486,7 +511,7 @@ upcall_rust_personality(int version,
486
511
// then switch to the C stack.
487
512
488
513
if (task->on_rust_stack ()) {
489
- UPCALL_SWITCH_STACK (&args, upcall_s_rust_personality);
514
+ UPCALL_SWITCH_STACK (task, &args, upcall_s_rust_personality);
490
515
} else {
491
516
upcall_s_rust_personality (&args);
492
517
}
@@ -517,9 +542,10 @@ extern "C" void
517
542
upcall_cmp_type (int8_t *result, const type_desc *tydesc,
518
543
const type_desc **subtydescs, uint8_t *data_0,
519
544
uint8_t *data_1, uint8_t cmp_type) {
545
+ rust_task *task = rust_get_current_task ();
520
546
s_cmp_type_args args = {result, tydesc, subtydescs,
521
547
data_0, data_1, cmp_type};
522
- UPCALL_SWITCH_STACK (&args, upcall_s_cmp_type);
548
+ UPCALL_SWITCH_STACK (task, &args, upcall_s_cmp_type);
523
549
}
524
550
525
551
extern " C" void
@@ -538,8 +564,9 @@ upcall_s_log_type(s_log_type_args *args) {
538
564
539
565
extern " C" void
540
566
upcall_log_type (const type_desc *tydesc, uint8_t *data, uint32_t level) {
567
+ rust_task *task = rust_get_current_task ();
541
568
s_log_type_args args = {tydesc, data, level};
542
- UPCALL_SWITCH_STACK (&args, upcall_s_log_type);
569
+ UPCALL_SWITCH_STACK (task, &args, upcall_s_log_type);
543
570
}
544
571
545
572
// NB: This needs to be blazing fast. Don't switch stacks
0 commit comments