Skip to content

Commit 3ab7aa0

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2: Workaround ZTS persistent resource crashes (PHP 8.3 and lower)
2 parents 56b7db6 + 2f60582 commit 3ab7aa0

File tree

5 files changed

+44
-7
lines changed

5 files changed

+44
-7
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.3.4
44

5+
- Core:
6+
. Fix ZTS persistent resource crashes on shutdown. (nielsdos)
7+
58
- Curl:
69
. Fix failing tests due to string changes in libcurl 8.6.0. (Ayesh)
710

Zend/zend.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,8 @@ void zend_shutdown(void) /* {{{ */
11671167
#endif
11681168
zend_destroy_rsrc_list_dtors();
11691169

1170+
zend_unload_modules();
1171+
11701172
zend_optimizer_shutdown();
11711173
startup_done = false;
11721174
}

Zend/zend.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ void zend_shutdown(void);
279279
void zend_register_standard_ini_entries(void);
280280
zend_result zend_post_startup(void);
281281
void zend_set_utility_values(zend_utility_values *utility_values);
282+
void zend_unload_modules(void);
282283

283284
ZEND_API ZEND_COLD ZEND_NORETURN void _zend_bailout(const char *filename, uint32_t lineno);
284285
ZEND_API size_t zend_get_page_size(void);

Zend/zend_API.c

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ ZEND_API HashTable module_registry;
4141
static zend_module_entry **module_request_startup_handlers;
4242
static zend_module_entry **module_request_shutdown_handlers;
4343
static zend_module_entry **module_post_deactivate_handlers;
44+
static zend_module_entry **modules_dl_loaded;
4445

4546
static zend_class_entry **class_cleanup_handlers;
4647

@@ -2368,6 +2369,7 @@ ZEND_API void zend_collect_module_handlers(void) /* {{{ */
23682369
int startup_count = 0;
23692370
int shutdown_count = 0;
23702371
int post_deactivate_count = 0;
2372+
int dl_loaded_count = 0;
23712373
zend_class_entry *ce;
23722374
int class_count = 0;
23732375

@@ -2382,6 +2384,9 @@ ZEND_API void zend_collect_module_handlers(void) /* {{{ */
23822384
if (module->post_deactivate_func) {
23832385
post_deactivate_count++;
23842386
}
2387+
if (module->handle) {
2388+
dl_loaded_count++;
2389+
}
23852390
} ZEND_HASH_FOREACH_END();
23862391
module_request_startup_handlers = (zend_module_entry**)realloc(
23872392
module_request_startup_handlers,
@@ -2394,6 +2399,9 @@ ZEND_API void zend_collect_module_handlers(void) /* {{{ */
23942399
module_request_shutdown_handlers[shutdown_count] = NULL;
23952400
module_post_deactivate_handlers = module_request_shutdown_handlers + shutdown_count + 1;
23962401
module_post_deactivate_handlers[post_deactivate_count] = NULL;
2402+
/* Cannot reuse module_request_startup_handlers because it is freed in zend_destroy_modules, which happens before zend_unload_modules. */
2403+
modules_dl_loaded = realloc(modules_dl_loaded, sizeof(zend_module_entry*) * (dl_loaded_count + 1));
2404+
modules_dl_loaded[dl_loaded_count] = NULL;
23972405
startup_count = 0;
23982406

23992407
ZEND_HASH_MAP_FOREACH_PTR(&module_registry, module) {
@@ -2406,6 +2414,9 @@ ZEND_API void zend_collect_module_handlers(void) /* {{{ */
24062414
if (module->post_deactivate_func) {
24072415
module_post_deactivate_handlers[--post_deactivate_count] = module;
24082416
}
2417+
if (module->handle) {
2418+
modules_dl_loaded[--dl_loaded_count] = module;
2419+
}
24092420
} ZEND_HASH_FOREACH_END();
24102421

24112422
/* Collect internal classes with static members */
@@ -3180,18 +3191,23 @@ void module_destructor(zend_module_entry *module) /* {{{ */
31803191
clean_module_functions(module);
31813192
}
31823193

3183-
#if HAVE_LIBDL
3184-
if (module->handle && !getenv("ZEND_DONT_UNLOAD_MODULES")) {
3185-
DL_UNLOAD(module->handle);
3186-
}
3187-
#endif
3188-
31893194
#if ZEND_RC_DEBUG
31903195
zend_rc_debug = orig_rc_debug;
31913196
#endif
31923197
}
31933198
/* }}} */
31943199

3200+
void module_registry_unload(const zend_module_entry *module)
3201+
{
3202+
#if HAVE_LIBDL
3203+
if (!getenv("ZEND_DONT_UNLOAD_MODULES")) {
3204+
DL_UNLOAD(module->handle);
3205+
}
3206+
#else
3207+
ZEND_IGNORE_VALUE(module);
3208+
#endif
3209+
}
3210+
31953211
ZEND_API void zend_activate_modules(void) /* {{{ */
31963212
{
31973213
zend_module_entry **p = module_request_startup_handlers;
@@ -3236,6 +3252,18 @@ ZEND_API void zend_deactivate_modules(void) /* {{{ */
32363252
}
32373253
/* }}} */
32383254

3255+
void zend_unload_modules(void) /* {{{ */
3256+
{
3257+
zend_module_entry **modules = modules_dl_loaded;
3258+
while (*modules) {
3259+
module_registry_unload(*modules);
3260+
modules++;
3261+
}
3262+
free(modules_dl_loaded);
3263+
modules_dl_loaded = NULL;
3264+
}
3265+
/* }}} */
3266+
32393267
ZEND_API void zend_post_deactivate_modules(void) /* {{{ */
32403268
{
32413269
if (EG(full_tables_cleanup)) {
@@ -3254,6 +3282,9 @@ ZEND_API void zend_post_deactivate_modules(void) /* {{{ */
32543282
break;
32553283
}
32563284
module_destructor(module);
3285+
if (module->handle) {
3286+
module_registry_unload(module);
3287+
}
32573288
zend_string_release_ex(key, 0);
32583289
} ZEND_HASH_MAP_FOREACH_END_DEL();
32593290
} else {

Zend/zend_modules.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ extern ZEND_API HashTable module_registry;
125125

126126
void module_destructor(zend_module_entry *module);
127127
int module_registry_request_startup(zend_module_entry *module);
128-
int module_registry_unload_temp(const zend_module_entry *module);
128+
void module_registry_unload(const zend_module_entry *module);
129129
END_EXTERN_C()
130130

131131
#endif

0 commit comments

Comments
 (0)