Skip to content

Commit 7f80e45

Browse files
committed
---
yaml --- r: 4826 b: refs/heads/master c: 396f6b4 h: refs/heads/master v: v3
1 parent a3e1aa4 commit 7f80e45

File tree

3 files changed

+72
-1
lines changed

3 files changed

+72
-1
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 0fedea39cecb61c46aa7ca93374ce39e98acbb6e
2+
refs/heads/master: 396f6b4f599edaf6dd9fe5593258428246ba3328

trunk/mk/rt.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ RUNTIME_CS := rt/sync/timer.cpp \
2525
rt/rust_kernel.cpp \
2626
rt/rust_shape.cpp \
2727
rt/rust_obstack.cpp \
28+
rt/rust_gc.cpp \
2829
rt/memory_region.cpp \
2930
rt/test/rust_test_harness.cpp \
3031
rt/test/rust_test_runtime.cpp \

trunk/src/rt/rust_gc.cpp

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Rust garbage collection.
2+
3+
// TODO: Windows
4+
#include <utility>
5+
#include <stdint.h>
6+
7+
#include "rust_internal.h"
8+
9+
#ifdef __WIN32__
10+
#include <windows.h>
11+
#else
12+
#include <dlfcn.h>
13+
#endif
14+
15+
namespace gc {
16+
17+
struct root {
18+
intptr_t frame_offset;
19+
uintptr_t dynamic; // 0 = static, 1 = dynamic
20+
type_desc *tydesc;
21+
};
22+
23+
struct safe_point {
24+
uintptr_t n_roots;
25+
root roots[0];
26+
};
27+
28+
class safe_point_map {
29+
uintptr_t n_safe_points;
30+
const std::pair<void *,const safe_point *> *index;
31+
const safe_point *safe_points;
32+
33+
public:
34+
safe_point_map() {
35+
const uintptr_t *data;
36+
#ifdef __WIN32__
37+
data = (const uintptr_t *)GetProcAddress(GetModuleHandle(NULL),
38+
"rust_gc_safe_points");
39+
#else
40+
data = (const uintptr_t *)dlsym(RTLD_DEFAULT, "rust_gc_safe_points");
41+
#endif
42+
n_safe_points = *data++;
43+
index = (const std::pair<void *,const safe_point *> *)data;
44+
data += n_safe_points;
45+
safe_points = (const safe_point *)data;
46+
}
47+
};
48+
49+
void
50+
gc() {
51+
safe_point_map map;
52+
53+
// TODO
54+
}
55+
56+
void
57+
maybe_gc() {
58+
// FIXME: We ought to lock this.
59+
static int zeal = -1;
60+
if (zeal == -1) {
61+
char *ev = getenv("RUST_GC_ZEAL");
62+
zeal = ev[0] != '\0' && ev[0] != '0';
63+
}
64+
65+
if (zeal)
66+
gc();
67+
}
68+
69+
}
70+

0 commit comments

Comments
 (0)