Skip to content

Commit 8ecfc0c

Browse files
committed
Improve zend_jit_stop_counter_handlers() locking
Use atomic to prevent resetting handlers from multiple processes or threads. Fixes phpGH-11609
1 parent 30a80b8 commit 8ecfc0c

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

ext/opcache/jit/zend_jit_trace.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
static zend_op_array dummy_op_array;
2020
static zend_jit_trace_info *zend_jit_traces = NULL;
2121
static const void **zend_jit_exit_groups = NULL;
22+
static zend_atomic_bool jit_counters_stopped;
2223

2324
#define ZEND_JIT_COUNTER_NUM zend_jit_traces[0].root
2425
#define ZEND_JIT_TRACE_NUM zend_jit_traces[0].id
@@ -63,6 +64,7 @@ static int zend_jit_trace_startup(zend_bool reattached)
6364
ZEND_JIT_EXIT_COUNTERS = 0;
6465
ZCSG(jit_traces) = zend_jit_traces;
6566
ZCSG(jit_exit_groups) = zend_jit_exit_groups;
67+
ZEND_ATOMIC_BOOL_INIT(&jit_counters_stopped, false);
6668
} else {
6769
zend_jit_traces = ZCSG(jit_traces);
6870
if (!zend_jit_traces) {
@@ -7242,6 +7244,10 @@ static void zend_jit_stop_persistent_script(zend_persistent_script *script)
72427244
/* Get all scripts which are accelerated by JIT */
72437245
static void zend_jit_stop_counter_handlers(void)
72447246
{
7247+
if (zend_atomic_bool_exchange_ex(&jit_counters_stopped, true)) {
7248+
return;
7249+
}
7250+
72457251
zend_shared_alloc_lock();
72467252
/* mprotect has an extreme overhead, avoid calls to it for every function. */
72477253
SHM_UNPROTECT();

0 commit comments

Comments
 (0)