Compute the size of pages before allocating memory (#14650)

`start_memory_manager()` calls `zend_mm_init()` via `alloc_globals_ctor()`
before setting `REAL_PAGE_SIZE` to the right value. Moving the `REAL_PAGE_SIZE`
setting block before the call to `alloc_globals_ctor()` makes the allocator
behave properly on systems with a page size different than 4k.

Suggested-by: arnaud-lb
This commit is contained in:
Julien Voisin 2024-06-24 14:51:18 +00:00 committed by GitHub
parent 3da6377806
commit e3c9f5a585
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3109,11 +3109,6 @@ static void alloc_globals_dtor(zend_alloc_globals *alloc_globals)
ZEND_API void start_memory_manager(void) ZEND_API void start_memory_manager(void)
{ {
#ifdef ZTS
ts_allocate_fast_id(&alloc_globals_id, &alloc_globals_offset, sizeof(zend_alloc_globals), (ts_allocate_ctor) alloc_globals_ctor, (ts_allocate_dtor) alloc_globals_dtor);
#else
alloc_globals_ctor(&alloc_globals);
#endif
#ifndef _WIN32 #ifndef _WIN32
# if defined(_SC_PAGESIZE) # if defined(_SC_PAGESIZE)
REAL_PAGE_SIZE = sysconf(_SC_PAGESIZE); REAL_PAGE_SIZE = sysconf(_SC_PAGESIZE);
@ -3121,6 +3116,11 @@ ZEND_API void start_memory_manager(void)
REAL_PAGE_SIZE = sysconf(_SC_PAGE_SIZE); REAL_PAGE_SIZE = sysconf(_SC_PAGE_SIZE);
# endif # endif
#endif #endif
#ifdef ZTS
ts_allocate_fast_id(&alloc_globals_id, &alloc_globals_offset, sizeof(zend_alloc_globals), (ts_allocate_ctor) alloc_globals_ctor, (ts_allocate_dtor) alloc_globals_dtor);
#else
alloc_globals_ctor(&alloc_globals);
#endif
} }
ZEND_API zend_mm_heap *zend_mm_set_heap(zend_mm_heap *new_heap) ZEND_API zend_mm_heap *zend_mm_set_heap(zend_mm_heap *new_heap)