Skip to content

Commit a368570

Browse files
committed
changes from review
1 parent 09f1756 commit a368570

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

Zend/zend_call_stack.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,11 @@
4545
# include <sys/user.h>
4646
#endif
4747
#ifdef __OpenBSD__
48+
typedef int boolean_t;
49+
# include <tib.h>
4850
# include <pthread_np.h>
49-
# include <machine/vmparam.h>
51+
# include <sys/sysctl.h>
52+
# include <sys/user.h>
5053
#endif
5154
#ifdef __linux__
5255
#include <sys/syscall.h>
@@ -460,9 +463,14 @@ static bool zend_call_stack_get_openbsd_pthread(zend_call_stack *stack)
460463

461464
static bool zend_call_stack_get_openbsd_vm(zend_call_stack *stack)
462465
{
463-
void *stack_base;
466+
struct _ps_strings ps;
464467
struct rlimit rlim;
468+
int mib[2] = {CTL_VM, VM_PSSTRINGS };
469+
size_t len = sizeof(ps), pagesize;
465470

471+
if (sysctl(mib, 2, &ps, &len, NULL, 0) != 0) {
472+
return false;
473+
}
466474

467475
if (getrlimit(RLIMIT_STACK, &rlim) != 0) {
468476
return false;
@@ -472,16 +480,18 @@ static bool zend_call_stack_get_openbsd_vm(zend_call_stack *stack)
472480
return false;
473481
}
474482

475-
// arch dependent top user's stack
476-
stack->base = USRSTACK - rlim.rlim_cur;
477-
stack->max_size = rlim.rlim_cur - sysconf(_SC_PAGE_SIZE);
483+
pagesize = sysconf(_SC_PAGE_SIZE);
484+
485+
stack->base = (void *)((uintptr_t)ps.val + (pagesize - 1) & ~(pagesize - 1));
486+
stack->max_size = rlim.rlim_cur - pagesize;
478487

479488
return true;
480489
}
481490

482491
static bool zend_call_stack_get_openbsd(zend_call_stack *stack)
483492
{
484-
if (getthrid() == getpid()) {
493+
// TIB_THREAD_INITIAL_STACK is private and here we avoid using pthread's api (ie pthread_main_np)
494+
if (!TIB_GET()->tib_thread || (TIB_GET()->tib_thread_flags & 0x002) != 0) {
485495
return zend_call_stack_get_openbsd_vm(stack);
486496
}
487497

0 commit comments

Comments
 (0)