Skip to content

Commit 294e408

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Fix race condition in zend_runtime_jit(), zend_jit_hot_func()
2 parents 1ca78dd + 359ad80 commit 294e408

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ PHP NEWS
2121
. Fixed segfault in function JIT due to NAN to bool warning. (Girgias)
2222
. Fixed bug GH-19984 (Double-free of EG(errors)/persistent_script->warnings on
2323
persist of already persisted file). (ilutov, Arnaud)
24+
. Fixed bug GH-19889 (race condition in zend_runtime_jit(),
25+
zend_jit_hot_func()). (Arnaud)
2426

2527
- SOAP:
2628
. Fixed bug GH-19773 (SIGSEGV due to uninitialized soap_globals->lang_en).

Zend/Optimizer/zend_func_info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#define ZEND_FUNC_JIT_ON_PROF_REQUEST (1<<14) /* used by JIT */
4040
#define ZEND_FUNC_JIT_ON_HOT_COUNTERS (1<<15) /* used by JIT */
4141
#define ZEND_FUNC_JIT_ON_HOT_TRACE (1<<16) /* used by JIT */
42-
42+
#define ZEND_FUNC_JITED (1<<17) /* used by JIT */
4343

4444
typedef struct _zend_func_info zend_func_info;
4545
typedef struct _zend_call_info zend_call_info;

ext/opcache/jit/zend_jit.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3098,8 +3098,9 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV zend_runtime_jit(Z
30983098
bool do_bailout = 0;
30993099

31003100
zend_shared_alloc_lock();
3101+
jit_extension = (zend_jit_op_array_extension*)ZEND_FUNC_INFO(op_array);
31013102

3102-
if (ZEND_FUNC_INFO(op_array)) {
3103+
if (jit_extension && !(jit_extension->func_info.flags & ZEND_FUNC_JITED)) {
31033104

31043105
SHM_UNPROTECT();
31053106
zend_jit_unprotect();
@@ -3111,11 +3112,12 @@ static ZEND_OPCODE_HANDLER_RET ZEND_OPCODE_HANDLER_FUNC_CCONV zend_runtime_jit(Z
31113112
opline++;
31123113
}
31133114
}
3114-
jit_extension = (zend_jit_op_array_extension*)ZEND_FUNC_INFO(op_array);
31153115
((zend_op*)opline)->handler = jit_extension->orig_handler;
31163116

31173117
/* perform real JIT for this function */
31183118
zend_real_jit_func(op_array, NULL, NULL, ZEND_JIT_ON_FIRST_EXEC);
3119+
3120+
jit_extension->func_info.flags |= ZEND_FUNC_JITED;
31193121
} zend_catch {
31203122
do_bailout = true;
31213123
} zend_end_try();
@@ -3182,7 +3184,7 @@ void ZEND_FASTCALL zend_jit_hot_func(zend_execute_data *execute_data, const zend
31823184
zend_shared_alloc_lock();
31833185
jit_extension = (zend_jit_op_array_hot_extension*)ZEND_FUNC_INFO(op_array);
31843186

3185-
if (jit_extension) {
3187+
if (jit_extension && !(jit_extension->func_info.flags & ZEND_FUNC_JITED)) {
31863188
SHM_UNPROTECT();
31873189
zend_jit_unprotect();
31883190

@@ -3195,6 +3197,8 @@ void ZEND_FASTCALL zend_jit_hot_func(zend_execute_data *execute_data, const zend
31953197

31963198
/* perform real JIT for this function */
31973199
zend_real_jit_func(op_array, NULL, opline, ZEND_JIT_ON_HOT_COUNTERS);
3200+
3201+
jit_extension->func_info.flags |= ZEND_FUNC_JITED;
31983202
} zend_catch {
31993203
do_bailout = 1;
32003204
} zend_end_try();

0 commit comments

Comments
 (0)