From a01a43ff7f9fd8d49ddbe6fcdb2e391a9cba5496 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 22 Jul 2023 22:01:57 +0100 Subject: [PATCH 1/2] The typo in HAVE_PTHREAD_ATTR_GET_STACK (might be due to pthread_attr_get_np being different from Linux's pthread_getattr_np) led to this code path never get called on FreeBSD. --- Zend/zend_call_stack.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/Zend/zend_call_stack.c b/Zend/zend_call_stack.c index 8c2b43ccdf921..61206680d4c85 100644 --- a/Zend/zend_call_stack.c +++ b/Zend/zend_call_stack.c @@ -104,7 +104,7 @@ static bool zend_call_stack_is_main_thread(void) { # endif } -# ifdef HAVE_PTHREAD_GETATTR_NP +# if defined(HAVE_PTHREAD_GETATTR_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK) static bool zend_call_stack_get_linux_pthread(zend_call_stack *stack) { pthread_attr_t attr; @@ -145,12 +145,12 @@ static bool zend_call_stack_get_linux_pthread(zend_call_stack *stack) return true; } -# else /* HAVE_PTHREAD_GETATTR_NP */ +# else /* defined(HAVE_PTHREAD_GETATTR_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK) */ static bool zend_call_stack_get_linux_pthread(zend_call_stack *stack) { return false; } -# endif /* HAVE_PTHREAD_GETATTR_NP */ +# endif /* defined(HAVE_PTHREAD_GETATTR_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK) */ static bool zend_call_stack_get_linux_proc_maps(zend_call_stack *stack) { @@ -251,7 +251,7 @@ static bool zend_call_stack_is_main_thread(void) return is_main == -1 || is_main == 1; } -# if defined(HAVE_PTHREAD_ATTR_GET_NP) && defined(HAVE_PTHREAD_ATTR_GET_STACK) +# if defined(HAVE_PTHREAD_ATTR_GET_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK) static bool zend_call_stack_get_freebsd_pthread(zend_call_stack *stack) { pthread_attr_t attr; @@ -275,6 +275,14 @@ static bool zend_call_stack_get_freebsd_pthread(zend_call_stack *stack) goto fail; } + error = pthread_attr_getguardsize(&attr, &guard_size); + if (error) { + return false; + } + + addr = (char *)addr + guard_size; + max_size -= guard_size; + stack->base = (int8_t*)addr + max_size; stack->max_size = max_size; @@ -285,12 +293,12 @@ static bool zend_call_stack_get_freebsd_pthread(zend_call_stack *stack) pthread_attr_destroy(&attr); return false; } -# else /* defined(HAVE_PTHREAD_ATTR_GET_NP) && defined(HAVE_PTHREAD_ATTR_GET_STACK) */ +# else /* defined(HAVE_PTHREAD_ATTR_GET_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK) */ static bool zend_call_stack_get_freebsd_pthread(zend_call_stack *stack) { return false; } -# endif /* defined(HAVE_PTHREAD_ATTR_GET_NP) && defined(HAVE_PTHREAD_ATTR_GET_STACK) */ +# endif /* defined(HAVE_PTHREAD_ATTR_GET_NP) && defined(HAVE_PTHREAD_ATTR_GETSTACK) */ static bool zend_call_stack_get_freebsd_sysctl(zend_call_stack *stack) { From 827fb3f7b463b55f6a89eeb7432ce49ee9a6f59c Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 23 Jul 2023 16:05:35 +0100 Subject: [PATCH 2/2] remove not needed stack size adjustment on freebsd --- Zend/zend_call_stack.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/Zend/zend_call_stack.c b/Zend/zend_call_stack.c index 61206680d4c85..06ee521911160 100644 --- a/Zend/zend_call_stack.c +++ b/Zend/zend_call_stack.c @@ -258,7 +258,6 @@ static bool zend_call_stack_get_freebsd_pthread(zend_call_stack *stack) int error; void *addr; size_t max_size; - size_t guard_size; /* pthread will return bogus values for the main thread */ ZEND_ASSERT(!zend_call_stack_is_main_thread()); @@ -275,14 +274,6 @@ static bool zend_call_stack_get_freebsd_pthread(zend_call_stack *stack) goto fail; } - error = pthread_attr_getguardsize(&attr, &guard_size); - if (error) { - return false; - } - - addr = (char *)addr + guard_size; - max_size -= guard_size; - stack->base = (int8_t*)addr + max_size; stack->max_size = max_size;