Hello,
I am trying to store a zval object into the persistent list in zend VM.
(Using EG(persistent_list) and zend_rscd_list_entry)Which works fine if I store/fetch the zval in the same request context.
But it seems that zend engine cleans up the zval object after the
request,
when the next request comes, the fetched list entry points to a freed
zval
address and it makes php segmentationfault. I guess zval is allocated by
emalloc, so I cant keep it cross requests?
For persistent alloc, you should use pemalloc() , which is just a
wrapper leading to libc's malloc.
If you use emalloc() , the Zend Memory Manager will free the storage
at the end of the request, thus leading to use-after-free crash if you
reuse your pointer on a next request.
--- Disclaimer ---
I'm passing this along; Joe is having technical difficulties and asked for
help sending this to the list. I provide no warranties or refunds ;)
All zvals passed into the engine must be allocated by the mm, you cannot
pemalloc anything and pass it into the engine safely.
You don't want to store a persistent zval, you want to store a persistent
resource entry, which should be allocated with pemalloc(size, 1)
The reason for this is when cleaning up, the engine has no means by which
to tell if a zval has been pemalloc or emalloc'd, zval_ptr_dtor works the
same for everything.
Cheers
Joe
Daniel Lowrey rdlowrey@php.net 於 2014年1月19日星期日寫道:
Hello,
I am trying to store a zval object into the persistent list in zend VM.
(Using EG(persistent_list) and zend_rscd_list_entry)Which works fine if I store/fetch the zval in the same request context.
But it seems that zend engine cleans up the zval object after the
request,
when the next request comes, the fetched list entry points to a freed
zval
address and it makes php segmentationfault. I guess zval is allocated by
emalloc, so I cant keep it cross requests?For persistent alloc, you should use pemalloc() , which is just a
wrapper leading to libc's malloc.
If you use emalloc() , the Zend Memory Manager will free the storage
at the end of the request, thus leading to use-after-free crash if you
reuse your pointer on a next request.--- Disclaimer ---
I'm passing this along; Joe is having technical difficulties and asked for
help sending this to the list. I provide no warranties or refunds ;)All zvals passed into the engine must be allocated by the mm, you cannot
pemalloc anything and pass it into the engine safely.You don't want to store a persistent zval, you want to store a persistent
resource entry, which should be allocated with pemalloc(size, 1)The reason for this is when cleaning up, the engine has no means by which
to tell if a zval has been pemalloc or emalloc'd, zval_ptr_dtor works the
same for everything.
Thank you so much! That is what i was guessing.. - ref cnt and pemalloc
does not work for persistent zval.
And zend engine cleans up zvals at the end of request no matter the ref cnt
is?
so zval is not persistent, then is HashTable persistent?
It's because I need to store a zval object which has several properties.
Is there a way to do make the object persistent? Or do i need to serialize
it just like apc?
Cheers
Joe
--
Best Regards,
Yo-An Lin
By the way, Is this the reason of date ext always check the global
HashTable and re-initialize the tzdata in every request?
Lin Yo-An cornelius.howl@gmail.com 於 2014年1月19日星期日寫道:
Daniel Lowrey <rdlowrey@php.net <javascript:_e({}, 'cvml',
'rdlowrey@php.net');>> 於 2014年1月19日星期日寫道:Hello,
I am trying to store a zval object into the persistent list in zend VM.
(Using EG(persistent_list) and zend_rscd_list_entry)Which works fine if I store/fetch the zval in the same request context.
But it seems that zend engine cleans up the zval object after the
request,
when the next request comes, the fetched list entry points to a freed
zval
address and it makes php segmentationfault. I guess zval is allocated
by
emalloc, so I cant keep it cross requests?For persistent alloc, you should use pemalloc() , which is just a
wrapper leading to libc's malloc.
If you use emalloc() , the Zend Memory Manager will free the storage
at the end of the request, thus leading to use-after-free crash if you
reuse your pointer on a next request.--- Disclaimer ---
I'm passing this along; Joe is having technical difficulties and asked for
help sending this to the list. I provide no warranties or refunds ;)All zvals passed into the engine must be allocated by the mm, you cannot
pemalloc anything and pass it into the engine safely.You don't want to store a persistent zval, you want to store a persistent
resource entry, which should be allocated with pemalloc(size, 1)The reason for this is when cleaning up, the engine has no means by which
to tell if a zval has been pemalloc or emalloc'd, zval_ptr_dtor works the
same for everything.Thank you so much! That is what i was guessing.. - ref cnt and pemalloc
does not work for persistent zval.And zend engine cleans up zvals at the end of request no matter the ref
cnt is?so zval is not persistent, then is HashTable persistent?
It's because I need to store a zval object which has several properties.
Is there a way to do make the object persistent? Or do i need to serialize
it just like apc?Cheers
Joe--
Best Regards,Yo-An Lin
--
Sent from Gmail Mobile
By the way, Is this the reason of date ext always check the global
HashTable and re-initialize the tzdata in every request?Lin Yo-An cornelius.howl@gmail.com 於 2014年1月19日星期日寫道:
Daniel Lowrey <rdlowrey@php.net <javascript:_e({}, 'cvml',
'rdlowrey@php.net');>> 於 2014年1月19日星期日寫道:Hello,
I am trying to store a zval object into the persistent list in zend VM.
(Using EG(persistent_list) and zend_rscd_list_entry)Which works fine if I store/fetch the zval in the same request context.
But it seems that zend engine cleans up the zval object after the
request,
when the next request comes, the fetched list entry points to a freed
zval
address and it makes php segmentationfault. I guess zval is allocated
by
emalloc, so I cant keep it cross requests?For persistent alloc, you should use pemalloc() , which is just a
wrapper leading to libc's malloc.
If you use emalloc() , the Zend Memory Manager will free the storage
at the end of the request, thus leading to use-after-free crash if you
reuse your pointer on a next request.--- Disclaimer ---
I'm passing this along; Joe is having technical difficulties and asked for
help sending this to the list. I provide no warranties or refunds ;)All zvals passed into the engine must be allocated by the mm, you cannot
pemalloc anything and pass it into the engine safely.You don't want to store a persistent zval, you want to store a persistent
resource entry, which should be allocated with pemalloc(size, 1)The reason for this is when cleaning up, the engine has no means by which
to tell if a zval has been pemalloc or emalloc'd, zval_ptr_dtor works the
same for everything.Thank you so much! That is what i was guessing.. - ref cnt and pemalloc
does not work for persistent zval.And zend engine cleans up zvals at the end of request no matter the ref
cnt is?so zval is not persistent, then is HashTable persistent?
It's because I need to store a zval object which has several properties.
Is there a way to do make the object persistent? Or do i need to serialize
it just like apc?
Read the shutdown sequence, and you will figure it out by yourself.
Non-persistent pointers are freed at request shutdown.
http://lxr.php.net/xref/PHP_5_5/Zend/zend_alloc.c#1601
Julien
Hi!
And zend engine cleans up zvals at the end of request no matter the ref cnt
is?
Yes and no. Zend Engine will clean up all emalloc-ed memory. It also
will clean up all symbol tables, objects, resources, etc. that are
stored in system tables. However, if you just create a zval structure
with persistent pemalloc, it would not be cleaned - but you could not
put this zval into any object, structure, etc., and passing it to engine
functions may be dangerous too. If you're knowing what you're doing, you
can pull it off (opcache sometimes does stuff like that IIRC) but you
need to be extremely careful so that the engine does not store your zval
and does not try to free it.
so zval is not persistent, then is HashTable persistent?
It's because I need to store a zval object which has several properties.
Is there a way to do make the object persistent? Or do i need to serialize
it just like apc?
Serializing it one way or another (doesn't have to be full serialize -
serialize is pretty complex since it has to account for all corner
cases, you can have something much simpler and use serialize handlers or
custom code) may be the simplest way. It is possible to also keep
objects in memory as is if you're very careful but it is not as simple
to do it right.
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227