@@ -170,9 +170,9 @@ ZEND_API const zend_internal_function zend_pass_function = {
170170
171171#define ZEND_VM_STACK_PAGE_SIZE (ZEND_VM_STACK_PAGE_SLOTS * sizeof(zval))
172172
173- #define ZEND_VM_STACK_PAGE_ALIGNED_SIZE (size ) \
173+ #define ZEND_VM_STACK_PAGE_ALIGNED_SIZE (size , page_size ) \
174174 (((size) + ZEND_VM_STACK_HEADER_SLOTS * sizeof(zval) \
175- + (ZEND_VM_STACK_PAGE_SIZE - 1)) & ~(ZEND_VM_STACK_PAGE_SIZE - 1))
175+ + ((page_size) - 1)) & ~((page_size) - 1))
176176
177177static zend_always_inline zend_vm_stack zend_vm_stack_new_page (size_t size , zend_vm_stack prev ) {
178178 zend_vm_stack page = (zend_vm_stack )emalloc (size );
@@ -192,6 +192,16 @@ ZEND_API void zend_vm_stack_init(void)
192192 EG (vm_stack_end ) = EG (vm_stack )-> end ;
193193}
194194
195+ ZEND_API void zend_vm_stack_init_ex (size_t page_size )
196+ {
197+ /* page_size must be a power of 2 */
198+ ZEND_ASSERT (page_size > 0 && (page_size & (page_size - 1 )) == 0 );
199+ EG (vm_stack_page_size ) = page_size ;
200+ EG (vm_stack ) = zend_vm_stack_new_page (page_size , NULL );
201+ EG (vm_stack_top ) = EG (vm_stack )-> top ;
202+ EG (vm_stack_end ) = EG (vm_stack )-> end ;
203+ }
204+
195205ZEND_API void zend_vm_stack_destroy (void )
196206{
197207 zend_vm_stack stack = EG (vm_stack );
@@ -212,7 +222,7 @@ ZEND_API void* zend_vm_stack_extend(size_t size)
212222 stack -> top = EG (vm_stack_top );
213223 EG (vm_stack ) = stack = zend_vm_stack_new_page (
214224 EXPECTED (size < EG (vm_stack_page_size ) - (ZEND_VM_STACK_HEADER_SLOTS * sizeof (zval ))) ?
215- EG (vm_stack_page_size ) : ZEND_VM_STACK_PAGE_ALIGNED_SIZE (size ),
225+ EG (vm_stack_page_size ) : ZEND_VM_STACK_PAGE_ALIGNED_SIZE (size , EG ( vm_stack_page_size ) ),
216226 stack );
217227 ptr = stack -> top ;
218228 EG (vm_stack_top ) = (void * )(((char * )ptr ) + size );
0 commit comments