46
46
#endif
47
47
#ifdef __OpenBSD__
48
48
# include <pthread_np.h>
49
+ # include <machine/vmparam.h>
49
50
#endif
50
51
#ifdef __linux__
51
52
#include <sys/syscall.h>
@@ -435,8 +436,9 @@ static bool zend_call_stack_get_macos(zend_call_stack *stack)
435
436
}
436
437
#endif /* defined(__APPLE__) && defined(HAVE_PTHREAD_GET_STACKADDR_NP) */
437
438
439
+ #if defined(__OpenBSD__ )
438
440
#if defined(HAVE_PTHREAD_STACKSEG_NP )
439
- static bool zend_call_stack_get_openbsd (zend_call_stack * stack )
441
+ static bool zend_call_stack_get_openbsd_pthread (zend_call_stack * stack )
440
442
{
441
443
stack_t ss ;
442
444
@@ -450,12 +452,49 @@ static bool zend_call_stack_get_openbsd(zend_call_stack *stack)
450
452
return true;
451
453
}
452
454
#else
453
- static bool zend_call_stack_get_openbsd (zend_call_stack * stack )
455
+ static bool zend_call_stack_get_openbsd_pthread (zend_call_stack * stack )
454
456
{
455
457
return false;
456
458
}
457
459
#endif /* defined(HAVE_PTHREAD_STACKSEG_NP) */
458
460
461
+ static bool zend_call_stack_get_openbsd_vm (zend_call_stack * stack )
462
+ {
463
+ void * stack_base ;
464
+ struct rlimit rlim ;
465
+
466
+
467
+ if (getrlimit (RLIMIT_STACK , & rlim ) != 0 ) {
468
+ return false;
469
+ }
470
+
471
+ if (rlim .rlim_cur == RLIM_INFINITY ) {
472
+ return false;
473
+ }
474
+
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 );
478
+
479
+ return true;
480
+ }
481
+
482
+ static bool zend_call_stack_get_openbsd (zend_call_stack * stack )
483
+ {
484
+ if (getthrid () == getpid ()) {
485
+ return zend_call_stack_get_openbsd_vm (stack );
486
+ }
487
+
488
+ return zend_call_stack_get_openbsd_pthread (stack );
489
+ }
490
+
491
+ #else
492
+ static bool zend_call_stack_get_openbsd (zend_call_stack * stack )
493
+ {
494
+ return false;
495
+ }
496
+ #endif /* defined(__OpenBSD__) */
497
+
459
498
/** Get the stack information for the calling thread */
460
499
ZEND_API bool zend_call_stack_get (zend_call_stack * stack )
461
500
{
0 commit comments