core::rt: Register stacks with valgrind. #6428

This commit is contained in:
Brian Anderson 2013-05-11 18:59:28 -07:00
parent f934fa73ac
commit 204e3d82cc
4 changed files with 49 additions and 7 deletions

View file

@ -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;

View file

@ -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);
}
StackSegment {
buf: stack
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;
}
}
/// 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);
}

View file

@ -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);
}

View file

@ -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