Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71252 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48494 invoked from network); 18 Jan 2014 20:12:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jan 2014 20:12:54 -0000 Authentication-Results: pb1.pair.com header.from=julienpauli@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=julienpauli@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.176 as permitted sender) X-PHP-List-Original-Sender: julienpauli@gmail.com X-Host-Fingerprint: 209.85.220.176 mail-vc0-f176.google.com Received: from [209.85.220.176] ([209.85.220.176:57713] helo=mail-vc0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D7/50-46720-540EAD25 for ; Sat, 18 Jan 2014 15:12:54 -0500 Received: by mail-vc0-f176.google.com with SMTP id la4so2147301vcb.35 for ; Sat, 18 Jan 2014 12:12:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=QHw/nhl/K3otHKmiiEBKA6wOqK71xiGqUh3Q3+yvG8k=; b=SFEJ6T+47woZmMyQDHSDtdjwLkstJ40jg2N8TkJEqy47qpxzwDyf39/QaY5QZuAUmu cXGiE4t+EG+FIi/qjXYF4bjJZojZ5j/maDzeQh7Km2Tq07+Z63Nx7zsLsLN+egoStM6/ uKjjBLKgcahvngjEoCG5U5e6HE+nD6dqSDNLs4m1RDpJug+vFiDlxZj7aezXSKbjQB4X ypqLApqY/iy1WTeEwxNjop0TX2Q5i7N0lOIk5K/v0r/kYGWBXL2oHNnEDjXGtUlSuHdm rI+LoZMLka60ffEGo7q9rJjN+3G2keme8S6fuzp6mkutskLJplryb/8ahIA7ZJEBV/ww Ga9A== X-Received: by 10.220.164.80 with SMTP id d16mr4968723vcy.15.1390075971381; Sat, 18 Jan 2014 12:12:51 -0800 (PST) MIME-Version: 1.0 Sender: julienpauli@gmail.com Received: by 10.220.158.206 with HTTP; Sat, 18 Jan 2014 12:12:11 -0800 (PST) In-Reply-To: References: Date: Sat, 18 Jan 2014 21:12:11 +0100 X-Google-Sender-Auth: TwmHYs4yg5ir909b-TpDibZ3nPE Message-ID: To: Lin Yo-An Cc: Daniel Lowrey , "internals@lists.php.net" Content-Type: text/plain; charset=Big5 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Re: How to create Persistent zval? From: jpauli@php.net (Julien Pauli) On Sat, Jan 18, 2014 at 9:01 PM, Lin Yo-An wrote= : > 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 =A9=F3 2014=A6~1=A4=EB19=A4=E9=ACP= =B4=C1=A4=E9=BCg=B9D=A1G > >> >> >> Daniel Lowrey > 'rdlowrey@php.net');>> =A9=F3 2014=A6~1=A4=EB19=A4=E9=ACP=B4=C1=A4=E9=BC= g=B9D=A1G >> >>> >> 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 conte= xt. >>> >> >>> >> 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 free= d >>> zval >>> >> address and it makes php segmentationfault. I guess zval is allocate= d >>> 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 yo= u >>> > 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 canno= t >>> pemalloc anything and pass it into the engine safely. >>> >>> You don't want to store a persistent zval, you want to store a persiste= nt >>> resource entry, which should be allocated with pemalloc(size, 1) >>> >>> The reason for this is when cleaning up, the engine has no means by whi= ch >>> to tell if a zval has been pemalloc or emalloc'd, zval_ptr_dtor works t= he >>> 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 serial= ize >> 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