Skip to content

zend stack: prepare zend_call_stack_get implementation for OpenBSD. #11578

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Zend/Zend.m4
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 29 additions & 1 deletion Zend/zend_call_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand All @@ -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
Expand Down Expand Up @@ -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)
{
Expand All @@ -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;
}

Expand Down