use Rust types for Valgrind, and use u32 for stack IDs
This commit is contained in:
parent
c19fc4625a
commit
904da1a1c8
11
src/os.rs
11
src/os.rs
|
@ -7,11 +7,13 @@ use self::libc::{c_void, size_t};
|
||||||
use core::ptr;
|
use core::ptr;
|
||||||
use stack;
|
use stack;
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
type stack_id_t = u32;
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#[link_name = "lwt_stack_register"]
|
#[link_name = "lwt_stack_register"]
|
||||||
fn stack_register(start: *const c_void, end: *const c_void) -> libc::c_uint;
|
fn stack_register(start: *const u8, end: *const u8) -> stack_id_t;
|
||||||
#[link_name = "lwt_stack_deregister"]
|
#[link_name = "lwt_stack_deregister"]
|
||||||
fn stack_deregister(id: libc::c_uint);
|
fn stack_deregister(id: stack_id_t);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(raw_pointer_derive)]
|
#[allow(raw_pointer_derive)]
|
||||||
|
@ -19,7 +21,7 @@ extern "C" {
|
||||||
pub struct Stack {
|
pub struct Stack {
|
||||||
ptr: *mut u8,
|
ptr: *mut u8,
|
||||||
len: usize,
|
len: usize,
|
||||||
valgrind_id: libc::c_uint
|
valgrind_id: stack_id_t
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct StackSource;
|
pub struct StackSource;
|
||||||
|
@ -67,7 +69,8 @@ impl Stack {
|
||||||
len, IoError::last_os_error())
|
len, IoError::last_os_error())
|
||||||
}
|
}
|
||||||
|
|
||||||
let valgrind_id = stack_register(ptr.offset(len as isize), ptr);
|
let valgrind_id = stack_register(ptr.offset(len as isize) as *const _,
|
||||||
|
ptr as *const _);
|
||||||
|
|
||||||
Stack { ptr: ptr as *mut u8, len: len, valgrind_id: valgrind_id }
|
Stack { ptr: ptr as *mut u8, len: len, valgrind_id: valgrind_id }
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <stdint.h>
|
||||||
#include "valgrind/valgrind.h"
|
#include "valgrind/valgrind.h"
|
||||||
|
|
||||||
// In order for Valgrind to keep track of stack overflows and such, it needs
|
// In order for Valgrind to keep track of stack overflows and such, it needs
|
||||||
|
@ -5,14 +6,16 @@
|
||||||
// macros. Calling out to un-inlineable C code for this is pointlessly slow,
|
// macros. Calling out to un-inlineable C code for this is pointlessly slow,
|
||||||
// but that's the way it is for now.
|
// but that's the way it is for now.
|
||||||
|
|
||||||
|
typedef uint32_t valgrind_stack_id_t;
|
||||||
|
|
||||||
// Register a stack with Valgrind. start < end. Returns an integer ID that can
|
// Register a stack with Valgrind. start < end. Returns an integer ID that can
|
||||||
// be used to deregister the stack when it's deallocated.
|
// be used to deregister the stack when it's deallocated.
|
||||||
unsigned int lwt_stack_register(const void *start, const void *end) {
|
valgrind_stack_id_t lwt_stack_register(const void *start, const void *end) {
|
||||||
return VALGRIND_STACK_REGISTER(start, end);
|
return VALGRIND_STACK_REGISTER(start, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deregister a stack from Valgrind. Takes the integer ID that was returned
|
// Deregister a stack from Valgrind. Takes the integer ID that was returned
|
||||||
// on registration.
|
// on registration.
|
||||||
void lwt_stack_deregister(unsigned int id) {
|
void lwt_stack_deregister(valgrind_stack_id_t id) {
|
||||||
VALGRIND_STACK_DEREGISTER(id);
|
VALGRIND_STACK_DEREGISTER(id);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue