Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:71250 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 45174 invoked from network); 18 Jan 2014 19:52:51 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jan 2014 19:52:51 -0000 Authentication-Results: pb1.pair.com header.from=cornelius.howl@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=cornelius.howl@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.176 as permitted sender) X-PHP-List-Original-Sender: cornelius.howl@gmail.com X-Host-Fingerprint: 209.85.213.176 mail-ig0-f176.google.com Received: from [209.85.213.176] ([209.85.213.176:44745] helo=mail-ig0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 32/81-36499-29BDAD25 for ; Sat, 18 Jan 2014 14:52:51 -0500 Received: by mail-ig0-f176.google.com with SMTP id j1so4572798iga.3 for ; Sat, 18 Jan 2014 11:52:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=cu1nXnmoqyY5ox+MaOWKA4k4jbc4EHqUmfFPAKbsPtQ=; b=M5/SCuegFxAyboI9ZoU7FA2ogeuxvcpUR8wMwjlFagXE7Q936wdwqSCIxZzWxa7Nk6 oocMgEQn1UFp6HDDudXprrqGZ5ckVYZrsWc7HnuWfl8Qnp99Gb8ayfzfHQKiXvIpBmbK 71yVzD8CdCrwjVdhxGCnXYJPX0NHFml0K2mmYlbqTNeJPEmCFrlt9swQsA5Nx2nM/oPW 4vlXh4B6Qj7h7twBtJQ/v39IiG+cE0BkrDDzhfUxzkMX9UTBXhw2QWxHARkRC72+J1c7 ulYUEc77jxK3FzxW6lkFapdBWHWo9KYx20vWNHFbxrDAHeHhGQKXO+V7OSHGn47clsww xHQg== MIME-Version: 1.0 X-Received: by 10.42.148.3 with SMTP id p3mr7394719icv.25.1390074767594; Sat, 18 Jan 2014 11:52:47 -0800 (PST) Received: by 10.64.6.4 with HTTP; Sat, 18 Jan 2014 11:52:47 -0800 (PST) In-Reply-To: References: Date: Sun, 19 Jan 2014 03:52:47 +0800 Message-ID: To: Daniel Lowrey Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=90e6ba6134bebbdca304f044004e Subject: Re: How to create Persistent zval? From: cornelius.howl@gmail.com (Lin Yo-An) --90e6ba6134bebbdca304f044004e Content-Type: text/plain; charset=Big5 Content-Transfer-Encoding: quoted-printable Daniel Lowrey =A9=F3 2014=A6~1=A4=EB19=A4=E9=ACP=B4=C1= =A4=E9=BCg=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 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 fo= r > 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 > --=20 Best Regards, Yo-An Lin --90e6ba6134bebbdca304f044004e--