Skip to content

Commit 1328b78

Browse files
committed
---
yaml --- r: 5358 b: refs/heads/master c: 3632629 h: refs/heads/master v: v3
1 parent 8869218 commit 1328b78

File tree

4 files changed

+60
-2
lines changed

4 files changed

+60
-2
lines changed

[refs]

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 5f44a1356e2b0adce5157f5e331ab9a55e891b0a
2+
refs/heads/master: 3632629acc96b2e3094033de47d6dd311749e112

trunk/src/rt/rust_box.h

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/* Rust box representation. */
2+
3+
#ifndef RUST_BOX_H
4+
#define RUST_BOX_H
5+
6+
#include "rust_internal.h"
7+
#include <stdint.h>
8+
9+
struct rust_box {
10+
RUST_REFCOUNTED(rust_box)
11+
type_desc *tydesc;
12+
rust_box *gc_next;
13+
rust_box *gc_prev;
14+
uint8_t data[0];
15+
};
16+
17+
#endif
18+

trunk/src/rt/rust_task.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include "context.h"
1111
#include "rust_obstack.h"
1212

13+
struct rust_box;
14+
1315
struct stk_seg {
1416
unsigned int valgrind_id;
1517
uintptr_t limit;
@@ -57,7 +59,7 @@ rust_task : public kernel_owned<rust_task>, rust_cond
5759
context ctx;
5860
stk_seg *stk;
5961
uintptr_t runtime_sp; // Runtime sp while task running.
60-
void *gc_alloc_chain; // Linked list of GC allocations.
62+
rust_box *gc_alloc_chain; // Linked list of GC allocations.
6163
rust_scheduler *sched;
6264
rust_crate_cache *cache;
6365

trunk/src/rt/rust_upcall.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include "rust_box.h"
12
#include "rust_gc.h"
23
#include "rust_internal.h"
34
#include "rust_unwind.h"
@@ -76,6 +77,25 @@ upcall_malloc(rust_task *task, size_t nbytes, type_desc *td) {
7677
return (uintptr_t) p;
7778
}
7879

80+
extern "C" CDECL rust_box *
81+
upcall_malloc_box(rust_task *task, size_t nbytes, type_desc *td) {
82+
LOG_UPCALL_ENTRY(task);
83+
84+
gc::maybe_gc(task);
85+
86+
rust_box *box = reinterpret_cast<rust_box *>
87+
(task->malloc(nbytes + sizeof(rust_box), "tdesc", td));
88+
box->ref_count = 1;
89+
box->tydesc = td;
90+
91+
box->gc_prev = NULL;
92+
if ((box->gc_next = task->gc_alloc_chain) != NULL)
93+
box->gc_next->gc_prev = box;
94+
task->gc_alloc_chain = box;
95+
96+
return box;
97+
}
98+
7999
/**
80100
* Called whenever an object's ref count drops to zero.
81101
*/
@@ -90,6 +110,24 @@ upcall_free(rust_task *task, void* ptr, uintptr_t is_gc) {
90110
task->free(ptr, (bool) is_gc);
91111
}
92112

113+
extern "C" CDECL void
114+
upcall_free_box(rust_task *task, rust_box *box) {
115+
LOG_UPCALL_ENTRY(task);
116+
117+
assert(!box->ref_count && "Box reference count is nonzero on free!");
118+
119+
if (box->gc_prev)
120+
box->gc_prev->gc_next = box->gc_next;
121+
else
122+
task->gc_alloc_chain = box->gc_next;
123+
if (box->gc_next)
124+
box->gc_next->gc_prev = box->gc_prev;
125+
126+
box->tydesc->drop_glue(NULL, task, (void *)box->tydesc,
127+
box->tydesc->first_param, box->data);
128+
task->free(box, false);
129+
}
130+
93131
extern "C" CDECL uintptr_t
94132
upcall_shared_malloc(rust_task *task, size_t nbytes, type_desc *td) {
95133
LOG_UPCALL_ENTRY(task);

0 commit comments

Comments
 (0)