Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:42691 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66888 invoked from network); 19 Jan 2009 01:45:32 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jan 2009 01:45:32 -0000 Authentication-Results: pb1.pair.com header.from=shire@tekrat.com; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=shire@tekrat.com; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain tekrat.com from 69.63.177.213 cause and error) X-PHP-List-Original-Sender: shire@tekrat.com X-Host-Fingerprint: 69.63.177.213 sizzo.org Linux 2.6 Received: from [69.63.177.213] ([69.63.177.213:46411] helo=sizzo.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id B7/65-49574-A3BD3794 for ; Sun, 18 Jan 2009 20:45:30 -0500 Received: from shirebook.tekrat.linksys (dsl092-189-079.sfo1.dsl.speakeasy.net [66.92.189.79]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (No client certificate requested) by sizzo.org (Postfix) with ESMTPSA id 6B6EF6D4954 for ; Sun, 18 Jan 2009 17:45:27 -0800 (PST) Message-ID: <4973DB36.3010703@tekrat.com> Date: Sun, 18 Jan 2009 17:45:26 -0800 User-Agent: Postbox 1.0b3 (Macintosh/2009011516) MIME-Version: 1.0 To: PHP Internals List Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: PATCH: zend_mm_heap_overflow() From: shire@tekrat.com (shire) I'm releasing an extended PHP logging extension that we currently use at facebook with much success. I currently use a small patch to determine if a memory overflow has occurred as there's currently no direct access into the allocator structures. You can get more information on the project at http://tekrat.com/php/xlog/. It would be useful if this patch (and perhaps more accessors into the memory allocator) where added. Although I understand there should be some careful choices and limitations here, and this case is a pretty specific use case, but I thought I'd share it in case there are others who happen to find this useful as well or perhaps someone can propose a more general alternative. Patches for different branches are here (I've pasted php53 below): http://tekrat.com/downloads/bits/zend_mm_heap_overflow.php6.patch http://tekrat.com/downloads/bits/zend_mm_heap_overflow.php53.patch http://tekrat.com/downloads/bits/zend_mm_heap_overflow.php52.patch diff --git a/ZendEngine2/zend_alloc.c b/ZendEngine2/zend_alloc.c index 8853d06..b8884a0 100644 --- a/ZendEngine2/zend_alloc.c +++ b/ZendEngine2/zend_alloc.c @@ -2537,6 +2537,13 @@ ZEND_API void start_memory_manager(TSRMLS_D) #endif } +/*** BEGIN Patch: zend_mm_heap_overflow ***/ +ZEND_API int zend_mm_heap_overflow(TSRMLS_D) +{ + return AG(mm_heap)->overflow; +} +/*** END Patch: zend_mm_heap_overflow ***/ + ZEND_API zend_mm_heap *zend_mm_set_heap(zend_mm_heap *new_heap TSRMLS_DC) { zend_mm_heap *old_heap; diff --git a/ZendEngine2/zend_alloc.h b/ZendEngine2/zend_alloc.h index d92df4b..3610931 100644 --- a/ZendEngine2/zend_alloc.h +++ b/ZendEngine2/zend_alloc.h @@ -231,6 +231,7 @@ struct _zend_mm_storage { }; ZEND_API zend_mm_heap *zend_mm_startup_ex(const zend_mm_mem_handlers *handlers, size_t block_size, size_t reserve_size, int internal, void *params); +ZEND_API int zend_mm_heap_overflow(TSRMLS_D); /* Patch: zend_mm_heap_overflow */ ZEND_API zend_mm_heap *zend_mm_set_heap(zend_mm_heap *new_heap TSRMLS_DC); ZEND_API zend_mm_storage *zend_mm_get_storage(zend_mm_heap *heap); -shire