From 2269c060420791ab4fea2899fb73975597391ee2 Mon Sep 17 00:00:00 2001 From: Arnaud Le Blanc Date: Fri, 5 Jul 2024 17:09:45 +0200 Subject: [PATCH] Fix stack limit under valgrind (#14818) Valgrind creates a stack mapping that can grow up to RLIMIT_STACK, but the last page is never useable --- Zend/zend_call_stack.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Zend/zend_call_stack.c b/Zend/zend_call_stack.c index 9edb4f29589..f12323d0d9c 100644 --- a/Zend/zend_call_stack.c +++ b/Zend/zend_call_stack.c @@ -71,6 +71,10 @@ typedef int boolean_t; #include #endif +#ifdef HAVE_VALGRIND +# include +#endif + #ifdef ZEND_CHECK_STACK_LIMIT /* Called once per process or thread */ @@ -238,6 +242,13 @@ static bool zend_call_stack_get_linux_proc_maps(zend_call_stack *stack) max_size = rlim.rlim_cur; +#ifdef HAVE_VALGRIND + /* Under Valgrind, the last page is not useable */ + if (RUNNING_ON_VALGRIND) { + max_size -= zend_get_page_size(); + } +#endif + /* Previous mapping may prevent the stack from growing */ if (end - max_size < prev_end) { max_size = prev_end - end;