1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-17 05:12:57 +01:00

Merge pull request #20726 from maribu/core/thread/valgrind-disable

core/thread: "fix" valgrind erros in thread_measure_stack_free()
This commit is contained in:
benpicco 2024-06-05 13:08:02 +00:00 committed by GitHub
commit 54cd5248c9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -35,6 +35,15 @@
#define ENABLE_DEBUG 0
#include "debug.h"
#if defined(HAVE_VALGRIND_H)
# include <valgrind.h>
#elif defined(HAVE_VALGRIND_VALGRIND_H)
# include <valgrind/valgrind.h>
#else
# define VALGRIND_DISABLE_ERROR_REPORTING (void)0
# define VALGRIND_ENABLE_ERROR_REPORTING (void)0
#endif
thread_status_t thread_getstatus(kernel_pid_t pid)
{
thread_t *thread = thread_get(pid);
@ -178,11 +187,23 @@ uintptr_t measure_stack_free_internal(const char *stack, size_t size)
uintptr_t *stackp = (uintptr_t *)(uintptr_t)stack;
uintptr_t end = (uintptr_t)stack + size;
/* HACK: This will affect native/native64 only.
*
* The dark magic used here is frowned upon by valgrind. E.g. valgrind may
* deduce that a specific value was at some point allocated on the stack,
* but has gone out of scope. When that value is now read again to
* estimate stack usage, it does look a lot like someone passed a pointer
* to a stack allocated value, and that pointer is referenced after that
* value has gone out of scope. */
VALGRIND_DISABLE_ERROR_REPORTING;
/* assume that the stack grows "downwards" */
while (((uintptr_t)stackp < end) && (*stackp == (uintptr_t)stackp)) {
stackp++;
}
VALGRIND_ENABLE_ERROR_REPORTING;
uintptr_t space_free = (uintptr_t)stackp - (uintptr_t)stack;
return space_free;