[php-src] PR #11758: Proposing ZendMM Observer API

From: Date: Fri, 21 Jul 2023 12:58:44 +0000
Subject: [php-src] PR #11758: Proposing ZendMM Observer API
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-23132@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/11758 Author: realFlowControl Hello everyone, this PR proposes a ZendMM Observer API which allows for observing memory allocations in the Zend Memory Manager. The only current way to observer the ZendMM is via the zend_mm_set_custom_handlers() function which is meant to bring your own memory manager. Using this API has some side effects which you need to work around: - ZendMM won't cleanup allocated memory anymore in shutdown - ZendMM won't cleanup allocated memory anymore in case the memory limit was reached - ZendMM’s gc_collect_cycles() function won't do anything Additionally you need to be aware of neighbouring extensions and handle everything in order. This proposal flips this by keeping track of observers and not interfering with ZendMM internals. It will only be an observer that calls observing functions on malloc, free and realloc. It has no overhead as long as no observer is installed or when all observers that are installed are disabled. An example of how to use the API can be found at https://github.com/realFlowControl/zendmmobserver/blob/main/zendmmobserver.c Big picture: - an extension registers its observers via zend_mm_observers_register() - after the module startup the ZendMM observers will be enabled (from this point on the observing functions will be called if any) - during runtime an extension may call zend_mm_observer_disable() / zend_mm_observer_enable() to disable / enable a registered observer - before module shutdown the ZendMM observers will be shutdown and unregistered

« previous php.git-pulls (#23132) next »