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

it was not wrong but there is a sysctl oid storing the number of guard
pages, which is 1 by default but is modifiable at runtime.
This commit is contained in:
David CARLIER 2024-03-04 19:06:37 +00:00 committed by GitHub
parent 3d4cb1da3e
commit e3b6872b51
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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());
@ -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;