rt: Make C stack switching Valgrind-clean by warning Valgrind when we're about to write to the C stack from the Rust stack
This commit is contained in:
parent
cf3e7f2f0b
commit
8d8b48a901
|
@ -7,6 +7,10 @@ CFG_GCCISH_LINK_FLAGS :=
|
|||
# embedded into the executable, so use a no-op command.
|
||||
CFG_DSYMUTIL := true
|
||||
|
||||
ifneq ($(CFG_VALGRIND),)
|
||||
CFG_GCCISH_CFLAGS += -DHAVE_VALGRIND
|
||||
endif
|
||||
|
||||
ifneq ($(findstring freebsd,$(CFG_OSTYPE)),)
|
||||
CFG_LIB_NAME=lib$(1).so
|
||||
CFG_GCCISH_CFLAGS += -fPIC -march=i686 -I/usr/local/include
|
||||
|
|
|
@ -7,6 +7,10 @@
|
|||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef HAVE_VALGRIND
|
||||
#include <valgrind/memcheck.h>
|
||||
#endif
|
||||
|
||||
template<typename T>
|
||||
T align_down(T sp)
|
||||
{
|
||||
|
@ -44,7 +48,14 @@ public:
|
|||
// function being called causes the task to fail, then we have to avoid
|
||||
// leaking space on the C stack.
|
||||
inline void *alloc_stack(size_t nbytes) {
|
||||
return (void *)(align_down(regs.esp - nbytes));
|
||||
uint32_t bot = regs.esp;
|
||||
uint32_t top = align_down(bot - nbytes);
|
||||
|
||||
#ifdef HAVE_VALGRIND
|
||||
(void)VALGRIND_MAKE_MEM_UNDEFINED(top - 4, bot - top + 4);
|
||||
#endif
|
||||
|
||||
return reinterpret_cast<void *>(top);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue