From 396f6b4f599edaf6dd9fe5593258428246ba3328 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 18 Aug 2011 18:48:32 -0700 Subject: [PATCH] rustc: Stub GC routines --- mk/rt.mk | 1 + src/rt/rust_gc.cpp | 70 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 src/rt/rust_gc.cpp diff --git a/mk/rt.mk b/mk/rt.mk index e9d77a1a3b94..7b50e579eefa 100644 --- a/mk/rt.mk +++ b/mk/rt.mk @@ -25,6 +25,7 @@ RUNTIME_CS := rt/sync/timer.cpp \ rt/rust_kernel.cpp \ rt/rust_shape.cpp \ rt/rust_obstack.cpp \ + rt/rust_gc.cpp \ rt/memory_region.cpp \ rt/test/rust_test_harness.cpp \ rt/test/rust_test_runtime.cpp \ diff --git a/src/rt/rust_gc.cpp b/src/rt/rust_gc.cpp new file mode 100644 index 000000000000..fee2d8b9834d --- /dev/null +++ b/src/rt/rust_gc.cpp @@ -0,0 +1,70 @@ +// Rust garbage collection. + +// TODO: Windows +#include +#include + +#include "rust_internal.h" + +#ifdef __WIN32__ +#include +#else +#include +#endif + +namespace gc { + +struct root { + intptr_t frame_offset; + uintptr_t dynamic; // 0 = static, 1 = dynamic + type_desc *tydesc; +}; + +struct safe_point { + uintptr_t n_roots; + root roots[0]; +}; + +class safe_point_map { + uintptr_t n_safe_points; + const std::pair *index; + const safe_point *safe_points; + +public: + safe_point_map() { + const uintptr_t *data; +#ifdef __WIN32__ + data = (const uintptr_t *)GetProcAddress(GetModuleHandle(NULL), + "rust_gc_safe_points"); +#else + data = (const uintptr_t *)dlsym(RTLD_DEFAULT, "rust_gc_safe_points"); +#endif + n_safe_points = *data++; + index = (const std::pair *)data; + data += n_safe_points; + safe_points = (const safe_point *)data; + } +}; + +void +gc() { + safe_point_map map; + + // TODO +} + +void +maybe_gc() { + // FIXME: We ought to lock this. + static int zeal = -1; + if (zeal == -1) { + char *ev = getenv("RUST_GC_ZEAL"); + zeal = ev[0] != '\0' && ev[0] != '0'; + } + + if (zeal) + gc(); +} + +} +