php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
zend_mm_custom_handlers.c
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Copyright (c) The PHP Group |
4 +----------------------------------------------------------------------+
5 | This source file is subject to version 3.01 of the PHP license, |
6 | that is bundled with this package in the file LICENSE, and is |
7 | available through the world-wide-web at the following url: |
8 | https://www.php.net/license/3_01.txt |
9 | If you did not receive a copy of the PHP license and are unable to |
10 | obtain it through the world-wide-web, please send a note to |
11 | license@php.net so we can mail you a copy immediately. |
12 +----------------------------------------------------------------------+
13 | Author: Florian Engelhardt <florian@engelhardt.tc> |
14 +----------------------------------------------------------------------+
15*/
16
17#include "php.h"
18#include "php_test.h"
19#include "Zend/zend_alloc.h"
20#include "zend_portability.h"
21#include <stddef.h>
22#include <stdio.h>
23
37
50
52{
53 void * new_ptr;
55 {
59 } else {
61 }
62 printf("Realloc of %zu bytes from %p to %p\n", size, ptr, new_ptr);
63 return new_ptr;
64}
65
66size_t observe_gc(void)
67{
68 size_t size = 0;
69 if (ZT_G(custom_gc)) {
71 size = ZT_G(custom_gc)();
73 } else {
75 }
76 printf("ZendMM GC freed %zu bytes", size);
77 return size;
78}
79
80void observe_shutdown(bool full, bool silent)
81{
82 if (ZT_G(custom_shutdown)) {
84 ZT_G(custom_shutdown)(full, silent);
86 } else {
87 zend_mm_shutdown(ZT_G(original_heap), full, silent);
88 }
89 printf("Shutdown happened: full -> %d, silent -> %d\n", full, silent);
90}
91
121
123{
124 if (ZT_G(observed_heap) == NULL) {
125 return;
126 }
130 NULL,
131 NULL,
132 NULL,
133 NULL,
134 NULL
135 );
136 zend_mm_shutdown(ZT_G(observed_heap), true, true);
138 printf("Prev heap at %p restored in ZendMM\n", ZT_G(original_heap));
139}
140
145
152
153static PHP_INI_MH(OnUpdateZendTestMMCustomHandlersEnabled)
154{
155 if (new_value == NULL) {
156 return FAILURE;
157 }
158
159 int int_value = zend_ini_parse_bool(new_value);
160
161 if (int_value == 1) {
163 } else {
165 }
166 return OnUpdateBool(entry, new_value, mh_arg1, mh_arg2, mh_arg3, stage);
167}
168
170 STD_PHP_INI_BOOLEAN("zend_test.zend_mm_custom_handlers.enabled", "0", PHP_INI_USER, OnUpdateZendTestMMCustomHandlersEnabled, zend_mm_custom_handlers_enabled, zend_zend_test_globals, zend_test_globals)
172
174{
175 if (type != MODULE_TEMPORARY) {
177 } else {
178 (void)ini_entries;
179 }
180}
printf(string $format, mixed ... $values)
zend_ffi_type * type
Definition ffi.c:3812
new_type size
Definition ffi.c:4365
void * ptr
Definition ffi.c:3814
#define NULL
Definition gdcache.h:45
#define PHP_INI_USER
Definition php_ini.h:41
#define PHP_INI_BEGIN
Definition php_ini.h:52
#define STD_PHP_INI_BOOLEAN
Definition php_ini.h:66
#define PHP_INI_MH
Definition php_ini.h:49
#define PHP_INI_END
Definition php_ini.h:53
#define ZT_G(v)
zend_mm_heap * observed_heap
Definition php_test.h:77
void *(* custom_realloc)(void *, size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
Definition php_test.h:72
size_t(* custom_gc)(void)
Definition php_test.h:73
void(* custom_shutdown)(bool, bool)
Definition php_test.h:74
void(* custom_free)(void *ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
Definition php_test.h:71
zend_mm_heap * original_heap
Definition php_test.h:68
int zend_mm_custom_handlers_enabled
Definition php_test.h:65
void *(* custom_malloc)(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
Definition php_test.h:70
ZEND_API void ZEND_FASTCALL _zend_mm_free(zend_mm_heap *heap, void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
ZEND_API void zend_mm_get_custom_handlers_ex(zend_mm_heap *heap, void *(**_malloc)(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC), void(**_free)(void *ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC), void *(**_realloc)(void *, size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC), size_t(**_gc)(void), void(**_shutdown)(bool, bool))
void *ZEND_FASTCALL _zend_mm_realloc(zend_mm_heap *heap, void *ptr, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
ZEND_API bool zend_mm_is_custom_heap(zend_mm_heap *new_heap)
ZEND_API zend_mm_heap * zend_mm_set_heap(zend_mm_heap *new_heap)
ZEND_API void zend_mm_set_custom_handlers_ex(zend_mm_heap *heap, void *(*_malloc)(size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC), void(*_free)(void *ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC), void *(*_realloc)(void *, size_t ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC), size_t(*_gc)(void), void(*_shutdown)(bool, bool))
ZEND_API size_t zend_mm_gc(zend_mm_heap *heap)
ZEND_API zend_mm_heap * zend_mm_get_heap(void)
ZEND_API zend_mm_heap * zend_mm_startup(void)
ZEND_API void *ZEND_FASTCALL _zend_mm_alloc(zend_mm_heap *heap, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
ZEND_API void zend_mm_shutdown(zend_mm_heap *heap, bool full, bool silent)
ZEND_API void(ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data)
ZEND_API bool zend_ini_parse_bool(zend_string *str)
Definition zend_ini.c:573
#define REGISTER_INI_ENTRIES()
Definition zend_ini.h:203
void zend_test_mm_custom_handlers_rshutdown(void)
void * observe_realloc(void *ptr, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
void * observe_malloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
void zend_test_mm_custom_handlers_shutdown(void)
void zend_test_mm_custom_handlers_minit(INIT_FUNC_ARGS)
void zend_test_mm_custom_handlers_rinit(void)
size_t observe_gc(void)
void observe_free(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC)
void zend_test_mm_custom_handlers_init(void)
void observe_shutdown(bool full, bool silent)
#define INIT_FUNC_ARGS
#define MODULE_TEMPORARY
#define ZEND_FILE_LINE_DC
#define ZEND_FILE_LINE_ORIG_RELAY_CC
#define ZEND_FILE_LINE_RELAY_CC
#define ZEND_FILE_LINE_ORIG_DC
@ FAILURE
Definition zend_types.h:61