cedricliang
cedricliang

Reputation: 352

PHP extension: Segmentation fault when returning from a function

I am developing a php extension and encounters a problem. In my extension, i defined a function which parse parameters from userspace and pass them to another function in static library.

But when my functions ends, it pops out the following error: "Cannot access memory at address 0x5 Segmentation fault(core dumped)"

I tried to solve it using gdb and print the following frame information:

0x0852dbe3 in zend_do_fcall_common_helper_SPEC (
    execute_data=<error reading variable: Cannot access memory at address 0xffffffc5>, 
    tsrm_ls=<error reading variable: Cannot access memory at address 0xffffffc1>) at /home/ted/php-5.5.6/Zend/zend_vm_execute.h:550

After i type "info frame" command, the following information comes out:

Stack level 0, frame at 0x9:
 eip = 0x852dbe3 in zend_do_fcall_common_helper_SPEC
    (/home/ted/php-5.5.6/Zend/zend_vm_execute.h:550); saved eip Cannot access memory at address 0x5

I have stuck in this for one day.. Could anyone help?

Upvotes: 0

Views: 932

Answers (1)

cedricliang
cedricliang

Reputation: 352

I have solved this problem.. It's caused by a error(maybe) which i don't quite understand. In my php code, i call a function like this:

$object->object_function($a,$b,$c,1);

In my php extension, i parse all these parameters:

if(zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sral",&string1,&strlen1,&resource,&array1 ,&intVal)     == FAILURE)

The problem is, i can't use 1 in php code. Instead, i should use:

$d = 1; 
$object->object_function($a,$b,$c,$d);

I suppose this is because of my poor understanding of php core. Directly passing 1 into the extension function will actually not give the value i want.

Upvotes: 1

Related Questions