simplify Valgrind wrapper
This commit is contained in:
parent
5411f10460
commit
878a6fefc3
|
@ -1,27 +1,21 @@
|
||||||
// This file is part of libfringe, a low-level green threading library.
|
// This file is part of libfringe, a low-level green threading library.
|
||||||
// Copyright (c) 2015, edef <edef@edef.eu>
|
// Copyright (c) 2015, edef <edef@edef.eu>
|
||||||
// See the LICENSE file included in this distribution.
|
// See the LICENSE file included in this distribution.
|
||||||
use stack;
|
pub use self::imp::*;
|
||||||
|
|
||||||
mod valgrind;
|
#[cfg(feature = "valgrind")]
|
||||||
|
#[path = "valgrind/mod.rs"]
|
||||||
|
mod imp;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[cfg(not(feature = "valgrind"))]
|
||||||
pub struct StackId(valgrind::stack_id_t);
|
mod imp {
|
||||||
|
use stack;
|
||||||
impl StackId {
|
#[derive(Debug)]
|
||||||
#[inline(always)]
|
pub struct StackId;
|
||||||
pub fn register<Stack: stack::Stack>(stack: &mut Stack) -> StackId {
|
/// No-op since no valgrind
|
||||||
StackId(unsafe {
|
impl StackId {
|
||||||
valgrind::stack_register(stack.limit(), stack.top())
|
pub unsafe fn register<Stack: stack::Stack>(_stack: &mut Stack) -> StackId {
|
||||||
})
|
StackId
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Drop for StackId {
|
|
||||||
#[inline(always)]
|
|
||||||
fn drop(&mut self) {
|
|
||||||
unsafe {
|
|
||||||
valgrind::stack_deregister(self.0)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,44 @@
|
||||||
// This file is part of libfringe, a low-level green threading library.
|
// This file is part of libfringe, a low-level green threading library.
|
||||||
// Copyright (c) 2015, edef <edef@edef.eu>
|
// Copyright (c) 2015, edef <edef@edef.eu>
|
||||||
// See the LICENSE file included in this distribution.
|
// See the LICENSE file included in this distribution.
|
||||||
pub use self::imp::*;
|
#![allow(non_camel_case_types)]
|
||||||
|
//! In order for Valgrind to keep track of stack overflows and such, it needs
|
||||||
|
//! a little help. That help unfortunately comes in the form of a set of C
|
||||||
|
//! macros. Calling out to un-inlineable C code for this is pointlessly slow,
|
||||||
|
//! but that's the way it is for now.
|
||||||
|
use stack;
|
||||||
|
|
||||||
#[cfg(feature = "valgrind")]
|
pub type stack_id_t = u32;
|
||||||
#[path = "native.rs"]
|
extern "C" {
|
||||||
mod imp;
|
#[link_name = "valgrind_stack_register"]
|
||||||
|
/// Register a stack with Valgrind. Returns an integer ID that can
|
||||||
|
/// be used to deregister the stack when it's deallocated.
|
||||||
|
/// `start < end`.
|
||||||
|
pub fn stack_register(start: *const u8, end: *const u8) -> stack_id_t;
|
||||||
|
|
||||||
#[cfg(not(feature = "valgrind"))]
|
#[link_name = "valgrind_stack_deregister"]
|
||||||
mod imp {
|
/// Deregister a stack from Valgrind. Takes the integer ID that was returned
|
||||||
//! Stub for the Valgrind functions
|
/// on registration.
|
||||||
#![allow(non_camel_case_types)]
|
pub fn stack_deregister(id: stack_id_t);
|
||||||
pub type stack_id_t = ();
|
}
|
||||||
pub unsafe fn stack_register(_start: *const u8, _end: *const u8) -> stack_id_t {}
|
|
||||||
pub unsafe fn stack_deregister(_id: stack_id_t) {}
|
#[derive(Debug)]
|
||||||
|
pub struct StackId(stack_id_t);
|
||||||
|
|
||||||
|
impl StackId {
|
||||||
|
#[inline(always)]
|
||||||
|
pub fn register<Stack: stack::Stack>(stack: &mut Stack) -> StackId {
|
||||||
|
StackId(unsafe {
|
||||||
|
stack_register(stack.limit(), stack.top())
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Drop for StackId {
|
||||||
|
#[inline(always)]
|
||||||
|
fn drop(&mut self) {
|
||||||
|
unsafe {
|
||||||
|
stack_deregister(self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
// This file is part of libfringe, a low-level green threading library.
|
|
||||||
// Copyright (c) 2015, edef <edef@edef.eu>
|
|
||||||
// See the LICENSE file included in this distribution.
|
|
||||||
#![allow(non_camel_case_types)]
|
|
||||||
//! In order for Valgrind to keep track of stack overflows and such, it needs
|
|
||||||
//! a little help. That help unfortunately comes in the form of a set of C
|
|
||||||
//! macros. Calling out to un-inlineable C code for this is pointlessly slow,
|
|
||||||
//! but that's the way it is for now.
|
|
||||||
|
|
||||||
pub type stack_id_t = u32;
|
|
||||||
extern "C" {
|
|
||||||
#[link_name = "valgrind_stack_register"]
|
|
||||||
/// Register a stack with Valgrind. Returns an integer ID that can
|
|
||||||
/// be used to deregister the stack when it's deallocated.
|
|
||||||
/// `start < end`.
|
|
||||||
pub fn stack_register(start: *const u8, end: *const u8) -> stack_id_t;
|
|
||||||
|
|
||||||
#[link_name = "valgrind_stack_deregister"]
|
|
||||||
/// Deregister a stack from Valgrind. Takes the integer ID that was returned
|
|
||||||
/// on registration.
|
|
||||||
pub fn stack_deregister(id: stack_id_t);
|
|
||||||
}
|
|
Loading…
Reference in New Issue