From eca993b42c07dc93817c9e743b3bf8c9d155b15a Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Thu, 12 Sep 2024 09:26:13 -0700 Subject: [PATCH] preload: add static assertion with offsetof() check --- src/preload/backtrace-helper.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/preload/backtrace-helper.h b/src/preload/backtrace-helper.h index 43a36175..ac4f8e9a 100644 --- a/src/preload/backtrace-helper.h +++ b/src/preload/backtrace-helper.h @@ -38,12 +38,14 @@ backtrace_func (SysprofCaptureAddress *addrs, G_GNUC_UNUSED gpointer user_data) { #if GLIB_SIZEOF_VOID_P == 8 + SYSPROF_STATIC_ASSERT (offsetof (SysprofCaptureAllocation, addrs) >= GLIB_SIZEOF_VOID_P * 2, + "Require space for 2 discarded instruction pointers"); /* We know that collector will overwrite fields *AFTER* it * has called the backtrace function allowing us to cheat * and subtract an offset from addrs to avoid having to * copy frame pointers around. */ - return unw_backtrace ((void **)addrs - 2, n_addrs) - 2; + return unw_backtrace (((void **)addrs) - 2, n_addrs) - 2; #else static const int skip = 2; void **stack = alloca (n_addrs * sizeof (gpointer));