Skip to content

Commit 1b10170

Browse files
committed
rt: Make some runtime calls work outside of task context
1 parent a8f07dc commit 1b10170

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

src/rt/rust_builtin.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ vec_reserve_shared_actual(type_desc* ty, rust_vec_box** vp,
124124
extern "C" CDECL void
125125
vec_reserve_shared(type_desc* ty, rust_vec_box** vp,
126126
size_t n_elts) {
127-
rust_task *task = rust_get_current_task();
128-
reserve_vec_exact(task, vp, n_elts * ty->size);
127+
reserve_vec_exact(vp, n_elts * ty->size);
129128
}
130129

131130
extern "C" CDECL size_t
@@ -445,9 +444,8 @@ void tm_to_rust_tm(tm* in_tm, rust_tm* out_tm, int32_t gmtoff,
445444
out_tm->tm_nsec = nsec;
446445

447446
if (zone != NULL) {
448-
rust_task *task = rust_get_current_task();
449447
size_t size = strlen(zone);
450-
reserve_vec_exact(task, &out_tm->tm_zone, size + 1);
448+
reserve_vec_exact(&out_tm->tm_zone, size + 1);
451449
memcpy(out_tm->tm_zone->body.data, zone, size);
452450
out_tm->tm_zone->body.fill = size + 1;
453451
out_tm->tm_zone->body.data[size] = '\0';

src/rt/rust_upcall.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ extern "C" CDECL void
118118
upcall_fail(char const *expr,
119119
char const *file,
120120
size_t line) {
121-
rust_task *task = rust_get_current_task();
121+
rust_task *task = rust_try_get_current_task();
122+
if (task == NULL) {
123+
// NOTE: Need to think about what to do here
124+
printf("failure outside of a task");
125+
abort();
126+
}
122127
s_fail_args args = {task,expr,file,line};
123128
UPCALL_SWITCH_STACK(task, &args, upcall_s_fail);
124129
}

src/rt/rust_util.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@ inline void reserve_vec_exact_shared(rust_task* task, rust_vec_box** vpp,
6767
}
6868
}
6969

70-
inline void reserve_vec_exact(rust_task* task, rust_vec_box** vpp,
70+
inline void reserve_vec_exact(rust_vec_box** vpp,
7171
size_t size) {
7272
if (size > (*vpp)->body.alloc) {
73-
*vpp = (rust_vec_box*)task->kernel
74-
->realloc(*vpp, size + sizeof(rust_vec_box));
73+
rust_exchange_alloc exchange_alloc;
74+
*vpp = (rust_vec_box*)exchange_alloc
75+
.realloc(*vpp, size + sizeof(rust_vec_box));
7576
(*vpp)->body.alloc = size;
7677
}
7778
}

0 commit comments

Comments
 (0)