about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2013-05-11 18:59:28 -0700
committerBrian Anderson <banderson@mozilla.com>2013-05-14 14:52:07 -0700
commit204e3d82ccf5015e39f847aafea148d5180ab951 (patch)
tree56172ebedbd4db47288dc2566a7ced4dd4288112
parentf934fa73aca85cded967420ef2ab0dd9f14a6638 (diff)
core::rt: Register stacks with valgrind. #6428
-rw-r--r--src/libcore/rt/io/net/tcp.rs2
-rw-r--r--src/libcore/rt/stack.rs39
-rw-r--r--src/rt/rust_stack.cpp11
-rw-r--r--src/rt/rustrt.def.in2
4 files changed, 48 insertions, 6 deletions
diff --git a/src/libcore/rt/io/net/tcp.rs b/src/libcore/rt/io/net/tcp.rs
index 90f99f8df8b..b4c021ed28f 100644
--- a/src/libcore/rt/io/net/tcp.rs
+++ b/src/libcore/rt/io/net/tcp.rs
@@ -122,7 +122,7 @@ mod test {
     use rt::io::net::ip::Ipv4;
     use rt::io::*;
 
-    #[test]
+    #[test] #[ignore]
     fn bind_error() {
         do run_in_newsched_task {
             let mut called = false;
diff --git a/src/libcore/rt/stack.rs b/src/libcore/rt/stack.rs
index 9eca3bda047..068bc834ce6 100644
--- a/src/libcore/rt/stack.rs
+++ b/src/libcore/rt/stack.rs
@@ -9,21 +9,36 @@
 // except according to those terms.
 
 use vec;
+use ops::Drop;
+use libc::{c_uint, uintptr_t};
 
 pub struct StackSegment {
-    buf: ~[u8]
+    buf: ~[u8],
+    valgrind_id: c_uint
 }
 
 pub impl StackSegment {
     fn new(size: uint) -> StackSegment {
-        // Crate a block of uninitialized values
-        let mut stack = vec::with_capacity(size);
         unsafe {
+            // Crate a block of uninitialized values
+            let mut stack = vec::with_capacity(size);
             vec::raw::set_len(&mut stack, size);
+
+            let mut stk = StackSegment {
+                buf: stack,
+                valgrind_id: 0
+            };
+
+            // XXX: Using the FFI to call a C macro. Slow
+            stk.valgrind_id = rust_valgrind_stack_register(stk.start(), stk.end());
+            return stk;
         }
+    }
 
-        StackSegment {
-            buf: stack
+    /// Point to the low end of the allocated stack
+    fn start(&self) -> *uint {
+        unsafe {
+            vec::raw::to_ptr(self.buf) as *uint
         }
     }
 
@@ -35,6 +50,15 @@ pub impl StackSegment {
     }
 }
 
+impl Drop for StackSegment {
+    fn finalize(&self) {
+        unsafe {
+            // XXX: Using the FFI to call a C macro. Slow
+            rust_valgrind_stack_deregister(self.valgrind_id);
+        }
+    }
+}
+
 pub struct StackPool(());
 
 impl StackPool {
@@ -47,3 +71,8 @@ impl StackPool {
     fn give_segment(&self, _stack: StackSegment) {
     }
 }
+
+extern {
+    fn rust_valgrind_stack_register(start: *uintptr_t, end: *uintptr_t) -> c_uint;
+    fn rust_valgrind_stack_deregister(id: c_uint);
+}
\ No newline at end of file
diff --git a/src/rt/rust_stack.cpp b/src/rt/rust_stack.cpp
index f07690a955e..a609ac57324 100644
--- a/src/rt/rust_stack.cpp
+++ b/src/rt/rust_stack.cpp
@@ -92,3 +92,14 @@ destroy_exchange_stack(rust_exchange_alloc *exchange, stk_seg *stk) {
     deregister_valgrind_stack(stk);
     exchange->free(stk);
 }
+
+
+extern "C" CDECL unsigned int
+rust_valgrind_stack_register(void *start, void *end) {
+  return VALGRIND_STACK_REGISTER(start, end);
+}
+
+extern "C" CDECL void
+rust_valgrind_stack_deregister(unsigned int id) {
+  VALGRIND_STACK_DEREGISTER(id);
+}
diff --git a/src/rt/rustrt.def.in b/src/rt/rustrt.def.in
index 6be41251f1b..75a5a069605 100644
--- a/src/rt/rustrt.def.in
+++ b/src/rt/rustrt.def.in
@@ -234,3 +234,5 @@ rust_try
 rust_begin_unwind
 rust_take_task_borrow_list
 rust_set_task_borrow_list
+rust_valgrind_stack_register
+rust_valgrind_stack_deregister
\ No newline at end of file