Skip to content

Commit 8dc689e

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Wrap JIT compiler with zend_try to recover in case of memory overflow
2 parents bad8c8e + 2568db2 commit 8dc689e

File tree

2 files changed

+223
-177
lines changed

2 files changed

+223
-177
lines changed

ext/opcache/jit/zend_jit.c

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4237,31 +4237,41 @@ static int ZEND_FASTCALL zend_runtime_jit(void)
42374237
zend_op_array *op_array = &EX(func)->op_array;
42384238
zend_op *opline = op_array->opcodes;
42394239
zend_jit_op_array_extension *jit_extension;
4240+
bool do_bailout = 0;
42404241

42414242
zend_shared_alloc_lock();
42424243

42434244
if (ZEND_FUNC_INFO(op_array)) {
4245+
42444246
SHM_UNPROTECT();
42454247
zend_jit_unprotect();
42464248

4247-
/* restore original opcode handlers */
4248-
if (!(op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS)) {
4249-
while (opline->opcode == ZEND_RECV || opline->opcode == ZEND_RECV_INIT) {
4250-
opline++;
4249+
zend_try {
4250+
/* restore original opcode handlers */
4251+
if (!(op_array->fn_flags & ZEND_ACC_HAS_TYPE_HINTS)) {
4252+
while (opline->opcode == ZEND_RECV || opline->opcode == ZEND_RECV_INIT) {
4253+
opline++;
4254+
}
42514255
}
4252-
}
4253-
jit_extension = (zend_jit_op_array_extension*)ZEND_FUNC_INFO(op_array);
4254-
opline->handler = jit_extension->orig_handler;
4256+
jit_extension = (zend_jit_op_array_extension*)ZEND_FUNC_INFO(op_array);
4257+
opline->handler = jit_extension->orig_handler;
42554258

4256-
/* perform real JIT for this function */
4257-
zend_real_jit_func(op_array, NULL, NULL);
4259+
/* perform real JIT for this function */
4260+
zend_real_jit_func(op_array, NULL, NULL);
4261+
} zend_catch {
4262+
do_bailout = 0;
4263+
} zend_end_try();
42584264

42594265
zend_jit_protect();
42604266
SHM_PROTECT();
42614267
}
42624268

42634269
zend_shared_alloc_unlock();
42644270

4271+
if (do_bailout) {
4272+
zend_bailout();
4273+
}
4274+
42654275
/* JIT-ed code is going to be called by VM */
42664276
return 0;
42674277
}
@@ -4304,6 +4314,7 @@ void ZEND_FASTCALL zend_jit_hot_func(zend_execute_data *execute_data, const zend
43044314
zend_op_array *op_array = &EX(func)->op_array;
43054315
zend_jit_op_array_hot_extension *jit_extension;
43064316
uint32_t i;
4317+
bool do_bailout = 0;
43074318

43084319
zend_shared_alloc_lock();
43094320
jit_extension = (zend_jit_op_array_hot_extension*)ZEND_FUNC_INFO(op_array);
@@ -4312,19 +4323,26 @@ void ZEND_FASTCALL zend_jit_hot_func(zend_execute_data *execute_data, const zend
43124323
SHM_UNPROTECT();
43134324
zend_jit_unprotect();
43144325

4315-
for (i = 0; i < op_array->last; i++) {
4316-
op_array->opcodes[i].handler = jit_extension->orig_handlers[i];
4317-
}
4326+
zend_try {
4327+
for (i = 0; i < op_array->last; i++) {
4328+
op_array->opcodes[i].handler = jit_extension->orig_handlers[i];
4329+
}
43184330

4319-
/* perform real JIT for this function */
4320-
zend_real_jit_func(op_array, NULL, opline);
4331+
/* perform real JIT for this function */
4332+
zend_real_jit_func(op_array, NULL, opline);
4333+
} zend_catch {
4334+
do_bailout = 1;
4335+
} zend_end_try();
43214336

43224337
zend_jit_protect();
43234338
SHM_PROTECT();
43244339
}
43254340

43264341
zend_shared_alloc_unlock();
43274342

4343+
if (do_bailout) {
4344+
zend_bailout();
4345+
}
43284346
/* JIT-ed code is going to be called by VM */
43294347
}
43304348

0 commit comments

Comments
 (0)