From 449be607d0801e714b5e61863cdaad396b36f3ca Mon Sep 17 00:00:00 2001 From: Thomas Debesse Date: Thu, 15 Oct 2026 08:23:45 +0200 Subject: [PATCH] src/client/linux/minidump_writer: make minidump stack-skipping test more deterministic - Check pthread attribute initialization, configuration, and thread creation errors. - Give the helper thread a dedicated and zero-initialized stack, to make the test less dependent on residual stack contents when checking whether stacks referencing the executable are skipped. The test checks that a helper thread that runs in libc and doesn't reference the main executable is excluded from the minidump. Initializing the dedicated stack should reduce the chance that stale pointers into the executable mapping cause the stack to be included. This changes a bit the original conditions of the test, since residual stack contents that could affect the result are eliminated. But it should make the test more deterministic. This test has been observed to sometimes fail in CI, reporting more threads with dumped stacks than expected. --- .../minidump_writer_unittest.cc | 40 +++++++++++++++++-- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/client/linux/minidump_writer/minidump_writer_unittest.cc b/src/client/linux/minidump_writer/minidump_writer_unittest.cc index 449ac189..5f74dc0a 100644 --- a/src/client/linux/minidump_writer/minidump_writer_unittest.cc +++ b/src/client/linux/minidump_writer/minidump_writer_unittest.cc @@ -270,12 +270,44 @@ TEST(MinidumpWriterTest, MinidumpStacksSkippedIfRequested) { // current executable). This thread should not be captured in the minidump. pthread_t thread; pthread_attr_t thread_attributes; - pthread_attr_init(&thread_attributes); - pthread_attr_setdetachstate(&thread_attributes, PTHREAD_CREATE_DETACHED); + if (pthread_attr_init(&thread_attributes) != 0) { + syscall(__NR_exit_group, 1); + } + if (pthread_attr_setdetachstate( + &thread_attributes, PTHREAD_CREATE_DETACHED) != 0) { + pthread_attr_destroy(&thread_attributes); + syscall(__NR_exit_group, 1); + } + + const size_t stack_size = 1024 * 1024; + void* thread_stack = mmap(nullptr, stack_size, + PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS | MAP_STACK, + -1, 0); + if (thread_stack == MAP_FAILED) { + pthread_attr_destroy(&thread_attributes); + syscall(__NR_exit_group, 1); + } + memset(thread_stack, 0, stack_size); + + if (pthread_attr_setstack( + &thread_attributes, thread_stack, stack_size) != 0) { + munmap(thread_stack, stack_size); + pthread_attr_destroy(&thread_attributes); + syscall(__NR_exit_group, 1); + } + sigset_t sigset; sigemptyset(&sigset); - pthread_create(&thread, &thread_attributes, - reinterpret_cast(&sigsuspend), &sigset); + const int create_result = + pthread_create(&thread, &thread_attributes, + reinterpret_cast(&sigsuspend), + &sigset); + pthread_attr_destroy(&thread_attributes); + if (create_result != 0) { + munmap(thread_stack, stack_size); + syscall(__NR_exit_group, 1); + } char b; IGNORE_RET(HANDLE_EINTR(read(fds[0], &b, sizeof(b))));