File tree Expand file tree Collapse file tree 3 files changed +72
-1
lines changed Expand file tree Collapse file tree 3 files changed +72
-1
lines changed Original file line number Diff line number Diff line change 1
1
---
2
- refs/heads/master: 0fedea39cecb61c46aa7ca93374ce39e98acbb6e
2
+ refs/heads/master: 396f6b4f599edaf6dd9fe5593258428246ba3328
Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ RUNTIME_CS := rt/sync/timer.cpp \
25
25
rt/rust_kernel.cpp \
26
26
rt/rust_shape.cpp \
27
27
rt/rust_obstack.cpp \
28
+ rt/rust_gc.cpp \
28
29
rt/memory_region.cpp \
29
30
rt/test/rust_test_harness.cpp \
30
31
rt/test/rust_test_runtime.cpp \
Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments