Skip to content

Commit 086efde

Browse files
committed
Add IS_OBJECT type assertions
1 parent 3e4e6d0 commit 086efde

File tree

2 files changed

+80
-48
lines changed

2 files changed

+80
-48
lines changed

ext/opcache/jit/zend_jit_ir_ffi.c

Lines changed: 70 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,20 @@ static int zend_jit_ffi_symbols_guard(zend_jit_ctx *jit,
3131
zend_ssa *ssa,
3232
int use,
3333
int def,
34+
uint32_t info,
3435
zend_jit_addr addr,
3536
HashTable *ffi_symbols,
3637
zend_jit_ffi_info *ffi_info);
3738

38-
static int zend_jit_ffi_guard(zend_jit_ctx *jit,
39-
const zend_op *opline,
40-
zend_ssa *ssa,
41-
int use,
42-
int def,
43-
ir_ref ref,
44-
zend_ffi_type *ffi_type,
45-
zend_jit_ffi_info *ffi_info);
39+
static ir_ref zend_jit_ffi_guard(zend_jit_ctx *jit,
40+
const zend_op *opline,
41+
zend_ssa *ssa,
42+
int use,
43+
int def,
44+
uint32_t info,
45+
zend_jit_addr addr,
46+
zend_ffi_type *ffi_type,
47+
zend_jit_ffi_info *ffi_info);
4648

4749
static int zend_jit_ffi_init_call_sym(zend_jit_ctx *jit,
4850
const zend_op *opline,
@@ -62,7 +64,7 @@ static int zend_jit_ffi_init_call_sym(zend_jit_ctx *jit,
6264
type = ZEND_FFI_TYPE(sym->type);
6365
ZEND_ASSERT(type->kind == ZEND_FFI_TYPE_FUNC);
6466

65-
if (!zend_jit_ffi_symbols_guard(jit, opline, ssa, ssa_op->op1_use, -1, op1_addr, op1_ffi_symbols, ffi_info)) {
67+
if (!zend_jit_ffi_symbols_guard(jit, opline, ssa, ssa_op->op1_use, -1, op1_info, op1_addr, op1_ffi_symbols, ffi_info)) {
6668
return 0;
6769
}
6870

@@ -92,14 +94,15 @@ static int zend_jit_ffi_init_call_obj(zend_jit_ctx *jit,
9294
zend_jit_ffi_info *ffi_info,
9395
ir_ref *ffi_func_ref)
9496
{
95-
ir_ref obj_ref = jit_Z_PTR(jit, op2_addr);
97+
ir_ref obj_ref;
9698
zend_ffi_type *type;
9799

98100
ZEND_ASSERT(op2_ffi_type->kind == ZEND_FFI_TYPE_POINTER);
99101
type = ZEND_FFI_TYPE(op2_ffi_type->pointer.type);
100102
ZEND_ASSERT(type->kind == ZEND_FFI_TYPE_FUNC);
101103

102-
if (!zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op2_use, -1, obj_ref, op2_ffi_type, ffi_info)) {
104+
obj_ref = zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op2_use, -1, op2_info, op2_addr, op2_ffi_type, ffi_info);
105+
if (!obj_ref) {
103106
return 0;
104107
}
105108

@@ -890,15 +893,22 @@ static int zend_jit_ffi_read(zend_jit_ctx *jit,
890893
return 1;
891894
}
892895

893-
static int zend_jit_ffi_guard(zend_jit_ctx *jit,
894-
const zend_op *opline,
895-
zend_ssa *ssa,
896-
int use,
897-
int def,
898-
ir_ref ref,
899-
zend_ffi_type *ffi_type,
900-
zend_jit_ffi_info *ffi_info)
896+
static ir_ref zend_jit_ffi_guard(zend_jit_ctx *jit,
897+
const zend_op *opline,
898+
zend_ssa *ssa,
899+
int use,
900+
int def,
901+
uint32_t info,
902+
zend_jit_addr addr,
903+
zend_ffi_type *ffi_type,
904+
zend_jit_ffi_info *ffi_info)
901905
{
906+
ir_ref ref;
907+
908+
/* MAY_BE_GUARD may be added by zend_jit_fetch_reference() */
909+
ZEND_ASSERT((info & (/*MAY_BE_GUARD|*/MAY_BE_REF|MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_OBJECT);
910+
911+
ref = jit_Z_PTR(jit, addr);
902912
if (ssa->var_info
903913
&& use >= 0
904914
&& ssa->var_info[use].ce != zend_ffi_api->cdata_ce) {
@@ -930,20 +940,23 @@ static int zend_jit_ffi_guard(zend_jit_ctx *jit,
930940
}
931941
}
932942

933-
return 1;
943+
return ref;
934944
}
935945

936946
static int zend_jit_ffi_symbols_guard(zend_jit_ctx *jit,
937947
const zend_op *opline,
938948
zend_ssa *ssa,
939949
int use,
940950
int def,
951+
uint32_t info,
941952
zend_jit_addr addr,
942953
HashTable *ffi_symbols,
943954
zend_jit_ffi_info *ffi_info)
944955
{
945956
ir_ref ref = IR_UNUSED;
946957

958+
ZEND_ASSERT((info & (MAY_BE_GUARD|MAY_BE_REF|MAY_BE_ANY|MAY_BE_UNDEF)) == MAY_BE_OBJECT);
959+
947960
if (ssa->var_info
948961
&& use >= 0
949962
&& ssa->var_info[use].ce != zend_ffi_api->scope_ce) {
@@ -1007,9 +1020,10 @@ static int zend_jit_ffi_fetch_dim(zend_jit_ctx *jit,
10071020
zend_jit_ffi_info *ffi_info)
10081021
{
10091022
zend_ffi_type *el_type = ZEND_FFI_TYPE(op1_ffi_type->array.type);
1010-
ir_ref obj_ref = jit_Z_PTR(jit, op1_addr);
1023+
ir_ref obj_ref;
10111024

1012-
if (!zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, -1, obj_ref, op1_ffi_type, ffi_info)) {
1025+
obj_ref = zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, -1, op1_info, op1_addr, op1_ffi_type, ffi_info);
1026+
if (!obj_ref) {
10131027
return 0;
10141028
}
10151029

@@ -1349,9 +1363,10 @@ static int zend_jit_ffi_assign_dim(zend_jit_ctx *jit,
13491363
zend_jit_ffi_info *ffi_info)
13501364
{
13511365
zend_ffi_type *el_type = ZEND_FFI_TYPE(op1_ffi_type->array.type);
1352-
ir_ref obj_ref = jit_Z_PTR(jit, op1_addr);
1366+
ir_ref obj_ref;
13531367

1354-
if (!zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, obj_ref, op1_ffi_type, ffi_info)) {
1368+
obj_ref = zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, op1_info, op1_addr, op1_ffi_type, ffi_info);
1369+
if (!obj_ref) {
13551370
return 0;
13561371
}
13571372

@@ -1596,9 +1611,10 @@ static int zend_jit_ffi_assign_dim_op(zend_jit_ctx *jit,
15961611
zend_jit_ffi_info *ffi_info)
15971612
{
15981613
zend_ffi_type *el_type = ZEND_FFI_TYPE(op1_ffi_type->array.type);
1599-
ir_ref obj_ref = jit_Z_PTR(jit, op1_addr);
1614+
ir_ref obj_ref;
16001615

1601-
if (!zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, obj_ref, op1_ffi_type, ffi_info)) {
1616+
obj_ref = zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, op1_info, op1_addr, op1_ffi_type, ffi_info);
1617+
if (!obj_ref) {
16021618
return 0;
16031619
}
16041620

@@ -1644,9 +1660,10 @@ static int zend_jit_ffi_fetch_obj(zend_jit_ctx *jit,
16441660
{
16451661
uint32_t res_info = RES_INFO();
16461662
zend_ffi_type *field_type = ZEND_FFI_TYPE(field->type);
1647-
ir_ref obj_ref = jit_Z_PTR(jit, op1_addr);
1663+
ir_ref obj_ref;
16481664

1649-
if (!zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, -1, obj_ref, op1_ffi_type, ffi_info)) {
1665+
obj_ref = zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, -1, op1_info, op1_addr, op1_ffi_type, ffi_info);
1666+
if (!obj_ref) {
16501667
return 0;
16511668
}
16521669

@@ -1692,9 +1709,10 @@ static int zend_jit_ffi_fetch_val(zend_jit_ctx *jit,
16921709
zend_jit_ffi_info *ffi_info)
16931710
{
16941711
uint32_t res_info = RES_INFO();
1695-
ir_ref obj_ref = jit_Z_PTR(jit, op1_addr);
1712+
ir_ref obj_ref;
16961713

1697-
if (!zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, -1, obj_ref, op1_ffi_type, ffi_info)) {
1714+
obj_ref = zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, -1, op1_info, op1_addr, op1_ffi_type, ffi_info);
1715+
if (!obj_ref) {
16981716
return 0;
16991717
}
17001718

@@ -1742,7 +1760,7 @@ static int zend_jit_ffi_fetch_sym(zend_jit_ctx *jit,
17421760
uint32_t res_info = RES_INFO();
17431761
zend_ffi_type *sym_type = ZEND_FFI_TYPE(sym->type);
17441762

1745-
if (!zend_jit_ffi_symbols_guard(jit, opline, ssa, ssa_op->op1_use, -1, op1_addr, op1_ffi_symbols, ffi_info)) {
1763+
if (!zend_jit_ffi_symbols_guard(jit, opline, ssa, ssa_op->op1_use, -1, op1_info, op1_addr, op1_ffi_symbols, ffi_info)) {
17461764
return 0;
17471765
}
17481766

@@ -1791,9 +1809,10 @@ static int zend_jit_ffi_assign_obj(zend_jit_ctx *jit,
17911809
zend_jit_ffi_info *ffi_info)
17921810
{
17931811
zend_ffi_type *field_type = ZEND_FFI_TYPE(field->type);
1794-
ir_ref obj_ref = jit_Z_PTR(jit, op1_addr);
1812+
ir_ref obj_ref;
17951813

1796-
if (!zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, obj_ref, op1_ffi_type, ffi_info)) {
1814+
obj_ref = zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, op1_info, op1_addr, op1_ffi_type, ffi_info);
1815+
if (!obj_ref) {
17971816
return 0;
17981817
}
17991818

@@ -1840,9 +1859,10 @@ static int zend_jit_ffi_assign_val(zend_jit_ctx *jit,
18401859
zend_ffi_type *val_ffi_type,
18411860
zend_jit_ffi_info *ffi_info)
18421861
{
1843-
ir_ref obj_ref = jit_Z_PTR(jit, op1_addr);
1862+
ir_ref obj_ref;
18441863

1845-
if (!zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, obj_ref, op1_ffi_type, ffi_info)) {
1864+
obj_ref = zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, op1_info, op1_addr, op1_ffi_type, ffi_info);
1865+
if (!obj_ref) {
18461866
return 0;
18471867
}
18481868

@@ -1891,7 +1911,7 @@ static int zend_jit_ffi_assign_sym(zend_jit_ctx *jit,
18911911
{
18921912
zend_ffi_type *sym_type = ZEND_FFI_TYPE(sym->type);
18931913

1894-
if (!zend_jit_ffi_symbols_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, op1_addr, op1_ffi_symbols, ffi_info)) {
1914+
if (!zend_jit_ffi_symbols_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, op1_info, op1_addr, op1_ffi_symbols, ffi_info)) {
18951915
return 0;
18961916
}
18971917

@@ -1935,9 +1955,10 @@ static int zend_jit_ffi_assign_obj_op(zend_jit_ctx *jit,
19351955
zend_jit_ffi_info *ffi_info)
19361956
{
19371957
zend_ffi_type *field_type = ZEND_FFI_TYPE(field->type);
1938-
ir_ref obj_ref = jit_Z_PTR(jit, op1_addr);
1958+
ir_ref obj_ref;
19391959

1940-
if (!zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, obj_ref, op1_ffi_type, ffi_info)) {
1960+
obj_ref = zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, op1_info, op1_addr, op1_ffi_type, ffi_info);
1961+
if (!obj_ref) {
19411962
return 0;
19421963
}
19431964

@@ -1971,9 +1992,10 @@ static int zend_jit_ffi_assign_val_op(zend_jit_ctx *jit,
19711992
zend_ffi_type *op1_ffi_type,
19721993
zend_jit_ffi_info *ffi_info)
19731994
{
1974-
ir_ref obj_ref = jit_Z_PTR(jit, op1_addr);
1995+
ir_ref obj_ref;
19751996

1976-
if (!zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, obj_ref, op1_ffi_type, ffi_info)) {
1997+
obj_ref = zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, op1_info, op1_addr, op1_ffi_type, ffi_info);
1998+
if (!obj_ref) {
19771999
return 0;
19782000
}
19792001

@@ -2009,7 +2031,7 @@ static int zend_jit_ffi_assign_sym_op(zend_jit_ctx *jit,
20092031
{
20102032
zend_ffi_type *sym_type = ZEND_FFI_TYPE(sym->type);
20112033

2012-
if (!zend_jit_ffi_symbols_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, op1_addr, op1_ffi_symbols, ffi_info)) {
2034+
if (!zend_jit_ffi_symbols_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, op1_info, op1_addr, op1_ffi_symbols, ffi_info)) {
20132035
return 0;
20142036
}
20152037

@@ -2249,9 +2271,10 @@ static int zend_jit_ffi_incdec_obj(zend_jit_ctx *jit,
22492271
zend_jit_ffi_info *ffi_info)
22502272
{
22512273
zend_ffi_type *field_type = ZEND_FFI_TYPE(field->type);
2252-
ir_ref obj_ref = jit_Z_PTR(jit, op1_addr);
2274+
ir_ref obj_ref;
22532275

2254-
if (!zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, obj_ref, op1_ffi_type, ffi_info)) {
2276+
obj_ref = zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, op1_info, op1_addr, op1_ffi_type, ffi_info);
2277+
if (!obj_ref) {
22552278
return 0;
22562279
}
22572280

@@ -2281,9 +2304,10 @@ static int zend_jit_ffi_incdec_val(zend_jit_ctx *jit,
22812304
zend_ffi_type *op1_ffi_type,
22822305
zend_jit_ffi_info *ffi_info)
22832306
{
2284-
ir_ref obj_ref = jit_Z_PTR(jit, op1_addr);
2307+
ir_ref obj_ref;
22852308

2286-
if (!zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, obj_ref, op1_ffi_type, ffi_info)) {
2309+
obj_ref = zend_jit_ffi_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, op1_info, op1_addr, op1_ffi_type, ffi_info);
2310+
if (!obj_ref) {
22872311
return 0;
22882312
}
22892313

@@ -2315,7 +2339,7 @@ static int zend_jit_ffi_incdec_sym(zend_jit_ctx *jit,
23152339
{
23162340
zend_ffi_type *sym_type = ZEND_FFI_TYPE(sym->type);
23172341

2318-
if (!zend_jit_ffi_symbols_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, op1_addr, op1_ffi_symbols, ffi_info)) {
2342+
if (!zend_jit_ffi_symbols_guard(jit, opline, ssa, ssa_op->op1_use, ssa_op->op1_def, op1_info, op1_addr, op1_ffi_symbols, ffi_info)) {
23192343
return 0;
23202344
}
23212345

ext/opcache/jit/zend_jit_trace.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2324,9 +2324,17 @@ static zend_ssa *zend_jit_trace_build_tssa(zend_jit_trace_rec *trace_buffer, uin
23242324
#endif
23252325
break;
23262326
case ZEND_INIT_DYNAMIC_CALL:
2327-
if (orig_op2_type == IS_OBJECT && op2_ce == zend_ce_closure) {
2328-
ADD_OP2_TRACE_GUARD();
2327+
#ifdef HAVE_FFI
2328+
if (orig_op2_type != IS_OBJECT
2329+
|| (op2_ce != zend_ce_closure && !op2_ffi_type)) {
2330+
break;
2331+
}
2332+
#else
2333+
if (orig_op2_type != IS_OBJECT || op2_ce != zend_ce_closure) {
2334+
break;
23292335
}
2336+
#endif
2337+
ADD_OP2_TRACE_GUARD();
23302338
break;
23312339
case ZEND_SEND_ARRAY:
23322340
case ZEND_SEND_UNPACK:

0 commit comments

Comments
 (0)