HAL_SITL: pre-fill stack on each loop with NaN

this allows us to catch use of uninitialised stack variables in SITL
without having valgrind running
This commit is contained in:
Andrew Tridgell 2019-09-28 17:39:30 +10:00
parent 66b4e92444
commit b9291d95f0
1 changed files with 13 additions and 0 deletions

View File

@ -136,6 +136,16 @@ void HAL_SITL::setup_signal_handlers() const
sigaction(SIGTERM, &sa, NULL);
}
/*
fill 8k of stack with NaN. This allows us to find uses of
uninitialised memory without valgrind
*/
static void fill_stack_nan(void)
{
float stk[2048];
fill_nanf(stk, ARRAY_SIZE(stk));
}
void HAL_SITL::run(int argc, char * const argv[], Callbacks* callbacks) const
{
assert(callbacks);
@ -168,6 +178,8 @@ void HAL_SITL::run(int argc, char * const argv[], Callbacks* callbacks) const
new_argv[new_argv_offset++] = argv[i];
}
fill_stack_nan();
callbacks->setup();
scheduler->system_initialized();
@ -197,6 +209,7 @@ void HAL_SITL::run(int argc, char * const argv[], Callbacks* callbacks) const
::fprintf(stderr, "Exitting\n");
exit(0);
}
fill_stack_nan();
callbacks->loop();
HALSITL::Scheduler::_run_io_procs();