zend stack: prepare zend_call_stack_get implementation for OpenBSD. (#11578)

This commit is contained in:
David CARLIER 2023-07-07 18:03:07 +01:00 committed by GitHub
parent 49864198cc
commit 75e9980054
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 2 deletions

View file

@ -146,7 +146,7 @@ _LT_AC_TRY_DLOPEN_SELF([
])
dnl Checks for library functions.
AC_CHECK_FUNCS(getpid kill sigsetjmp pthread_getattr_np pthread_attr_get_np pthread_get_stackaddr_np pthread_attr_getstack gettid)
AC_CHECK_FUNCS(getpid kill sigsetjmp pthread_getattr_np pthread_attr_get_np pthread_get_stackaddr_np pthread_attr_getstack pthread_stackseg_np gettid)
dnl Test whether the stack grows downwards
dnl Assumes contiguous stack

View file

@ -35,7 +35,7 @@
# include <sys/types.h>
# endif
#endif /* ZEND_WIN32 */
#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
# include <pthread.h>
#endif
#ifdef __FreeBSD__
@ -44,6 +44,9 @@
# include <sys/sysctl.h>
# include <sys/user.h>
#endif
#ifdef __OpenBSD__
# include <pthread_np.h>
#endif
#ifdef __linux__
#include <sys/syscall.h>
#endif
@ -432,6 +435,27 @@ static bool zend_call_stack_get_macos(zend_call_stack *stack)
}
#endif /* defined(__APPLE__) && defined(HAVE_PTHREAD_GET_STACKADDR_NP) */
#if defined(HAVE_PTHREAD_STACKSEG_NP)
static bool zend_call_stack_get_openbsd(zend_call_stack *stack)
{
stack_t ss;
if (pthread_stackseg_np(pthread_self(), &ss) != 0) {
return false;
}
stack->base = (char *)ss.ss_sp - ss.ss_size;
stack->max_size = ss.ss_size - sysconf(_SC_PAGE_SIZE);
return true;
}
#else
static bool zend_call_stack_get_openbsd(zend_call_stack *stack)
{
return false;
}
#endif /* defined(HAVE_PTHREAD_STACKSEG_NP) */
/** Get the stack information for the calling thread */
ZEND_API bool zend_call_stack_get(zend_call_stack *stack)
{
@ -451,6 +475,10 @@ ZEND_API bool zend_call_stack_get(zend_call_stack *stack)
return true;
}
if (zend_call_stack_get_openbsd(stack)) {
return true;
}
return false;
}