Skip to content

Commit 3a7fbb7

Browse files
committed
zend call stack support for haiku w/o using posix pthread api but the
underlying native BeOs one.
1 parent dda6b8f commit 3a7fbb7

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

Zend/zend_call_stack.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ typedef int boolean_t;
5151
# include <sys/sysctl.h>
5252
# include <sys/user.h>
5353
#endif
54+
#ifdef __HAIKU__
55+
# include <kernel/OS.h>
56+
#endif
5457
#ifdef __linux__
5558
#include <sys/syscall.h>
5659
#endif
@@ -503,6 +506,32 @@ static bool zend_call_stack_get_openbsd(zend_call_stack *stack)
503506
return false;
504507
}
505508
#endif /* defined(__OpenBSD__) */
509+
#if defined(__HAIKU__)
510+
static bool zend_call_stack_get_haiku(zend_call_stack *stack)
511+
{
512+
thread_id id;
513+
thread_info ti;
514+
size_t guard_size;
515+
516+
// unlikely, main thread ought to be always available but we never know
517+
if ((id = find_thread(NULL)) == B_NAME_NOT_FOUND || get_thread_info(id, &ti) != B_OK) {
518+
return false;
519+
}
520+
521+
// USER_STACK_GUARD_SIZE
522+
guard_size = sysconf(_SC_PAGESIZE) * 4;
523+
524+
stack->base = ti.stack_base;
525+
stack->max_size = ((size_t)ti.stack_end - (size_t)ti.stack_base) - guard_size;
526+
527+
return true;
528+
}
529+
#else
530+
static bool zend_call_stack_get_haiku(zend_call_stack *stack)
531+
{
532+
return false;
533+
}
534+
#endif /* defined(__HAIKU__) */
506535

507536
/** Get the stack information for the calling thread */
508537
ZEND_API bool zend_call_stack_get(zend_call_stack *stack)
@@ -527,6 +556,10 @@ ZEND_API bool zend_call_stack_get(zend_call_stack *stack)
527556
return true;
528557
}
529558

559+
if (zend_call_stack_get_haiku(stack)) {
560+
return true;
561+
}
562+
530563
return false;
531564
}
532565

Zend/zend_call_stack.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ static inline size_t zend_call_stack_default_size(void)
8686
}
8787
return 512 * 1024;
8888
#endif
89+
#ifdef __HAIKU__
90+
return 64 * 4096;
91+
#endif
8992

9093
return 2 * 1024 * 1024;
9194
}

0 commit comments

Comments
 (0)