Skip to content

Commit ccf35ed

Browse files
committed
---
yaml --- r: 10572 b: refs/heads/snap-stage3 c: ee9e5b9 h: refs/heads/master v: v3
1 parent 74e08ce commit ccf35ed

File tree

2 files changed

+72
-45
lines changed

2 files changed

+72
-45
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
refs/heads/master: 2898dcc5d97da9427ac367542382b6239d9c0bbf
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: 30dd32d4db0834a9bb965cfceaee3211f09a5344
4+
refs/heads/snap-stage3: ee9e5b9d201d876c07b00663e2df224eb170a0f2
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105

branches/snap-stage3/src/rt/rust_upcall.cpp

Lines changed: 71 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
(task)->name, (task));
2929
#endif
3030

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)
3233

3334
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) {
3636
task->call_on_c_stack(args, fn_ptr);
3737
}
3838

@@ -93,14 +93,15 @@ upcall_call_shim_on_rust_stack(void *args, void *fn_ptr) {
9393
/**********************************************************************/
9494

9595
struct s_fail_args {
96+
rust_task *task;
9697
char const *expr;
9798
char const *file;
9899
size_t line;
99100
};
100101

101102
extern "C" CDECL void
102103
upcall_s_fail(s_fail_args *args) {
103-
rust_task *task = rust_get_current_task();
104+
rust_task *task = args->task;
104105
LOG_UPCALL_ENTRY(task);
105106
task->fail(args->expr, args->file, args->line);
106107
}
@@ -109,19 +110,21 @@ extern "C" CDECL void
109110
upcall_fail(char const *expr,
110111
char const *file,
111112
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);
114116
}
115117

116118
struct s_trace_args {
119+
rust_task *task;
117120
char const *msg;
118121
char const *file;
119122
size_t line;
120123
};
121124

122125
extern "C" CDECL void
123126
upcall_s_trace(s_trace_args *args) {
124-
rust_task *task = rust_get_current_task();
127+
rust_task *task = args->task;
125128
LOG_UPCALL_ENTRY(task);
126129
LOG(task, trace, "Trace %s:%d: %s",
127130
args->file, args->line, args->msg);
@@ -131,8 +134,9 @@ extern "C" CDECL void
131134
upcall_trace(char const *msg,
132135
char const *file,
133136
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);
136140
}
137141

138142
/**********************************************************************
@@ -158,61 +162,67 @@ exchange_malloc(rust_task *task, type_desc *td, uintptr_t size) {
158162

159163
// FIXME: remove after snapshot (6/13/12)
160164
struct s_exchange_malloc_args {
165+
rust_task *task;
161166
uintptr_t retval;
162167
type_desc *td;
163168
};
164169

165170
extern "C" CDECL void
166171
upcall_s_exchange_malloc(s_exchange_malloc_args *args) {
167-
rust_task *task = rust_get_current_task();
172+
rust_task *task = args->task;
168173
LOG_UPCALL_ENTRY(task);
169174

170175
args->retval = exchange_malloc(task, args->td, args->td->size);
171176
}
172177

173178
extern "C" CDECL uintptr_t
174179
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);
177183
return args.retval;
178184
}
179185

180186
struct s_exchange_malloc_dyn_args {
187+
rust_task *task;
181188
uintptr_t retval;
182189
type_desc *td;
183190
uintptr_t size;
184191
};
185192

186193
extern "C" CDECL void
187194
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;
189196
LOG_UPCALL_ENTRY(task);
190197

191198
args->retval = exchange_malloc(task, args->td, args->size);
192199
}
193200

194201
extern "C" CDECL uintptr_t
195202
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);
198206
return args.retval;
199207
}
200208

201209
struct s_exchange_free_args {
210+
rust_task *task;
202211
void *ptr;
203212
};
204213

205214
extern "C" CDECL void
206215
upcall_s_exchange_free(s_exchange_free_args *args) {
207-
rust_task *task = rust_get_current_task();
216+
rust_task *task = args->task;
208217
LOG_UPCALL_ENTRY(task);
209218
task->kernel->free(args->ptr);
210219
}
211220

212221
extern "C" CDECL void
213222
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);
216226
}
217227

218228
/**********************************************************************
@@ -241,43 +251,47 @@ shared_malloc(rust_task *task, type_desc *td, uintptr_t size) {
241251

242252
// FIXME: remove after snapshot (6/13/12)
243253
struct s_malloc_args {
254+
rust_task *task;
244255
uintptr_t retval;
245256
type_desc *td;
246257
};
247258

248259
extern "C" CDECL void
249260
upcall_s_malloc(s_malloc_args *args) {
250-
rust_task *task = rust_get_current_task();
261+
rust_task *task = args->task;
251262
LOG_UPCALL_ENTRY(task);
252263

253264
args->retval = shared_malloc(task, args->td, args->td->size);
254265
}
255266

256267
extern "C" CDECL uintptr_t
257268
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);
260272
return args.retval;
261273
}
262274

263275
struct s_malloc_dyn_args {
276+
rust_task *task;
264277
uintptr_t retval;
265278
type_desc *td;
266279
uintptr_t size;
267280
};
268281

269282
extern "C" CDECL void
270283
upcall_s_malloc_dyn(s_malloc_dyn_args *args) {
271-
rust_task *task = rust_get_current_task();
284+
rust_task *task = args->task;
272285
LOG_UPCALL_ENTRY(task);
273286

274287
args->retval = shared_malloc(task, args->td, args->size);
275288
}
276289

277290
extern "C" CDECL uintptr_t
278291
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);
281295
return args.retval;
282296
}
283297

@@ -287,12 +301,13 @@ upcall_malloc_dyn(type_desc *td, uintptr_t size) {
287301
*/
288302

289303
struct s_free_args {
304+
rust_task *task;
290305
void *ptr;
291306
};
292307

293308
extern "C" CDECL void
294309
upcall_s_free(s_free_args *args) {
295-
rust_task *task = rust_get_current_task();
310+
rust_task *task = args->task;
296311
LOG_UPCALL_ENTRY(task);
297312

298313
rust_sched_loop *sched_loop = task->sched_loop;
@@ -308,8 +323,9 @@ upcall_s_free(s_free_args *args) {
308323

309324
extern "C" CDECL void
310325
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);
313329
}
314330

315331
/**********************************************************************
@@ -330,44 +346,48 @@ upcall_validate_box(rust_opaque_box* ptr) {
330346
/**********************************************************************/
331347

332348
struct s_str_new_uniq_args {
349+
rust_task *task;
333350
const char *cstr;
334351
size_t len;
335352
rust_str *retval;
336353
};
337354

338355
extern "C" CDECL void
339356
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;
341358
LOG_UPCALL_ENTRY(task);
342359
args->retval = make_str(task->kernel, args->cstr, args->len,
343360
"str_new_uniq");
344361
}
345362

346363
extern "C" CDECL rust_str*
347364
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);
350368
return args.retval;
351369
}
352370

353371
extern "C" CDECL rust_str*
354372
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);
357376
return args.retval;
358377
}
359378

360379

361380

362381
struct s_str_new_shared_args {
382+
rust_task *task;
363383
const char *cstr;
364384
size_t len;
365385
rust_opaque_box *retval;
366386
};
367387

368388
extern "C" CDECL void
369389
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;
371391
LOG_UPCALL_ENTRY(task);
372392

373393
size_t str_fill = args->len + 1;
@@ -384,32 +404,36 @@ upcall_s_str_new_shared(s_str_new_shared_args *args) {
384404

385405
extern "C" CDECL rust_opaque_box*
386406
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);
389410
return args.retval;
390411
}
391412

392413

393414
struct s_vec_grow_args {
415+
rust_task *task;
394416
rust_vec_box** vp;
395417
size_t new_sz;
396418
};
397419

398420
extern "C" CDECL void
399421
upcall_s_vec_grow(s_vec_grow_args *args) {
400-
rust_task *task = rust_get_current_task();
422+
rust_task *task = args->task;
401423
LOG_UPCALL_ENTRY(task);
402424
reserve_vec(task, args->vp, args->new_sz);
403425
(*args->vp)->body.fill = args->new_sz;
404426
}
405427

406428
extern "C" CDECL void
407429
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);
410433
}
411434

412435
struct s_str_concat_args {
436+
rust_task *task;
413437
rust_vec_box* lhs;
414438
rust_vec_box* rhs;
415439
rust_vec_box* retval;
@@ -419,7 +443,7 @@ extern "C" CDECL void
419443
upcall_s_str_concat(s_str_concat_args *args) {
420444
rust_vec *lhs = &args->lhs->body;
421445
rust_vec *rhs = &args->rhs->body;
422-
rust_task *task = rust_get_current_task();
446+
rust_task *task = args->task;
423447
size_t fill = lhs->fill + rhs->fill - 1;
424448
rust_vec_box* v = (rust_vec_box*)
425449
task->kernel->malloc(fill + sizeof(rust_vec_box),
@@ -433,8 +457,9 @@ upcall_s_str_concat(s_str_concat_args *args) {
433457

434458
extern "C" CDECL rust_vec_box*
435459
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);
438463
return args.retval;
439464
}
440465

@@ -486,7 +511,7 @@ upcall_rust_personality(int version,
486511
// then switch to the C stack.
487512

488513
if (task->on_rust_stack()) {
489-
UPCALL_SWITCH_STACK(&args, upcall_s_rust_personality);
514+
UPCALL_SWITCH_STACK(task, &args, upcall_s_rust_personality);
490515
} else {
491516
upcall_s_rust_personality(&args);
492517
}
@@ -517,9 +542,10 @@ extern "C" void
517542
upcall_cmp_type(int8_t *result, const type_desc *tydesc,
518543
const type_desc **subtydescs, uint8_t *data_0,
519544
uint8_t *data_1, uint8_t cmp_type) {
545+
rust_task *task = rust_get_current_task();
520546
s_cmp_type_args args = {result, tydesc, subtydescs,
521547
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);
523549
}
524550

525551
extern "C" void
@@ -538,8 +564,9 @@ upcall_s_log_type(s_log_type_args *args) {
538564

539565
extern "C" void
540566
upcall_log_type(const type_desc *tydesc, uint8_t *data, uint32_t level) {
567+
rust_task *task = rust_get_current_task();
541568
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);
543570
}
544571

545572
// NB: This needs to be blazing fast. Don't switch stacks

0 commit comments

Comments
 (0)