Skip to content

Commit 2269c06

Browse files
authored
Fix stack limit under valgrind (php#14818)
Valgrind creates a stack mapping that can grow up to RLIMIT_STACK, but the last page is never useable
1 parent 83cd1c2 commit 2269c06

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Zend/zend_call_stack.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,10 @@ typedef int boolean_t;
7171
#include <thread.h>
7272
#endif
7373

74+
#ifdef HAVE_VALGRIND
75+
# include <valgrind/valgrind.h>
76+
#endif
77+
7478
#ifdef ZEND_CHECK_STACK_LIMIT
7579

7680
/* Called once per process or thread */
@@ -238,6 +242,13 @@ static bool zend_call_stack_get_linux_proc_maps(zend_call_stack *stack)
238242

239243
max_size = rlim.rlim_cur;
240244

245+
#ifdef HAVE_VALGRIND
246+
/* Under Valgrind, the last page is not useable */
247+
if (RUNNING_ON_VALGRIND) {
248+
max_size -= zend_get_page_size();
249+
}
250+
#endif
251+
241252
/* Previous mapping may prevent the stack from growing */
242253
if (end - max_size < prev_end) {
243254
max_size = prev_end - end;

0 commit comments

Comments
 (0)