Skip to content

Commit 20d1fb8

Browse files
committed
Try to figure out how to free arguments
1 parent 1437b07 commit 20d1fb8

File tree

2 files changed

+134
-0
lines changed

2 files changed

+134
-0
lines changed

Zend/zend_vm_def.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7871,6 +7871,73 @@ ZEND_VM_HANDLER(149, ZEND_HANDLE_EXCEPTION, ANY, ANY)
78717871
if (!is_in_silence_live_range(EX(func)->op_array, throw_op_num)
78727872
|| !instanceof_function(zend_ce_exception, EG(exception)->ce)) {
78737873
cleanup_unfinished_calls(execute_data, throw_op_num);
7874+
} else if (UNEXPECTED(EX(call))) {
7875+
zend_execute_data *call = EX(call);
7876+
zend_op *opline = EX(func)->op_array.opcodes + throw_op_num;
7877+
bool do_exit = false;
7878+
unsigned int level = 0;
7879+
7880+
printf("Opcode %d\n", opline->opcode);
7881+
/* Decrement opline */
7882+
opline--;
7883+
7884+
do {
7885+
switch (opline->opcode) {
7886+
case ZEND_DO_FCALL:
7887+
case ZEND_DO_ICALL:
7888+
case ZEND_DO_UCALL:
7889+
case ZEND_DO_FCALL_BY_NAME:
7890+
level++;
7891+
break;
7892+
case ZEND_INIT_FCALL:
7893+
case ZEND_INIT_FCALL_BY_NAME:
7894+
case ZEND_INIT_NS_FCALL_BY_NAME:
7895+
case ZEND_INIT_DYNAMIC_CALL:
7896+
case ZEND_INIT_USER_CALL:
7897+
case ZEND_INIT_METHOD_CALL:
7898+
case ZEND_INIT_STATIC_METHOD_CALL:
7899+
case ZEND_NEW:
7900+
if (level == 0) {
7901+
ZEND_CALL_NUM_ARGS(call) = 0;
7902+
do_exit = true;
7903+
}
7904+
level--;
7905+
break;
7906+
case ZEND_SEND_VAL:
7907+
case ZEND_SEND_VAL_EX:
7908+
case ZEND_SEND_VAR:
7909+
case ZEND_SEND_VAR_EX:
7910+
case ZEND_SEND_FUNC_ARG:
7911+
case ZEND_SEND_REF:
7912+
case ZEND_SEND_VAR_NO_REF:
7913+
case ZEND_SEND_VAR_NO_REF_EX:
7914+
case ZEND_SEND_USER:
7915+
if (level == 0) {
7916+
/* For named args, the number of arguments is up to date. */
7917+
if (opline->op2_type != IS_CONST) {
7918+
ZEND_CALL_NUM_ARGS(call) = opline->op2.num;
7919+
}
7920+
do_exit = true;
7921+
}
7922+
break;
7923+
case ZEND_SEND_ARRAY:
7924+
case ZEND_SEND_UNPACK:
7925+
case ZEND_CHECK_UNDEF_ARGS:
7926+
if (level == 0) {
7927+
do_exit = true;
7928+
}
7929+
break;
7930+
}
7931+
if (!do_exit) {
7932+
opline--;
7933+
}
7934+
} while (!do_exit);
7935+
7936+
//zend_vm_stack_free_args(call);
7937+
//zend_vm_stack_free_extra_args(call);
7938+
//EX(call) = call->prev_execute_data;
7939+
//zend_vm_stack_free_call_frame(call);
7940+
//call = EX(call);
78747941
}
78757942

78767943
if (throw_op->result_type & (IS_VAR | IS_TMP_VAR)) {

Zend/zend_vm_execute.h

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3147,6 +3147,73 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_HANDLE_EXCEPTION_SPEC_HANDLER(
31473147
if (!is_in_silence_live_range(EX(func)->op_array, throw_op_num)
31483148
|| !instanceof_function(zend_ce_exception, EG(exception)->ce)) {
31493149
cleanup_unfinished_calls(execute_data, throw_op_num);
3150+
} else if (UNEXPECTED(EX(call))) {
3151+
zend_execute_data *call = EX(call);
3152+
zend_op *opline = EX(func)->op_array.opcodes + throw_op_num;
3153+
bool do_exit = false;
3154+
unsigned int level = 0;
3155+
3156+
printf("Opcode %d\n", opline->opcode);
3157+
/* Decrement opline */
3158+
opline--;
3159+
3160+
do {
3161+
switch (opline->opcode) {
3162+
case ZEND_DO_FCALL:
3163+
case ZEND_DO_ICALL:
3164+
case ZEND_DO_UCALL:
3165+
case ZEND_DO_FCALL_BY_NAME:
3166+
level++;
3167+
break;
3168+
case ZEND_INIT_FCALL:
3169+
case ZEND_INIT_FCALL_BY_NAME:
3170+
case ZEND_INIT_NS_FCALL_BY_NAME:
3171+
case ZEND_INIT_DYNAMIC_CALL:
3172+
case ZEND_INIT_USER_CALL:
3173+
case ZEND_INIT_METHOD_CALL:
3174+
case ZEND_INIT_STATIC_METHOD_CALL:
3175+
case ZEND_NEW:
3176+
if (level == 0) {
3177+
ZEND_CALL_NUM_ARGS(call) = 0;
3178+
do_exit = true;
3179+
}
3180+
level--;
3181+
break;
3182+
case ZEND_SEND_VAL:
3183+
case ZEND_SEND_VAL_EX:
3184+
case ZEND_SEND_VAR:
3185+
case ZEND_SEND_VAR_EX:
3186+
case ZEND_SEND_FUNC_ARG:
3187+
case ZEND_SEND_REF:
3188+
case ZEND_SEND_VAR_NO_REF:
3189+
case ZEND_SEND_VAR_NO_REF_EX:
3190+
case ZEND_SEND_USER:
3191+
if (level == 0) {
3192+
/* For named args, the number of arguments is up to date. */
3193+
if (opline->op2_type != IS_CONST) {
3194+
ZEND_CALL_NUM_ARGS(call) = opline->op2.num;
3195+
}
3196+
do_exit = true;
3197+
}
3198+
break;
3199+
case ZEND_SEND_ARRAY:
3200+
case ZEND_SEND_UNPACK:
3201+
case ZEND_CHECK_UNDEF_ARGS:
3202+
if (level == 0) {
3203+
do_exit = true;
3204+
}
3205+
break;
3206+
}
3207+
if (!do_exit) {
3208+
opline--;
3209+
}
3210+
} while (!do_exit);
3211+
3212+
//zend_vm_stack_free_args(call);
3213+
//zend_vm_stack_free_extra_args(call);
3214+
//EX(call) = call->prev_execute_data;
3215+
//zend_vm_stack_free_call_frame(call);
3216+
//call = EX(call);
31503217
}
31513218

31523219
if (throw_op->result_type & (IS_VAR | IS_TMP_VAR)) {

0 commit comments

Comments
 (0)