Skip to content

Commit cd5b933

Browse files
committed
use zend_execute_internal if set on internal-internal calls
This will allow modules that override zend_execute_internal to intercept all internal function calls, not just user-internal calls.
1 parent b11fa4e commit cd5b933

File tree

7 files changed

+34
-28
lines changed

7 files changed

+34
-28
lines changed

Zend/zend_dtrace.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ ZEND_API void dtrace_execute(zend_op_array *op_array TSRMLS_DC)
8383
}
8484
}
8585

86-
ZEND_API void dtrace_execute_internal(zend_execute_data *execute_data_ptr, int return_value_used TSRMLS_DC)
86+
ZEND_API void dtrace_execute_internal(zend_execute_data *execute_data_ptr, zend_fcall_info *fci, int return_value_used TSRMLS_DC)
8787
{
8888
int lineno;
8989
char *filename;
@@ -96,7 +96,7 @@ ZEND_API void dtrace_execute_internal(zend_execute_data *execute_data_ptr, int r
9696
DTRACE_EXECUTE_ENTRY(filename, lineno);
9797
}
9898

99-
execute_internal(execute_data_ptr, return_value_used TSRMLS_CC);
99+
execute_internal(execute_data_ptr, fci, return_value_used TSRMLS_CC);
100100

101101
if (DTRACE_EXECUTE_RETURN_ENABLED()) {
102102
DTRACE_EXECUTE_RETURN(filename, lineno);

Zend/zend_dtrace.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ extern "C" {
3232
#ifdef HAVE_DTRACE
3333
ZEND_API zend_op_array *(*zend_dtrace_compile_file)(zend_file_handle *file_handle, int type TSRMLS_DC);
3434
ZEND_API void (*zend_dtrace_execute)(zend_op_array *op_array TSRMLS_DC);
35-
ZEND_API void (*zend_dtrace_execute_internal)(zend_execute_data *execute_data_ptr, int return_value_used TSRMLS_DC);
35+
ZEND_API void (*zend_dtrace_execute_internal)(zend_execute_data *execute_data_ptr, zend_fcall_info *fci, int return_value_used TSRMLS_DC);
3636

3737
ZEND_API zend_op_array *dtrace_compile_file(zend_file_handle *file_handle, int type TSRMLS_DC);
3838
ZEND_API void dtrace_execute(zend_op_array *op_array TSRMLS_DC);
39-
ZEND_API void dtrace_execute_internal(zend_execute_data *execute_data_ptr, int return_value_used TSRMLS_DC);
39+
ZEND_API void dtrace_execute_internal(zend_execute_data *execute_data_ptr, zend_fcall_info *fci, int return_value_used TSRMLS_DC);
4040
#include <zend_dtrace_gen.h>
4141

4242
#endif /* HAVE_DTRACE */

Zend/zend_execute.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,10 +1474,18 @@ static int zend_check_symbol(zval **pz TSRMLS_DC)
14741474

14751475
ZEND_API opcode_handler_t *zend_opcode_handlers;
14761476

1477-
ZEND_API void execute_internal(zend_execute_data *execute_data_ptr, int return_value_used TSRMLS_DC)
1477+
ZEND_API void execute_internal(zend_execute_data *execute_data_ptr, zend_fcall_info *fci, int return_value_used TSRMLS_DC)
14781478
{
1479-
zval **return_value_ptr = &(*(temp_variable *)((char *) execute_data_ptr->Ts + execute_data_ptr->opline->result.var)).var.ptr;
1480-
((zend_internal_function *) execute_data_ptr->function_state.function)->handler(execute_data_ptr->opline->extended_value, *return_value_ptr, (execute_data_ptr->function_state.function->common.fn_flags & ZEND_ACC_RETURN_REFERENCE)?return_value_ptr:NULL, execute_data_ptr->object, return_value_used TSRMLS_CC);
1479+
if(fci != NULL) {
1480+
((zend_internal_function *) execute_data_ptr->function_state.function)->handler(fci->param_count,
1481+
*fci->retval_ptr_ptr, fci->retval_ptr_ptr, fci->object_ptr, 1 TSRMLS_CC);
1482+
1483+
} else {
1484+
zval **return_value_ptr = &(*(temp_variable *)((char *) execute_data_ptr->Ts + execute_data_ptr->opline->result.var)).var.ptr;
1485+
((zend_internal_function *) execute_data_ptr->function_state.function)->handler(execute_data_ptr->opline->extended_value, *return_value_ptr,
1486+
(execute_data_ptr->function_state.function->common.fn_flags & ZEND_ACC_RETURN_REFERENCE)?return_value_ptr:NULL,
1487+
execute_data_ptr->object, return_value_used TSRMLS_CC);
1488+
}
14811489
}
14821490

14831491
#define ZEND_VM_NEXT_OPCODE() \
@@ -1512,7 +1520,7 @@ ZEND_API int zend_set_user_opcode_handler(zend_uchar opcode, user_opcode_handler
15121520
{
15131521
if (opcode != ZEND_USER_OPCODE) {
15141522
if (handler == NULL) {
1515-
/* restore the original handler */
1523+
/* restore the original handler */
15161524
zend_user_opcodes[opcode] = opcode;
15171525
} else {
15181526
zend_user_opcodes[opcode] = ZEND_USER_OPCODE;

Zend/zend_execute.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
| Copyright (c) 1998-2012 Zend Technologies Ltd. (http://www.zend.com) |
66
+----------------------------------------------------------------------+
77
| This source file is subject to version 2.00 of the Zend license, |
8-
| that is bundled with this package in the file LICENSE, and is |
8+
| that is bundled with this package in the file LICENSE, and is |
99
| available through the world-wide-web at the following url: |
1010
| http://www.zend.com/license/2_00.txt. |
1111
| If you did not receive a copy of the Zend license and are unable to |
@@ -49,14 +49,15 @@ typedef union _temp_variable {
4949

5050

5151
BEGIN_EXTERN_C()
52+
struct _zend_fcall_info;
5253
ZEND_API extern void (*zend_execute)(zend_op_array *op_array TSRMLS_DC);
53-
ZEND_API extern void (*zend_execute_internal)(zend_execute_data *execute_data_ptr, int return_value_used TSRMLS_DC);
54+
ZEND_API extern void (*zend_execute_internal)(zend_execute_data *execute_data_ptr, struct _zend_fcall_info *fci, int return_value_used TSRMLS_DC);
5455

5556
void init_executor(TSRMLS_D);
5657
void shutdown_executor(TSRMLS_D);
5758
void shutdown_destructors(TSRMLS_D);
5859
ZEND_API void execute(zend_op_array *op_array TSRMLS_DC);
59-
ZEND_API void execute_internal(zend_execute_data *execute_data_ptr, int return_value_used TSRMLS_DC);
60+
ZEND_API void execute_internal(zend_execute_data *execute_data_ptr, struct _zend_fcall_info *fci, int return_value_used TSRMLS_DC);
6061
ZEND_API int zend_is_true(zval *op);
6162
#define safe_free_zval_ptr(p) safe_free_zval_ptr_rel(p ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC)
6263
static zend_always_inline void safe_free_zval_ptr_rel(zval *p ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
@@ -270,7 +271,7 @@ static zend_always_inline void *zend_vm_stack_alloc(size_t size TSRMLS_DC)
270271
}
271272

272273
static zend_always_inline void zend_vm_stack_free_int(void *ptr TSRMLS_DC)
273-
{
274+
{
274275
if (UNEXPECTED(ZEND_VM_STACK_ELEMETS(EG(argument_stack)) == (void**)ptr)) {
275276
zend_vm_stack p = EG(argument_stack);
276277

@@ -282,7 +283,7 @@ static zend_always_inline void zend_vm_stack_free_int(void *ptr TSRMLS_DC)
282283
}
283284

284285
static zend_always_inline void zend_vm_stack_free(void *ptr TSRMLS_DC)
285-
{
286+
{
286287
if (UNEXPECTED(ZEND_VM_STACK_ELEMETS(EG(argument_stack)) == (void**)ptr)) {
287288
zend_vm_stack p = EG(argument_stack);
288289

@@ -302,7 +303,7 @@ static zend_always_inline void zend_vm_stack_free(void *ptr TSRMLS_DC)
302303
static zend_always_inline void** zend_vm_stack_push_args(int count TSRMLS_DC)
303304
{
304305

305-
if (UNEXPECTED(EG(argument_stack)->top - ZEND_VM_STACK_ELEMETS(EG(argument_stack)) < count) ||
306+
if (UNEXPECTED(EG(argument_stack)->top - ZEND_VM_STACK_ELEMETS(EG(argument_stack)) < count) ||
306307
UNEXPECTED(EG(argument_stack)->top == EG(argument_stack)->end)) {
307308
zend_vm_stack p = EG(argument_stack);
308309

Zend/zend_execute_API.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
#endif
3939

4040
ZEND_API void (*zend_execute)(zend_op_array *op_array TSRMLS_DC);
41-
ZEND_API void (*zend_execute_internal)(zend_execute_data *execute_data_ptr, int return_value_used TSRMLS_DC);
41+
ZEND_API void (*zend_execute_internal)(zend_execute_data *execute_data_ptr, zend_fcall_info *fci, int return_value_used TSRMLS_DC);
4242

4343
/* true globals */
4444
ZEND_API const zend_fcall_info empty_fcall_info = { 0, NULL, NULL, NULL, NULL, 0, NULL, NULL, 0 };
@@ -977,15 +977,12 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS
977977
if (EX(function_state).function->common.scope) {
978978
EG(scope) = EX(function_state).function->common.scope;
979979
}
980-
981-
if (!zend_execute_internal) {
980+
if(EXPECTED(zend_execute_internal == NULL)) {
982981
/* saves one function call if zend_execute_internal is not used */
983982
((zend_internal_function *) EX(function_state).function)->handler(fci->param_count, *fci->retval_ptr_ptr, fci->retval_ptr_ptr, fci->object_ptr, 1 TSRMLS_CC);
984983
} else {
985-
zend_execute_internal(&execute_data, 1 TSRMLS_CC);
984+
zend_execute_internal(&execute_data, fci, 1 TSRMLS_CC);
986985
}
987-
988-
989986
/* We shouldn't fix bad extensions here,
990987
because it can break proper ones (Bug #34045)
991988
if (!EX(function_state).function->common.return_reference)

Zend/zend_vm_def.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,7 @@ ZEND_VM_HELPER(zend_do_fcall_common_helper, ANY, ANY)
20282028
/* saves one function call if zend_execute_internal is not used */
20292029
fbc->internal_function.handler(opline->extended_value, ret->var.ptr, (fbc->common.fn_flags & ZEND_ACC_RETURN_REFERENCE) ? &ret->var.ptr : NULL, EX(object), RETURN_VALUE_USED(opline) TSRMLS_CC);
20302030
} else {
2031-
zend_execute_internal(EXECUTE_DATA, RETURN_VALUE_USED(opline) TSRMLS_CC);
2031+
zend_execute_internal(EXECUTE_DATA, NULL, RETURN_VALUE_USED(opline) TSRMLS_CC);
20322032
}
20332033

20342034
if (!RETURN_VALUE_USED(opline)) {
@@ -2151,7 +2151,7 @@ ZEND_VM_HELPER_EX(zend_finally_handler_leaving, ANY, ANY, int type)
21512151
for (i=0; i<EX(op_array)->last_try_catch; i++) {
21522152
if (EX(op_array)->try_catch_array[i].try_op > op_num) {
21532153
break;
2154-
}
2154+
}
21552155
if (op_num < EX(op_array)->try_catch_array[i].finally_op) {
21562156
finally_op_num = EX(op_array)->try_catch_array[i].finally_op;
21572157
}
@@ -2163,7 +2163,7 @@ ZEND_VM_HELPER_EX(zend_finally_handler_leaving, ANY, ANY, int type)
21632163
for (i=0; i<EX(op_array)->last_try_catch; i++) {
21642164
if (EX(op_array)->try_catch_array[i].try_op > op_num) {
21652165
break;
2166-
}
2166+
}
21672167
if (op_num < EX(op_array)->try_catch_array[i].finally_op) {
21682168
finally_op_num = EX(op_array)->try_catch_array[i].finally_op;
21692169
}
@@ -2207,8 +2207,8 @@ ZEND_VM_HELPER_EX(zend_finally_handler_leaving, ANY, ANY, int type)
22072207
for (i=0; i<EG(active_op_array)->last_try_catch; i++) {
22082208
if (EG(active_op_array)->try_catch_array[i].try_op > op_num) {
22092209
break;
2210-
}
2211-
if (op_num < EG(active_op_array)->try_catch_array[i].finally_op
2210+
}
2211+
if (op_num < EG(active_op_array)->try_catch_array[i].finally_op
22122212
&& (EX(leaving_dest) < EG(active_op_array)->try_catch_array[i].try_op
22132213
|| EX(leaving_dest) >= EG(active_op_array)->try_catch_array[i].finally_end)) {
22142214
finally_op_num = EG(active_op_array)->try_catch_array[i].finally_op;
@@ -5145,7 +5145,7 @@ ZEND_VM_HANDLER(149, ZEND_HANDLE_EXCEPTION, ANY, ANY)
51455145
if (EG(active_op_array)->try_catch_array[i].try_op > op_num) {
51465146
/* further blocks will not be relevant... */
51475147
break;
5148-
}
5148+
}
51495149
if (op_num < EG(active_op_array)->try_catch_array[i].catch_op) {
51505150
catch_op_num = EX(op_array)->try_catch_array[i].catch_op;
51515151
catched = i + 1;
@@ -5221,7 +5221,7 @@ ZEND_VM_HANDLER(149, ZEND_HANDLE_EXCEPTION, ANY, ANY)
52215221
ZEND_VM_SET_OPCODE(&EX(op_array)->opcodes[finally_op_num]);
52225222
ZEND_VM_CONTINUE();
52235223
}
5224-
} else if (catched) {
5224+
} else if (catched) {
52255225
EX(leaving) = 0;
52265226
ZEND_VM_SET_OPCODE(&EX(op_array)->opcodes[catch_op_num]);
52275227
ZEND_VM_CONTINUE();

Zend/zend_vm_execute.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ static int ZEND_FASTCALL zend_do_fcall_common_helper_SPEC(ZEND_OPCODE_HANDLER_AR
615615
/* saves one function call if zend_execute_internal is not used */
616616
fbc->internal_function.handler(opline->extended_value, ret->var.ptr, (fbc->common.fn_flags & ZEND_ACC_RETURN_REFERENCE) ? &ret->var.ptr : NULL, EX(object), RETURN_VALUE_USED(opline) TSRMLS_CC);
617617
} else {
618-
zend_execute_internal(execute_data, RETURN_VALUE_USED(opline) TSRMLS_CC);
618+
zend_execute_internal(execute_data, NULL, RETURN_VALUE_USED(opline) TSRMLS_CC);
619619
}
620620

621621
if (!RETURN_VALUE_USED(opline)) {

0 commit comments

Comments
 (0)