php-internal-docs 8.4.8
Unofficial docs for php/php-src
Loading...
Searching...
No Matches
zend_shared_alloc.h
Go to the documentation of this file.
1/*
2 +----------------------------------------------------------------------+
3 | Zend OPcache |
4 +----------------------------------------------------------------------+
5 | Copyright (c) The PHP Group |
6 +----------------------------------------------------------------------+
7 | This source file is subject to version 3.01 of the PHP license, |
8 | that is bundled with this package in the file LICENSE, and is |
9 | available through the world-wide-web at the following url: |
10 | https://www.php.net/license/3_01.txt |
11 | If you did not receive a copy of the PHP license and are unable to |
12 | obtain it through the world-wide-web, please send a note to |
13 | license@php.net so we can mail you a copy immediately. |
14 +----------------------------------------------------------------------+
15 | Authors: Andi Gutmans <andi@php.net> |
16 | Zeev Suraski <zeev@php.net> |
17 | Stanislav Malyshev <stas@zend.com> |
18 | Dmitry Stogov <dmitry@php.net> |
19 +----------------------------------------------------------------------+
20*/
21
22#ifndef ZEND_SHARED_ALLOC_H
23#define ZEND_SHARED_ALLOC_H
24
25#include "zend.h"
26#include "ZendAccelerator.h"
27
28#if defined(__APPLE__) && defined(__MACH__) /* darwin */
29# ifdef HAVE_SHM_MMAP_POSIX
30# define USE_SHM_OPEN 1
31# endif
32# ifdef HAVE_SHM_MMAP_ANON
33# define USE_MMAP 1
34# endif
35#elif defined(__linux__) || defined(_AIX)
36# ifdef HAVE_SHM_MMAP_POSIX
37# define USE_SHM_OPEN 1
38# endif
39# ifdef HAVE_SHM_IPC
40# define USE_SHM 1
41# endif
42# ifdef HAVE_SHM_MMAP_ANON
43# define USE_MMAP 1
44# endif
45#elif defined(__sparc) || defined(__sun)
46# ifdef HAVE_SHM_MMAP_POSIX
47# define USE_SHM_OPEN 1
48# endif
49# ifdef HAVE_SHM_IPC
50# define USE_SHM 1
51# endif
52# if defined(__i386)
53# ifdef HAVE_SHM_MMAP_ANON
54# define USE_MMAP 1
55# endif
56# endif
57#else
58# ifdef HAVE_SHM_MMAP_POSIX
59# define USE_SHM_OPEN 1
60# endif
61# ifdef HAVE_SHM_MMAP_ANON
62# define USE_MMAP 1
63# endif
64# ifdef HAVE_SHM_IPC
65# define USE_SHM 1
66# endif
67#endif
68
69#define ALLOC_FAILURE 0
70#define ALLOC_SUCCESS 1
71#define FAILED_REATTACHED 2
72#define SUCCESSFULLY_REATTACHED 4
73#define ALLOC_FAIL_MAPPING 8
74#define ALLOC_FALLBACK 9
75
76typedef struct _zend_shared_segment {
77 size_t size;
78 size_t end;
79 size_t pos; /* position for simple stack allocator */
80 void *p;
82
83typedef int (*create_segments_t)(size_t requested_size, zend_shared_segment ***shared_segments, int *shared_segment_count, const char **error_in);
84typedef int (*detach_segment_t)(zend_shared_segment *shared_segment);
85
91
96
98 size_t *positions; /* current positions for each segment */
99 size_t shared_free; /* amount of free shared memory */
101
103 /* Shared Memory Manager */
105 /* Number of allocated shared segments */
107 /* Amount of free shared memory */
109 /* Amount of shared memory allocated by garbage */
111 /* No more shared memory flag */
113 /* Saved Shared Allocator State */
115 /* Pointer to the application's shared data structures */
117 /* Reserved shared memory */
118 void *reserved;
121
123
124#define ZSMMG(element) (smm_shared_globals->element)
125
126#define SHARED_ALLOC_REATTACHED (SUCCESS+1)
127
129
130int zend_shared_alloc_startup(size_t requested_size, size_t reserved_size);
132
133/* allocate shared memory block */
134void *zend_shared_alloc(size_t size);
135
140static inline void *zend_shared_alloc_aligned(size_t size) {
141#if defined(__AVX__) || defined(__SSE2__)
142 /* Align to 64-byte boundary */
143 void *p = zend_shared_alloc(size + 64);
144 return (void *)(((uintptr_t)p + 63L) & ~63L);
145#else
146 return zend_shared_alloc(size);
147#endif
148}
149
150/* copy into shared memory */
151void *zend_shared_memdup_get_put_free(void *source, size_t size);
152void *zend_shared_memdup_put_free(void *source, size_t size);
153void *zend_shared_memdup_free(void *source, size_t size);
154void *zend_shared_memdup_get_put(void *source, size_t size);
155void *zend_shared_memdup_put(void *source, size_t size);
156void *zend_shared_memdup(void *source, size_t size);
157
158int zend_shared_memdup_size(void *p, size_t size);
159
160bool zend_accel_in_shm(void *ptr);
161
162typedef union _align_test {
163 void *ptr;
164 double dbl;
167
168#if ZEND_GCC_VERSION >= 2000
169# define PLATFORM_ALIGNMENT (__alignof__(align_test) < 8 ? 8 : __alignof__(align_test))
170#else
171# define PLATFORM_ALIGNMENT (sizeof(align_test))
172#endif
173
174#define ZEND_ALIGNED_SIZE(size) \
175 ZEND_MM_ALIGNED_SIZE_EX(size, PLATFORM_ALIGNMENT)
176
177/* exclusive locking */
178void zend_shared_alloc_lock(void);
179void zend_shared_alloc_unlock(void); /* returns the allocated size during lock..unlock */
181
182/* old/new mapping functions */
187void zend_shared_alloc_restore_xlat_table(uint32_t checkpoint);
188void zend_shared_alloc_register_xlat_entry(const void *key, const void *value);
189void *zend_shared_alloc_get_xlat_entry(const void *key);
190
194const char *zend_accel_get_shared_model(void);
195
202void zend_accel_shared_protect(bool protected);
203
204#ifdef USE_MMAP
205extern const zend_shared_memory_handlers zend_alloc_mmap_handlers;
206#endif
207
208#ifdef USE_SHM
209extern const zend_shared_memory_handlers zend_alloc_shm_handlers;
210#endif
211
212#ifdef USE_SHM_OPEN
213extern const zend_shared_memory_handlers zend_alloc_posix_handlers;
214#endif
215
216#ifdef ZEND_WIN32
221#endif
222
224
225#endif /* ZEND_SHARED_ALLOC_H */
#define ZEND_EXT_API
new_type size
Definition ffi.c:4365
void * ptr
Definition ffi.c:3814
unsigned char key[REFLECTION_KEY_LEN]
p
Definition session.c:1105
const zend_shared_memory_handlers zend_alloc_win32_handlers
void zend_shared_alloc_lock_win32(void)
void zend_shared_alloc_unlock_win32(void)
void zend_shared_alloc_create_lock(void)
const zend_shared_memory_handlers * handler
const char * name
zend_shared_segment ** shared_segments
zend_shared_memory_state shared_memory_state
create_segments_t create_segments
ZEND_API void(ZEND_FASTCALL *zend_touch_vm_stack_data)(void *vm_stack_data)
int32_t zend_long
Definition zend_long.h:42
#define END_EXTERN_C()
#define BEGIN_EXTERN_C()
void zend_shared_alloc_shutdown(void)
ZEND_EXT_API zend_smm_shared_globals * smm_shared_globals
void * zend_shared_alloc(size_t size)
int zend_shared_alloc_startup(size_t requested_size, size_t reserved_size)
struct _zend_shared_segment zend_shared_segment
struct _zend_shared_memory_state zend_shared_memory_state
void * zend_shared_alloc_get_xlat_entry(const void *key)
uint32_t zend_shared_alloc_checkpoint_xlat_table(void)
void zend_shared_alloc_save_state(void)
void zend_shared_alloc_lock(void)
const char * zend_accel_get_shared_model(void)
void * zend_shared_memdup_free(void *source, size_t size)
bool zend_accel_in_shm(void *ptr)
void zend_shared_alloc_init_xlat_table(void)
void * zend_shared_memdup_put_free(void *source, size_t size)
int(* detach_segment_t)(zend_shared_segment *shared_segment)
struct _handler_entry zend_shared_memory_handler_entry
void zend_shared_alloc_register_xlat_entry(const void *key, const void *value)
void zend_shared_alloc_safe_unlock(void)
void * zend_shared_memdup_put(void *source, size_t size)
void * zend_shared_memdup_get_put_free(void *source, size_t size)
union _align_test align_test
void zend_shared_alloc_unlock(void)
void zend_shared_alloc_restore_xlat_table(uint32_t checkpoint)
void zend_shared_alloc_clear_xlat_table(void)
void zend_accel_shared_protect(bool protected)
int(* create_segments_t)(size_t requested_size, zend_shared_segment ***shared_segments, int *shared_segment_count, const char **error_in)
void zend_shared_alloc_destroy_xlat_table(void)
size_t zend_shared_alloc_get_free_memory(void)
int zend_shared_memdup_size(void *p, size_t size)
void zend_shared_alloc_restore_state(void)
void * zend_shared_memdup_get_put(void *source, size_t size)
void * zend_shared_alloc(size_t size)
struct _zend_smm_shared_globals zend_smm_shared_globals
void * zend_shared_memdup(void *source, size_t size)
value