Skip to content

Commit 75e9980

Browse files
authored
zend stack: prepare zend_call_stack_get implementation for OpenBSD. (php#11578)
1 parent 4986419 commit 75e9980

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

Zend/Zend.m4

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ _LT_AC_TRY_DLOPEN_SELF([
146146
])
147147
148148
dnl Checks for library functions.
149-
AC_CHECK_FUNCS(getpid kill sigsetjmp pthread_getattr_np pthread_attr_get_np pthread_get_stackaddr_np pthread_attr_getstack gettid)
149+
AC_CHECK_FUNCS(getpid kill sigsetjmp pthread_getattr_np pthread_attr_get_np pthread_get_stackaddr_np pthread_attr_getstack pthread_stackseg_np gettid)
150150
151151
dnl Test whether the stack grows downwards
152152
dnl Assumes contiguous stack

Zend/zend_call_stack.c

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
# include <sys/types.h>
3636
# endif
3737
#endif /* ZEND_WIN32 */
38-
#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__)
38+
#if defined(__linux__) || defined(__FreeBSD__) || defined(__APPLE__) || defined(__OpenBSD__)
3939
# include <pthread.h>
4040
#endif
4141
#ifdef __FreeBSD__
@@ -44,6 +44,9 @@
4444
# include <sys/sysctl.h>
4545
# include <sys/user.h>
4646
#endif
47+
#ifdef __OpenBSD__
48+
# include <pthread_np.h>
49+
#endif
4750
#ifdef __linux__
4851
#include <sys/syscall.h>
4952
#endif
@@ -432,6 +435,27 @@ static bool zend_call_stack_get_macos(zend_call_stack *stack)
432435
}
433436
#endif /* defined(__APPLE__) && defined(HAVE_PTHREAD_GET_STACKADDR_NP) */
434437

438+
#if defined(HAVE_PTHREAD_STACKSEG_NP)
439+
static bool zend_call_stack_get_openbsd(zend_call_stack *stack)
440+
{
441+
stack_t ss;
442+
443+
if (pthread_stackseg_np(pthread_self(), &ss) != 0) {
444+
return false;
445+
}
446+
447+
stack->base = (char *)ss.ss_sp - ss.ss_size;
448+
stack->max_size = ss.ss_size - sysconf(_SC_PAGE_SIZE);
449+
450+
return true;
451+
}
452+
#else
453+
static bool zend_call_stack_get_openbsd(zend_call_stack *stack)
454+
{
455+
return false;
456+
}
457+
#endif /* defined(HAVE_PTHREAD_STACKSEG_NP) */
458+
435459
/** Get the stack information for the calling thread */
436460
ZEND_API bool zend_call_stack_get(zend_call_stack *stack)
437461
{
@@ -451,6 +475,10 @@ ZEND_API bool zend_call_stack_get(zend_call_stack *stack)
451475
return true;
452476
}
453477

478+
if (zend_call_stack_get_openbsd(stack)) {
479+
return true;
480+
}
481+
454482
return false;
455483
}
456484

0 commit comments

Comments
 (0)