I'm in the process of adding IActiveScriptError support to my active script sapi. The way the sapi works is by compiling "scriptlets" into zend_op_arrays and then, at a later time, uses zend_execute to execute them.
This works perfectly when the script has no errors :-)
If I deliberately add a scriplet that tries to call an undefined
function,
the code is compiled correctly, but when it is executed, the engine
triggers
a "call to undefined function error" (that's fine), but then I end up
with a
segfault:
zend_execute.c:
do_fcall_common:
{
zval **original_return_value;
int return_value_used = RETURN_VALUE_USED(EX(opline));
zend_ptr_stack_n_push(&EG(argument_stack), 2,
(void *) EX(opline)->extended_value, NULL);
EX(Ts)[EX(opline)->result.u.var].var.ptr_ptr =
&EX(Ts)[EX(opline)->result.u.var].var.ptr;
// Segfault on this next line
if (EX(function_state).function->type==ZEND_INTERNAL_FUNCTION) {
I suspect this probably has something to do with the way that the
execution
environment is setup. The code I'm using is this:
zval *retval_ptr = NULL;
zend_op_array *active_op_array = EG(active_op_array);
zend_function_state *function_state_ptr = EG(function_state_ptr);
zval **return_value_ptr_ptr =
EG(return_value_ptr_ptr);
zend_op **opline_ptr = EG(opline_ptr);
EG(return_value_ptr_ptr) = &retval_ptr;
EG(active_op_array) = frag->opcodes;
EG(no_extensions) = 1;
zend_execute(frag->opcodes TSRMLS_CC);
EG(no_extensions) = 0;
EG(opline_ptr) = opline_ptr;
EG(active_op_array) = active_op_array;
EG(function_state_ptr) = function_state_ptr;
EG(return_value_ptr_ptr) = return_value_ptr_ptr;
if (retval_ptr) {
zval_ptr_dtor(&retval_ptr);
}
That works fine if there are no errors or calls to undefined functions;
it's just when there are errors that I run into problems.
Could this error also be attributed to the way that the op_array was
compiled? I'm using compile_string to do that part.
Is there anything in particular that I should do to make this work?
The sapi framework is initialized in a similar way to the ISAPI sapi,
in case that helps.
--Wez.
smime.p7s
Description: application/pkcs7-signature
