- Notifications
You must be signed in to change notification settings - Fork 7.8k
/
Copy pathZendAccelerator.h
352 lines (307 loc) · 11.1 KB
/
ZendAccelerator.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
/*
+----------------------------------------------------------------------+
| Zend OPcache |
+----------------------------------------------------------------------+
| Copyright (c) The PHP Group |
+----------------------------------------------------------------------+
| This source file is subject to version 3.01 of the PHP license, |
| that is bundled with this package in the file LICENSE, and is |
| available through the world-wide-web at the following url: |
| https://www.php.net/license/3_01.txt |
| If you did not receive a copy of the PHP license and are unable to |
| obtain it through the world-wide-web, please send a note to |
| license@php.net so we can mail you a copy immediately. |
+----------------------------------------------------------------------+
| Authors: Andi Gutmans <andi@php.net> |
| Zeev Suraski <zeev@php.net> |
| Stanislav Malyshev <stas@zend.com> |
| Dmitry Stogov <dmitry@php.net> |
+----------------------------------------------------------------------+
*/
#ifndefZEND_ACCELERATOR_H
#defineZEND_ACCELERATOR_H
#ifdefHAVE_CONFIG_H
# include<config.h>
#endif
#defineACCELERATOR_PRODUCT_NAME "Zend OPcache"
/* 2 - added Profiler support, on 20010712 */
/* 3 - added support for Optimizer's encoded-only-files mode */
/* 4 - works with the new Optimizer, that supports the file format with licenses */
/* 5 - API 4 didn't really work with the license-enabled file format. v5 does. */
/* 6 - Monitor was removed from ZendPlatform.so, to a module of its own */
/* 7 - Optimizer was embedded into Accelerator */
/* 8 - Standalone Open Source Zend OPcache */
#defineACCELERATOR_API_NO 8
#ifdefZEND_WIN32
# include"zend_config.w32.h"
#else
#include"zend_config.h"
# include<sys/time.h>
# include<sys/resource.h>
#endif
#ifdefHAVE_UNISTD_H
# include<unistd.h>
#endif
#include"zend_extensions.h"
#include"zend_compile.h"
#include"Optimizer/zend_optimizer.h"
#include"zend_accelerator_hash.h"
#include"zend_accelerator_debug.h"
#ifndefPHPAPI
# ifdefZEND_WIN32
# definePHPAPI __declspec(dllimport)
# else
# definePHPAPI
# endif
#endif
#ifndefZEND_EXT_API
# ifdefZEND_WIN32
# defineZEND_EXT_API __declspec(dllexport)
# elif defined(__GNUC__) &&__GNUC__ >= 4
# defineZEND_EXT_API __attribute__ ((visibility("default")))
# else
# defineZEND_EXT_API
# endif
#endif
#ifdefZEND_WIN32
# ifndefMAXPATHLEN
# include"win32/ioutil.h"
# defineMAXPATHLEN PHP_WIN32_IOUTIL_MAXPATHLEN
# endif
# include<direct.h>
#else
# ifndefMAXPATHLEN
# defineMAXPATHLEN 4096
# endif
# include<sys/param.h>
#endif
/*** file locking ***/
#ifndefZEND_WIN32
externintlock_file;
#endif
#if defined(ZEND_WIN32)
# defineENABLE_FILE_CACHE_FALLBACK 1
#else
# defineENABLE_FILE_CACHE_FALLBACK 0
#endif
#ifdefZEND_WIN32
typedefunsigned __int64accel_time_t;
#else
typedeftime_taccel_time_t;
#endif
typedefenum_zend_accel_restart_reason {
ACCEL_RESTART_OOM, /* restart because of out of memory */
ACCEL_RESTART_HASH, /* restart because of hash overflow */
ACCEL_RESTART_USER/* restart scheduled by opcache_reset() */
} zend_accel_restart_reason;
typedefstruct_zend_early_binding {
zend_string*lcname;
zend_string*rtd_key;
zend_string*lc_parent_name;
uint32_tcache_slot;
} zend_early_binding;
typedefstruct_zend_persistent_script {
zend_scriptscript;
zend_longcompiler_halt_offset; /* position of __HALT_COMPILER or -1 */
intping_auto_globals_mask; /* which autoglobals are used by the script */
accel_time_ttimestamp; /* the script modification time */
boolcorrupted;
boolis_phar;
boolempty;
uint32_tnum_warnings;
uint32_tnum_early_bindings;
zend_error_info**warnings;
zend_early_binding*early_bindings;
void*mem; /* shared memory area used by script structures */
size_tsize; /* size of used shared memory */
structzend_persistent_script_dynamic_members {
time_tlast_used;
zend_ulonghits;
unsigned intmemory_consumption;
time_trevalidate;
} dynamic_members;
} zend_persistent_script;
typedefstruct_zend_accel_directives {
zend_longmemory_consumption;
zend_longmax_accelerated_files;
doublemax_wasted_percentage;
char*user_blacklist_filename;
zend_longforce_restart_timeout;
booluse_cwd;
boolignore_dups;
boolvalidate_timestamps;
boolrevalidate_path;
boolsave_comments;
boolrecord_warnings;
boolprotect_memory;
boolfile_override_enabled;
boolenable_cli;
boolvalidate_permission;
#ifndefZEND_WIN32
boolvalidate_root;
#endif
zend_ulongrevalidate_freq;
zend_ulongfile_update_protection;
char*error_log;
#ifdefZEND_WIN32
char*mmap_base;
#endif
char*memory_model;
zend_longlog_verbosity_level;
zend_longoptimization_level;
zend_longopt_debug_level;
zend_longmax_file_size;
zend_longinterned_strings_buffer;
char*restrict_api;
#ifndefZEND_WIN32
char*lockfile_path;
#endif
char*file_cache;
boolfile_cache_only;
boolfile_cache_consistency_checks;
#ifENABLE_FILE_CACHE_FALLBACK
boolfile_cache_fallback;
#endif
#ifdefHAVE_HUGE_CODE_PAGES
boolhuge_code_pages;
#endif
char*preload;
#ifndefZEND_WIN32
char*preload_user;
#endif
#ifdefZEND_WIN32
char*cache_id;
#endif
} zend_accel_directives;
typedefstruct_zend_accel_globals {
boolcounted; /* the process uses shared memory */
boolenabled;
boollocked; /* thread obtained exclusive lock */
boolaccelerator_enabled; /* accelerator enabled for current request */
boolpcre_reseted;
zend_accel_directivesaccel_directives;
zend_string*cwd; /* current working directory or NULL */
zend_string*include_path; /* current value of "include_path" directive */
charinclude_path_key[32]; /* key of current "include_path" */
charcwd_key[32]; /* key of current working directory */
intinclude_path_key_len;
boolinclude_path_check;
intcwd_key_len;
boolcwd_check;
intauto_globals_mask;
time_trequest_time;
time_tlast_restart_time; /* used to synchronize SHM and in-process caches */
HashTablexlat_table;
#ifndefZEND_WIN32
zend_ulongroot_hash;
#endif
/* preallocated shared-memory block to save current script */
void*mem;
zend_persistent_script*current_persistent_script;
/* cache to save hash lookup on the same INCLUDE opcode */
constzend_op*cache_opline;
zend_persistent_script*cache_persistent_script;
/* preallocated buffer for keys */
zend_stringkey;
char_key[MAXPATHLEN*8];
} zend_accel_globals;
typedefstruct_zend_string_table {
uint32_tnTableMask;
uint32_tnNumOfElements;
zend_string*start;
zend_string*top;
zend_string*end;
zend_string*saved_top;
} zend_string_table;
typedefuint32_tzend_string_table_pos_t;
#defineZEND_STRING_TABLE_POS_MAX UINT32_MAX
#defineZEND_STRING_TABLE_POS_ALIGNMENT 8
typedefstruct_zend_accel_shared_globals {
/* Cache Data Structures */
zend_ulonghits;
zend_ulongmisses;
zend_ulongblacklist_misses;
zend_ulongoom_restarts; /* number of restarts because of out of memory */
zend_ulonghash_restarts; /* number of restarts because of hash overflow */
zend_ulongmanual_restarts; /* number of restarts scheduled by opcache_reset() */
zend_accel_hashhash; /* hash table for cached scripts */
size_tmap_ptr_last;
/* Directives & Maintenance */
time_tstart_time;
time_tlast_restart_time;
time_tforce_restart_time;
boolaccelerator_enabled;
boolrestart_pending;
zend_accel_restart_reasonrestart_reason;
boolcache_status_before_restart;
#ifdefZEND_WIN32
LONGLONGmem_usage;
LONGLONGrestart_in;
#endif
boolrestart_in_progress;
booljit_counters_stopped;
/* Preloading */
zend_persistent_script*preload_script;
zend_persistent_script**saved_scripts;
/* uninitialized HashTable Support */
uint32_tuninitialized_bucket[-HT_MIN_MASK];
/* Tracing JIT */
void*jit_traces;
constvoid**jit_exit_groups;
/* Interned Strings Support (must be the last element) */
ZEND_SET_ALIGNED(ZEND_STRING_TABLE_POS_ALIGNMENT, zend_string_tableinterned_strings);
} zend_accel_shared_globals;
#ifdefZEND_WIN32
externcharaccel_uname_id[32];
#endif
externboolaccel_startup_ok;
externboolfile_cache_only;
#ifENABLE_FILE_CACHE_FALLBACK
externboolfallback_process;
#endif
externzend_accel_shared_globals*accel_shared_globals;
#defineZCSG(element) (accel_shared_globals->element)
#ifdefZTS
# defineZCG(v) ZEND_TSRMG(accel_globals_id, zend_accel_globals *, v)
externintaccel_globals_id;
# ifdefCOMPILE_DL_OPCACHE
ZEND_TSRMLS_CACHE_EXTERN()
# endif
#else
# defineZCG(v) (accel_globals.v)
externzend_accel_globalsaccel_globals;
#endif
externconstchar*zps_api_failure_reason;
BEGIN_EXTERN_C()
voidaccel_shutdown(void);
zend_resultaccel_activate(INIT_FUNC_ARGS);
zend_resultaccel_post_deactivate(void);
voidzend_accel_schedule_restart(zend_accel_restart_reasonreason);
voidzend_accel_schedule_restart_if_necessary(zend_accel_restart_reasonreason);
accel_time_tzend_get_file_handle_timestamp(zend_file_handle*file_handle, size_t*size);
zend_resultvalidate_timestamp_and_record(zend_persistent_script*persistent_script, zend_file_handle*file_handle);
zend_resultvalidate_timestamp_and_record_ex(zend_persistent_script*persistent_script, zend_file_handle*file_handle);
zend_resultzend_accel_invalidate(zend_string*filename, boolforce);
zend_resultaccelerator_shm_read_lock(void);
voidaccelerator_shm_read_unlock(void);
zend_string*accel_make_persistent_key(zend_string*path);
zend_op_array*persistent_compile_file(zend_file_handle*file_handle, inttype);
#defineIS_ACCEL_INTERNED(str) \
((char*)(str) >= (char*)ZCSG(interned_strings).start && (char*)(str) < (char*)ZCSG(interned_strings).top)
zend_string*ZEND_FASTCALLaccel_new_interned_string(zend_string*str);
uint32_tzend_accel_get_class_name_map_ptr(zend_string*type_name);
END_EXTERN_C()
/* memory write protection */
#defineSHM_PROTECT() \
do { \
if (ZCG(accel_directives).protect_memory) { \
zend_accel_shared_protect(true); \
} \
} while (0)
#defineSHM_UNPROTECT() \
do { \
if (ZCG(accel_directives).protect_memory) { \
zend_accel_shared_protect(false); \
} \
} while (0)
#endif/* ZEND_ACCELERATOR_H */