add valgrind support to coroutine code

master
Daniel Kolesa 2017-03-08 00:52:31 +01:00
parent 4987fd568d
commit 1d5c98f830
1 changed files with 18 additions and 1 deletions

View File

@ -23,12 +23,19 @@
# include <signal.h>
#endif
#ifdef OSTD_USE_VALGRIND
# include <valgrind/valgrind.h>
#endif
namespace ostd {
namespace detail {
struct context_stack_t {
void *ptr;
size_t size;
#ifdef OSTD_USE_VALGRIND
int valgrind_id;
#endif
};
/* from boost.fcontext */
@ -233,7 +240,13 @@ inline context_stack_t context_stack_alloc(size_t ss) {
mprotect(p, pgs, PROT_NONE);
#endif
return { static_cast<byte *>(p) + ss, ss };
context_stack_t ret{static_cast<byte *>(p) + ss, ss};
#ifdef OSTD_USE_VALGRIND
ret.valgrind_id = VALGRIND_STACK_REGISTER(ret.ptr, p);
#endif
return ret;
}
inline void context_stack_free(context_stack_t &st) {
@ -241,6 +254,10 @@ inline void context_stack_free(context_stack_t &st) {
return;
}
#ifdef OSTD_USE_VALGRIND
VALGRIND_STACK_DEREGISTER(st.valgrind_id);
#endif
auto p = static_cast<byte *>(st.ptr) - st.size;
#if defined(OSTD_PLATFORM_WIN32)
VirtualFree(p, 0, MEM_RELEASE);