diff --git a/ostd/internal/context.hh b/ostd/internal/context.hh index ff0da53..dba94dd 100644 --- a/ostd/internal/context.hh +++ b/ostd/internal/context.hh @@ -23,12 +23,19 @@ # include #endif +#ifdef OSTD_USE_VALGRIND +# include +#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(p) + ss, ss }; + context_stack_t ret{static_cast(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(st.ptr) - st.size; #if defined(OSTD_PLATFORM_WIN32) VirtualFree(p, 0, MEM_RELEASE);