@@ -12426,6 +12426,23 @@ static int zend_jit_fetch_dim_read(zend_jit_ctx *jit,
12426
12426
}
12427
12427
12428
12428
#ifdef HAVE_FFI
12429
+ static int zend_jit_class_guard(zend_jit_ctx *jit, const zend_op *opline, ir_ref obj_ref, zend_class_entry *ce);
12430
+
12431
+ static int zend_jit_ffi_type_guard(zend_jit_ctx *jit, const zend_op *opline, ir_ref obj_ref, zend_ffi_type *ffi_type)
12432
+ {
12433
+ int32_t exit_point = zend_jit_trace_get_exit_point(opline, 0);
12434
+ const void *exit_addr = zend_jit_trace_get_exit_addr(exit_point);
12435
+
12436
+ if (!exit_addr) {
12437
+ return 0;
12438
+ }
12439
+
12440
+ ir_GUARD(ir_EQ(ir_LOAD_A(ir_ADD_OFFSET(obj_ref, offsetof(zend_ffi_cdata, type))), ir_CONST_ADDR(ffi_type)),
12441
+ ir_CONST_ADDR(exit_addr));
12442
+
12443
+ return 1;
12444
+ }
12445
+
12429
12446
static int zend_jit_ffi_abc(zend_jit_ctx *jit,
12430
12447
const zend_op *opline,
12431
12448
zend_ffi_type *ffi_type,
@@ -12492,15 +12509,30 @@ static int zend_jit_ffi_fetch_dim_read(zend_jit_ctx *jit,
12492
12509
{
12493
12510
uint32_t res_type;
12494
12511
zend_ffi_type *el_type = ZEND_FFI_TYPE(op1_ffi_type->array.type);
12512
+ ir_ref obj_ref = jit_Z_PTR(jit, op1_addr);
12513
+
12514
+ if (ssa->var_info
12515
+ && ssa_op->op1_use >= 0
12516
+ && ssa->var_info[ssa_op->op1_use].ce != zend_ffi_cdata_ce) {
12517
+ if (!zend_jit_class_guard(jit, opline, obj_ref, zend_ffi_cdata_ce)) {
12518
+ return 0;
12519
+ }
12520
+ if (ssa->var_info && ssa_op->op1_use >= 0) {
12521
+ ssa->var_info[ssa_op->op1_use].type |= MAY_BE_CLASS_GUARD;
12522
+ ssa->var_info[ssa_op->op1_use].ce = zend_ffi_cdata_ce;
12523
+ ssa->var_info[ssa_op->op1_use].is_instanceof = 0;
12524
+ }
12525
+ }
12495
12526
12496
- // TODO: ce guard ???
12497
12527
// TODO: ffi type guard ???
12528
+ if (!zend_jit_ffi_type_guard(jit, opline, obj_ref, op1_ffi_type)) {
12529
+ return 0;
12530
+ }
12498
12531
12499
12532
if (!zend_jit_ffi_abc(jit, opline, op1_ffi_type, op2_info, op2_addr, op2_range)) {
12500
12533
return 0;
12501
12534
}
12502
12535
12503
- ir_ref obj_ref = jit_Z_PTR(jit, op1_addr);
12504
12536
ir_ref cdata_ref = ir_LOAD_A(ir_ADD_OFFSET(obj_ref, offsetof(zend_ffi_cdata, ptr)));
12505
12537
12506
12538
if (op1_ffi_type->kind == ZEND_FFI_TYPE_POINTER) {
@@ -13238,29 +13270,51 @@ static int zend_jit_assign_dim(zend_jit_ctx *jit,
13238
13270
}
13239
13271
13240
13272
#ifdef HAVE_FFI
13241
- static int zend_jit_ffi_assign_dim(zend_jit_ctx *jit,
13242
- const zend_op *opline,
13243
- uint32_t op1_info,
13244
- zend_jit_addr op1_addr,
13245
- uint32_t op2_info,
13246
- zend_jit_addr op2_addr,
13247
- zend_ssa_range *op2_range,
13248
- uint32_t val_info,
13249
- zend_jit_addr op3_addr,
13250
- zend_jit_addr op3_def_addr,
13251
- zend_jit_addr res_addr,
13252
- zend_ffi_type *op1_ffi_type)
13273
+ static int zend_jit_ffi_assign_dim(zend_jit_ctx *jit,
13274
+ const zend_op *opline,
13275
+ zend_ssa *ssa,
13276
+ const zend_ssa_op *ssa_op,
13277
+ uint32_t op1_info,
13278
+ zend_jit_addr op1_addr,
13279
+ uint32_t op2_info,
13280
+ zend_jit_addr op2_addr,
13281
+ zend_ssa_range *op2_range,
13282
+ uint32_t val_info,
13283
+ zend_jit_addr op3_addr,
13284
+ zend_jit_addr op3_def_addr,
13285
+ zend_jit_addr res_addr,
13286
+ zend_ffi_type *op1_ffi_type)
13253
13287
{
13254
13288
zend_ffi_type *el_type = ZEND_FFI_TYPE(op1_ffi_type->array.type);
13289
+ ir_ref obj_ref = jit_Z_PTR(jit, op1_addr);
13290
+
13291
+ if (ssa->var_info
13292
+ && ssa_op->op1_use >= 0
13293
+ && ssa->var_info[ssa_op->op1_use].ce != zend_ffi_cdata_ce) {
13294
+ if (!zend_jit_class_guard(jit, opline, obj_ref, zend_ffi_cdata_ce)) {
13295
+ return 0;
13296
+ }
13297
+ if (ssa->var_info && ssa_op->op1_use >= 0) {
13298
+ ssa->var_info[ssa_op->op1_use].type |= MAY_BE_CLASS_GUARD;
13299
+ ssa->var_info[ssa_op->op1_use].ce = zend_ffi_cdata_ce;
13300
+ ssa->var_info[ssa_op->op1_use].is_instanceof = 0;
13301
+ }
13302
+ if (ssa->var_info && ssa_op->op1_def >= 0) {
13303
+ ssa->var_info[ssa_op->op1_def].type |= MAY_BE_CLASS_GUARD;
13304
+ ssa->var_info[ssa_op->op1_def].ce = zend_ffi_cdata_ce;
13305
+ ssa->var_info[ssa_op->op1_def].is_instanceof = 0;
13306
+ }
13307
+ }
13255
13308
13256
- // TODO: ce guard ???
13257
13309
// TODO: ffi type guard ???
13310
+ if (!zend_jit_ffi_type_guard(jit, opline, obj_ref, op1_ffi_type)) {
13311
+ return 0;
13312
+ }
13258
13313
13259
13314
if (!zend_jit_ffi_abc(jit, opline, op1_ffi_type, op2_info, op2_addr, op2_range)) {
13260
13315
return 0;
13261
13316
}
13262
13317
13263
- ir_ref obj_ref = jit_Z_PTR(jit, op1_addr);
13264
13318
ir_ref cdata_ref = ir_LOAD_A(ir_ADD_OFFSET(obj_ref, offsetof(zend_ffi_cdata, ptr)));
13265
13319
13266
13320
if (op1_ffi_type->kind == ZEND_FFI_TYPE_POINTER) {
@@ -13730,29 +13784,51 @@ static int zend_jit_ffi_assign_op_helper(zend_jit_ctx *jit,
13730
13784
return 1;
13731
13785
}
13732
13786
13733
- static int zend_jit_ffi_assign_dim_op(zend_jit_ctx *jit,
13734
- const zend_op *opline,
13735
- uint32_t op1_info,
13736
- uint32_t op1_def_info,
13737
- zend_jit_addr op1_addr,
13738
- uint32_t op2_info,
13739
- zend_jit_addr op2_addr,
13740
- zend_ssa_range *op2_range,
13741
- uint32_t op1_data_info,
13742
- zend_jit_addr op3_addr,
13743
- zend_ssa_range *op1_data_range,
13744
- zend_ffi_type *op1_ffi_type)
13787
+ static int zend_jit_ffi_assign_dim_op(zend_jit_ctx *jit,
13788
+ const zend_op *opline,
13789
+ zend_ssa *ssa,
13790
+ const zend_ssa_op *ssa_op,
13791
+ uint32_t op1_info,
13792
+ uint32_t op1_def_info,
13793
+ zend_jit_addr op1_addr,
13794
+ uint32_t op2_info,
13795
+ zend_jit_addr op2_addr,
13796
+ zend_ssa_range *op2_range,
13797
+ uint32_t op1_data_info,
13798
+ zend_jit_addr op3_addr,
13799
+ zend_ssa_range *op1_data_range,
13800
+ zend_ffi_type *op1_ffi_type)
13745
13801
{
13746
13802
zend_ffi_type *el_type = ZEND_FFI_TYPE(op1_ffi_type->array.type);
13803
+ ir_ref obj_ref = jit_Z_PTR(jit, op1_addr);
13804
+
13805
+ if (ssa->var_info
13806
+ && ssa_op->op1_use >= 0
13807
+ && ssa->var_info[ssa_op->op1_use].ce != zend_ffi_cdata_ce) {
13808
+ if (!zend_jit_class_guard(jit, opline, obj_ref, zend_ffi_cdata_ce)) {
13809
+ return 0;
13810
+ }
13811
+ if (ssa->var_info && ssa_op->op1_use >= 0) {
13812
+ ssa->var_info[ssa_op->op1_use].type |= MAY_BE_CLASS_GUARD;
13813
+ ssa->var_info[ssa_op->op1_use].ce = zend_ffi_cdata_ce;
13814
+ ssa->var_info[ssa_op->op1_use].is_instanceof = 0;
13815
+ }
13816
+ if (ssa->var_info && ssa_op->op1_def >= 0) {
13817
+ ssa->var_info[ssa_op->op1_def].type |= MAY_BE_CLASS_GUARD;
13818
+ ssa->var_info[ssa_op->op1_def].ce = zend_ffi_cdata_ce;
13819
+ ssa->var_info[ssa_op->op1_def].is_instanceof = 0;
13820
+ }
13821
+ }
13747
13822
13748
- // TODO: ce guard ???
13749
13823
// TODO: ffi type guard ???
13824
+ if (!zend_jit_ffi_type_guard(jit, opline, obj_ref, op1_ffi_type)) {
13825
+ return 0;
13826
+ }
13750
13827
13751
13828
if (!zend_jit_ffi_abc(jit, opline, op1_ffi_type, op2_info, op2_addr, op2_range)) {
13752
13829
return 0;
13753
13830
}
13754
13831
13755
- ir_ref obj_ref = jit_Z_PTR(jit, op1_addr);
13756
13832
ir_ref cdata_ref = ir_LOAD_A(ir_ADD_OFFSET(obj_ref, offsetof(zend_ffi_cdata, ptr)));
13757
13833
13758
13834
if (op1_ffi_type->kind == ZEND_FFI_TYPE_POINTER) {
0 commit comments