Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does apache hold offsets into memory where php-cli holds virtual memory addresses?

I'm debugging php. When looking at a place in memory where I know a pointer to an address is, I see the pointer - for example 22810408 (0x08048122) - this is when using the CLI version of php.

HOWEVER, when I'm using apache2 and attempting to do the same thing, I don't see a pointer to the real address. Instead, I see an offset from the ELF header that when added to the address of the ELF header, gives me the "real" address. For example, if the "real" address was 0x08048122, and the ELF header was at 0x08048000 then I would see 22010000 (0x122) at this same position.

The problem arises when I try to figure out the "real" address of something that is on the stack. The "real" address is supposed to be 0xbfccxxxx, but when adding the number I find to the ELF header, things just don't add up! I get all the wrong addresses.

I've already tried googling for a long time, but I am really not sure how to word this correctly, or what to search for.

So, what I'm essentially looking for is more information on WHY Apache has an offset instead of a real memory address, and how this all relates to addresses on the stack. Could anyone give me any pointers to material that might clarify?

like image 825
optional Avatar asked Nov 05 '22 07:11

optional


1 Answers

Apache utilizes mod_php, a dynamically linked shared object library (.so). See what is mod_php?. Where as PHP-CLI is a front-end to the zend API (php executable).

mod_php on its' side loads and utilizes the zend API to parse and return PHP files to apache. As you can see there's a lot of indirection here. This method works better and faster than letting apache use PHP as a daemon or similar.

When debugging PHP you normally work on a much higher level than this, because even if you get the offsets right; PHP datatypes are not 1:1 those of C (because of PHP's duck typing) and for associative arrays and objects the representation in memory is very different than that of a C object.

I would recommend you to use a specialized PHP debugger to debug PHP applications.

like image 102
thwd Avatar answered Nov 10 '22 17:11

thwd