Skip to content

Commit 204e3d8

Browse files
committed
core::rt: Register stacks with valgrind. #6428
1 parent f934fa7 commit 204e3d8

File tree

4 files changed

+48
-6
lines changed

4 files changed

+48
-6
lines changed

src/libcore/rt/io/net/tcp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ mod test {
122122
use rt::io::net::ip::Ipv4;
123123
use rt::io::*;
124124

125-
#[test]
125+
#[test] #[ignore]
126126
fn bind_error() {
127127
do run_in_newsched_task {
128128
let mut called = false;

src/libcore/rt/stack.rs

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,36 @@
99
// except according to those terms.
1010

1111
use vec;
12+
use ops::Drop;
13+
use libc::{c_uint, uintptr_t};
1214

1315
pub struct StackSegment {
14-
buf: ~[u8]
16+
buf: ~[u8],
17+
valgrind_id: c_uint
1518
}
1619

1720
pub impl StackSegment {
1821
fn new(size: uint) -> StackSegment {
19-
// Crate a block of uninitialized values
20-
let mut stack = vec::with_capacity(size);
2122
unsafe {
23+
// Crate a block of uninitialized values
24+
let mut stack = vec::with_capacity(size);
2225
vec::raw::set_len(&mut stack, size);
26+
27+
let mut stk = StackSegment {
28+
buf: stack,
29+
valgrind_id: 0
30+
};
31+
32+
// XXX: Using the FFI to call a C macro. Slow
33+
stk.valgrind_id = rust_valgrind_stack_register(stk.start(), stk.end());
34+
return stk;
2335
}
36+
}
2437

25-
StackSegment {
26-
buf: stack
38+
/// Point to the low end of the allocated stack
39+
fn start(&self) -> *uint {
40+
unsafe {
41+
vec::raw::to_ptr(self.buf) as *uint
2742
}
2843
}
2944

@@ -35,6 +50,15 @@ pub impl StackSegment {
3550
}
3651
}
3752

53+
impl Drop for StackSegment {
54+
fn finalize(&self) {
55+
unsafe {
56+
// XXX: Using the FFI to call a C macro. Slow
57+
rust_valgrind_stack_deregister(self.valgrind_id);
58+
}
59+
}
60+
}
61+
3862
pub struct StackPool(());
3963

4064
impl StackPool {
@@ -47,3 +71,8 @@ impl StackPool {
4771
fn give_segment(&self, _stack: StackSegment) {
4872
}
4973
}
74+
75+
extern {
76+
fn rust_valgrind_stack_register(start: *uintptr_t, end: *uintptr_t) -> c_uint;
77+
fn rust_valgrind_stack_deregister(id: c_uint);
78+
}

src/rt/rust_stack.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,14 @@ destroy_exchange_stack(rust_exchange_alloc *exchange, stk_seg *stk) {
9292
deregister_valgrind_stack(stk);
9393
exchange->free(stk);
9494
}
95+
96+
97+
extern "C" CDECL unsigned int
98+
rust_valgrind_stack_register(void *start, void *end) {
99+
return VALGRIND_STACK_REGISTER(start, end);
100+
}
101+
102+
extern "C" CDECL void
103+
rust_valgrind_stack_deregister(unsigned int id) {
104+
VALGRIND_STACK_DEREGISTER(id);
105+
}

src/rt/rustrt.def.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,3 +234,5 @@ rust_try
234234
rust_begin_unwind
235235
rust_take_task_borrow_list
236236
rust_set_task_borrow_list
237+
rust_valgrind_stack_register
238+
rust_valgrind_stack_deregister

0 commit comments

Comments
 (0)