forked from OctaForge/libostd
add valgrind support to coroutine code
This commit is contained in:
parent
4987fd568d
commit
1d5c98f830
|
@ -23,12 +23,19 @@
|
||||||
# include <signal.h>
|
# include <signal.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef OSTD_USE_VALGRIND
|
||||||
|
# include <valgrind/valgrind.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace ostd {
|
namespace ostd {
|
||||||
namespace detail {
|
namespace detail {
|
||||||
|
|
||||||
struct context_stack_t {
|
struct context_stack_t {
|
||||||
void *ptr;
|
void *ptr;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
#ifdef OSTD_USE_VALGRIND
|
||||||
|
int valgrind_id;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
/* from boost.fcontext */
|
/* from boost.fcontext */
|
||||||
|
@ -233,7 +240,13 @@ inline context_stack_t context_stack_alloc(size_t ss) {
|
||||||
mprotect(p, pgs, PROT_NONE);
|
mprotect(p, pgs, PROT_NONE);
|
||||||
#endif
|
#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) {
|
inline void context_stack_free(context_stack_t &st) {
|
||||||
|
@ -241,6 +254,10 @@ inline void context_stack_free(context_stack_t &st) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef OSTD_USE_VALGRIND
|
||||||
|
VALGRIND_STACK_DEREGISTER(st.valgrind_id);
|
||||||
|
#endif
|
||||||
|
|
||||||
auto p = static_cast<byte *>(st.ptr) - st.size;
|
auto p = static_cast<byte *>(st.ptr) - st.size;
|
||||||
#if defined(OSTD_PLATFORM_WIN32)
|
#if defined(OSTD_PLATFORM_WIN32)
|
||||||
VirtualFree(p, 0, MEM_RELEASE);
|
VirtualFree(p, 0, MEM_RELEASE);
|
||||||
|
|
Loading…
Reference in a new issue