about summary refs log tree commit diff
path: root/src/rt/rust_crate_map.cpp
diff options
context:
space:
mode:
authorElliott Slaughter <eslaughter@mozilla.com>2012-07-16 12:28:15 -0700
committerElliott Slaughter <eslaughter@mozilla.com>2012-09-07 09:21:21 -0700
commit3f0d207b3251e598488588765b942bf6b7a4f9bb (patch)
tree98fad8b4761bb95d63615e7e2217ca559bd4962a /src/rt/rust_crate_map.cpp
parentfb8786fe522ed96172cf1ae8e205e3f2722e834c (diff)
downloadrust-3f0d207b3251e598488588765b942bf6b7a4f9bb.tar.gz
rust-3f0d207b3251e598488588765b942bf6b7a4f9bb.zip
gc: Add stack walker for new garbage collector.
Safe points are exported in a per-module list via the crate map. A C
runtime call walks the crate map at startup and aggregates the list of
safe points for the program.

Currently the GC doesn't actually deallocate memory on malloc and
free. Adding the GC at this stage is primarily of testing value.

The GC does attempt to clean up exchange heap and stack-allocated
resource on failure.

A result of this patch is that the user now needs to be careful about
what code they write in destructors, because the GC and/or failure
cleanup may need to call destructors. Specifically, calls to malloc
are considered unsafe and may result in infinite loops or segfaults.
Diffstat (limited to 'src/rt/rust_crate_map.cpp')
-rw-r--r--src/rt/rust_crate_map.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/rt/rust_crate_map.cpp b/src/rt/rust_crate_map.cpp
new file mode 100644
index 00000000000..633361bb932
--- /dev/null
+++ b/src/rt/rust_crate_map.cpp
@@ -0,0 +1,33 @@
+#include "rust_crate_map.h"
+
+void iter_module_map(const mod_entry* map,
+                     void (*fn)(const mod_entry* entry, void *cookie),
+                     void *cookie) {
+    for (const mod_entry* cur = map; cur->name; cur++) {
+        fn(cur, cookie);
+    }
+}
+
+void iter_crate_map(const cratemap* map,
+                    void (*fn)(const mod_entry* map, void *cookie),
+                    void *cookie) {
+    // First iterate this crate
+    iter_module_map(map->entries, fn, cookie);
+    // Then recurse on linked crates
+    // FIXME (#2673) this does double work in diamond-shaped deps. could
+    //   keep a set of visited addresses, if it turns out to be actually
+    //   slow
+    for (size_t i = 0; map->children[i]; i++) {
+        iter_crate_map(map->children[i], fn, cookie);
+    }
+}
+
+//
+// Local Variables:
+// mode: C++
+// fill-column: 78;
+// indent-tabs-mode: nil
+// c-basic-offset: 4
+// buffer-file-coding-system: utf-8-unix
+// End:
+//