@@ -30,6 +30,15 @@ static int zend_jit_ffi_symbols_guard(zend_jit_ctx *jit,
3030 HashTable * ffi_symbols ,
3131 zend_jit_ffi_info * ffi_info );
3232
33+ static int zend_jit_ffi_guard (zend_jit_ctx * jit ,
34+ const zend_op * opline ,
35+ zend_ssa * ssa ,
36+ int use ,
37+ int def ,
38+ ir_ref ref ,
39+ zend_ffi_type * ffi_type ,
40+ zend_jit_ffi_info * ffi_info );
41+
3342static int zend_jit_ffi_init_call_sym (zend_jit_ctx * jit ,
3443 const zend_op * opline ,
3544 const zend_op_array * op_array ,
@@ -39,12 +48,56 @@ static int zend_jit_ffi_init_call_sym(zend_jit_ctx *jit,
3948 zend_jit_addr op1_addr ,
4049 zend_ffi_symbol * sym ,
4150 HashTable * op1_ffi_symbols ,
42- zend_jit_ffi_info * ffi_info )
51+ zend_jit_ffi_info * ffi_info ,
52+ ir_ref * ffi_func_ref )
4353{
54+ zend_ffi_type * type ;
55+
56+ ZEND_ASSERT (sym -> kind == ZEND_FFI_SYM_FUNC );
57+ type = ZEND_FFI_TYPE (sym -> type );
58+ ZEND_ASSERT (type -> kind == ZEND_FFI_TYPE_FUNC );
59+
4460 if (!zend_jit_ffi_symbols_guard (jit , opline , ssa , ssa_op -> op1_use , -1 , op1_addr , op1_ffi_symbols , ffi_info )) {
4561 return 0 ;
4662 }
4763
64+ if (type -> func .abi == ZEND_FFI_ABI_FASTCALL ) {
65+ * ffi_func_ref = ir_CONST_FC_FUNC (sym -> addr );
66+ } else {
67+ * ffi_func_ref = ir_CONST_FUNC (sym -> addr );
68+ }
69+ return 1 ;
70+ }
71+
72+ static int zend_jit_ffi_init_call_obj (zend_jit_ctx * jit ,
73+ const zend_op * opline ,
74+ const zend_op_array * op_array ,
75+ zend_ssa * ssa ,
76+ const zend_ssa_op * ssa_op ,
77+ uint32_t op1_info ,
78+ zend_jit_addr op1_addr ,
79+ uint32_t op2_info ,
80+ zend_jit_addr op2_addr ,
81+ zend_ffi_type * op2_ffi_type ,
82+ zend_jit_ffi_info * ffi_info ,
83+ ir_ref * ffi_func_ref )
84+ {
85+ ir_ref obj_ref = jit_Z_PTR (jit , op2_addr );
86+ zend_ffi_type * type ;
87+
88+ ZEND_ASSERT (op2_ffi_type -> kind == ZEND_FFI_TYPE_POINTER );
89+ type = ZEND_FFI_TYPE (op2_ffi_type -> pointer .type );
90+ ZEND_ASSERT (type -> kind == ZEND_FFI_TYPE_FUNC );
91+
92+ if (!zend_jit_ffi_guard (jit , opline , ssa , ssa_op -> op2_use , -1 , obj_ref , op2_ffi_type , ffi_info )) {
93+ return 0 ;
94+ }
95+
96+ * ffi_func_ref = ir_LOAD_A (jit_FFI_CDATA_PTR (jit , obj_ref ));
97+ if (type -> func .abi == ZEND_FFI_ABI_FASTCALL ) {
98+ * ffi_func_ref = ir_CAST_FC_FUNC (* ffi_func_ref );
99+ }
100+
48101 return 1 ;
49102}
50103
@@ -60,12 +113,9 @@ static int zend_jit_ffi_send_val(zend_jit_ctx *jit,
60113{
61114 zend_jit_trace_stack_frame * call = JIT_G (current_frame )-> call ;
62115 zend_jit_trace_stack * stack = call -> stack ;
63- zend_ffi_symbol * sym = (zend_ffi_symbol * )(void * )call -> call_opline ;
64- zend_ffi_type * type ;
116+ zend_ffi_type * type = (zend_ffi_type * )(void * )call -> call_opline ;
65117 ir_ref ref = IR_UNUSED ;
66118
67- ZEND_ASSERT (sym -> kind == ZEND_FFI_SYM_FUNC );
68- type = ZEND_FFI_TYPE (sym -> type );
69119 ZEND_ASSERT (type -> kind == ZEND_FFI_TYPE_FUNC );
70120 if (type -> attr & ZEND_FFI_ATTR_VARIADIC ) {
71121 ZEND_ASSERT (TRACE_FRAME_NUM_ARGS (call ) >= zend_hash_num_elements (type -> func .args ));
@@ -225,22 +275,20 @@ static int zend_jit_ffi_send_val(zend_jit_ctx *jit,
225275 return 1 ;
226276}
227277
228- static int zend_jit_ffi_do_call_sym (zend_jit_ctx * jit ,
229- const zend_op * opline ,
230- const zend_op_array * op_array ,
231- zend_ssa * ssa ,
232- const zend_ssa_op * ssa_op ,
233- zend_jit_addr res_addr )
278+ static int zend_jit_ffi_do_call (zend_jit_ctx * jit ,
279+ const zend_op * opline ,
280+ const zend_op_array * op_array ,
281+ zend_ssa * ssa ,
282+ const zend_ssa_op * ssa_op ,
283+ zend_jit_addr res_addr )
234284{
235285 zend_jit_trace_stack_frame * call = JIT_G (current_frame )-> call ;
236- zend_ffi_symbol * sym = (zend_ffi_symbol * )(void * )call -> call_opline ;
286+ zend_ffi_type * type = (zend_ffi_type * )(void * )call -> call_opline ;
287+ ir_ref func_ref = (intptr_t )(void * )call -> ce ;
237288 uint32_t i , num_args ;
238- zend_ffi_type * type ;
239289 ir_type ret_type = IR_VOID ;
240290 ir_ref ref = IR_UNUSED ;
241291
242- ZEND_ASSERT (sym -> kind == ZEND_FFI_SYM_FUNC );
243- type = ZEND_FFI_TYPE (sym -> type );
244292 ZEND_ASSERT (type -> kind == ZEND_FFI_TYPE_FUNC );
245293
246294 switch (ZEND_FFI_TYPE (type -> func .ret_type )-> kind ) {
@@ -300,18 +348,10 @@ static int zend_jit_ffi_do_call_sym(zend_jit_ctx *jit,
300348 for (i = 0 ; i < num_args ; i ++ ) {
301349 args [i ] = STACK_REF (stack , i );
302350 }
303- if (type -> func .abi == ZEND_FFI_ABI_FASTCALL ) {
304- ref = ir_CALL_N (ret_type , ir_CONST_FC_FUNC (sym -> addr ), num_args , args );
305- } else {
306- ref = ir_CALL_N (ret_type , ir_CONST_FUNC (sym -> addr ), num_args , args );
307- }
351+ ref = ir_CALL_N (ret_type , func_ref , num_args , args );
308352 } else {
309353 ZEND_ASSERT (!type -> func .args );
310- if (type -> func .abi == ZEND_FFI_ABI_FASTCALL ) {
311- ref = ir_CALL (ret_type , ir_CONST_FC_FUNC (sym -> addr ));
312- } else {
313- ref = ir_CALL (ret_type , ir_CONST_FUNC (sym -> addr ));
314- }
354+ ref = ir_CALL (ret_type , func_ref );
315355 }
316356
317357 if (RETURN_VALUE_USED (opline )) {
0 commit comments