diff --git a/Zend/Zend.m4 b/Zend/Zend.m4 index 951f593973575..2f56cb266cc4e 100644 --- a/Zend/Zend.m4 +++ b/Zend/Zend.m4 @@ -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 diff --git a/Zend/zend_call_stack.c b/Zend/zend_call_stack.c index dadaa60dcb208..4b8f4106a1a6c 100644 --- a/Zend/zend_call_stack.c +++ b/Zend/zend_call_stack.c @@ -35,7 +35,7 @@ # include # endif #endif /* ZEND_WIN32 */ -#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) +#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__) # include #endif #ifdef __FreeBSD__ @@ -44,6 +44,9 @@ # include # include #endif +#ifdef __OpenBSD__ +# include +#endif #ifdef __linux__ #include #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; }