Skip to content

zend call stack adjust case for freebsd to calculate the guard size. #13586

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion Zend/zend_call_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ static bool zend_call_stack_get_freebsd_sysctl(zend_call_stack *stack)
int mib[2] = {CTL_KERN, KERN_USRSTACK};
size_t len = sizeof(stack_base);
struct rlimit rlim;
size_t numguards = 0;

/* This method is relevant only for the main thread */
ZEND_ASSERT(zend_call_stack_is_main_thread());
Expand All @@ -329,7 +330,13 @@ static bool zend_call_stack_get_freebsd_sysctl(zend_call_stack *stack)
return false;
}

size_t guard_size = getpagesize();
len = sizeof(numguards);
/* For most of the cases, we do not necessarily need to do so as, by default, it is `1` page, but is user writable */
if (sysctlbyname("security.bsd.stack_guard_page", &numguards, &len, NULL, 0) != 0) {
return false;
}

size_t guard_size = numguards * getpagesize();

stack->base = stack_base;
stack->max_size = rlim.rlim_cur - guard_size;
Expand Down