forked from eaccelerator/eaccelerator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
eaccelerator.h
520 lines (454 loc) · 14.6 KB
/
eaccelerator.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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
/*
+----------------------------------------------------------------------+
| eAccelerator project |
+----------------------------------------------------------------------+
| Copyright (c) 2004 - 2012 eAccelerator |
| http://eaccelerator.net |
+----------------------------------------------------------------------+
| This program is free software; you can redistribute it and/or |
| modify it under the terms of the GNU General Public License |
| as published by the Free Software Foundation; either version 2 |
| of the License, or (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU General Public License for more details. |
| |
| You should have received a copy of the GNU General Public License |
| along with this program; if not, write to the Free Software |
| Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
| MA 02111-1307, USA. |
| |
| A copy is availble at http://www.gnu.org/copyleft/gpl.txt |
+----------------------------------------------------------------------+
$Id: eaccelerator.h 423 2010-07-11 21:03:25Z bart $
*/
#ifndef INCLUDED_EACCELERATOR_H
#define INCLUDED_EACCELERATOR_H
#include "php.h"
#include "zend.h"
#include "zend_API.h"
#include "zend_extensions.h"
#if !defined(ZEND_WIN32) && defined(HAVE_CONFIG_H)
# if ZEND_MODULE_API_NO >= 20001222
# include "config.h"
# else
# include "php_config.h"
# endif
#endif
#if PHP_MAJOR_VERSION == 4 || (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION < 1)
#error "eAccelerator only supports PHP 5.1 and higher"
#endif
#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2
# define ZEND_ENGINE_2_2
#endif
#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3
# define ZEND_ENGINE_2_3
#endif
#if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4
# define ZEND_ENGINE_2_4
#endif
/* fixes compile errors on php5.1 */
#ifdef STR_EMPTY_ALLOC
# define empty_string STR_EMPTY_ALLOC()
#endif
#ifdef WITH_EACCELERATOR_CRASH_DETECTION
# include <signal.h>
#endif
#define EACCELERATOR_MM_FILE "/tmp/eaccelerator"
#ifdef EACCELERATOR_WITHOUT_FILE_LOCKING
# ifndef LOCK_SH
# define LOCK_SH 1
# define LOCK_EX 2
# define LOCK_UN 8
# endif
# define EACCELERATOR_FLOCK(FILE,OP)
#else
# ifndef ZEND_WIN32
# ifdef HAVE_FLOCK
# include <sys/file.h>
# define EACCELERATOR_FLOCK(FILE,OP) flock((FILE),(OP))
# else
# ifndef LOCK_SH
# define LOCK_SH 1
# define LOCK_EX 2
# define LOCK_UN 8
# endif
# define EACCELERATOR_FLOCK(FILE,OP)
# endif
# else
# define LOCK_SH 0
# define LOCK_EX 1
# define LOCK_UN 2
# define EACCELERATOR_FLOCK(FILE,OP) {OVERLAPPED offset = {0,0,0,0,NULL};\
if ((OP) == LOCK_EX) {\
LockFileEx((HANDLE)_get_osfhandle(FILE), \
LOCKFILE_EXCLUSIVE_LOCK, 0,\
1, 0, &offset);\
} else if ((OP) == LOCK_SH) {\
LockFileEx((HANDLE)_get_osfhandle(FILE), \
0, 0,\
1, 0, &offset);\
} else if ((OP) == LOCK_UN) {\
UnlockFileEx((HANDLE)_get_osfhandle(FILE), \
0,\
1, 0, &offset);\
}}
# endif
#endif
#if !defined(_INTPTR_T_DEFINED) && ZEND_WIN32
typedef intptr_t;
#define _INTPTR_T_DEFINED
#else
# ifdef HAVE_STDINT_H
# include <stdint.h>
# elif HAVE_INTTYPES_H
# include <inttypes.h>
# endif
#endif
#if !defined(ssize_t) && ZEND_WIN32
/* define ssize_t for Win32. */
#define ssize_t int
#endif
#ifdef HAVE_EACCELERATOR
#include "mm.h"
#ifdef ZEND_WIN32
# include <process.h>
# ifndef S_ISREG
# define S_ISREG(mode) (((mode)&S_IFMT) & S_IFREG)
# endif
# ifndef S_IRUSR
# define S_IRUSR S_IREAD
# endif
# ifndef S_IWUSR
# define S_IWUSR S_IWRITE
# endif
#else
# include <dirent.h>
#endif
#ifdef ZTS
# define ZTS_LOCK() tsrm_mutex_lock(ea_mutex)
# define ZTS_UNLOCK() tsrm_mutex_unlock(ea_mutex)
#else
# define ZTS_LOCK()
# define ZTS_UNLOCK()
#endif
#if defined(EACCELERATOR_PROTECT_SHM)
# define EACCELERATOR_PROTECT() do {mm_protect(ea_mm_instance->mm, MM_PROT_READ);} while(0)
# define EACCELERATOR_UNPROTECT() do {mm_protect(ea_mm_instance->mm, MM_PROT_READ|MM_PROT_WRITE);} while(0)
#else
# define EACCELERATOR_PROTECT()
# define EACCELERATOR_UNPROTECT()
#endif
#define EACCELERATOR_LOCK_RW() do {ZTS_LOCK(); mm_lock(ea_mm_instance->mm, MM_LOCK_RW);} while(0)
#define EACCELERATOR_LOCK_RD() do {ZTS_LOCK(); mm_lock(ea_mm_instance->mm, MM_LOCK_RD);} while(0)
#define EACCELERATOR_UNLOCK() do {mm_unlock(ea_mm_instance->mm); ZTS_UNLOCK();} while(0)
#define EACCELERATOR_UNLOCK_RW() EACCELERATOR_UNLOCK()
#define EACCELERATOR_UNLOCK_RD() EACCELERATOR_UNLOCK()
#define EACCELERATOR_BLOCK_INTERRUPTIONS() HANDLE_BLOCK_INTERRUPTIONS()
#define EACCELERATOR_UNBLOCK_INTERRUPTIONS() HANDLE_UNBLOCK_INTERRUPTIONS()
#define EACCELERATOR_HASH_LEVEL 2
#define EA_HASH_SIZE 512
#define EA_HASH_MAX (EA_HASH_SIZE-1)
#define eaccelerator_malloc(size) mm_malloc_lock(ea_mm_instance->mm, size)
#define eaccelerator_free(x) mm_free_lock(ea_mm_instance->mm, x)
#define eaccelerator_malloc_nolock(size) mm_malloc_nolock(ea_mm_instance->mm, size)
#define eaccelerator_free_nolock(x) mm_free_nolock(ea_mm_instance->mm, x)
#if (defined (__GNUC__) && __GNUC__ >= 2)
#define EACCELERATOR_PLATFORM_ALIGNMENT (__alignof__ (align_test))
#else
#define EACCELERATOR_PLATFORM_ALIGNMENT (sizeof(align_union))
#endif
#define EACCELERATOR_ALIGN(n) (n) = (void*)((((size_t)(n)-1) & ~(EACCELERATOR_PLATFORM_ALIGNMENT-1)) + EACCELERATOR_PLATFORM_ALIGNMENT)
#define EA_SIZE_ALIGN(n) (n) = ((((size_t)(n)-1) & ~(EACCELERATOR_PLATFORM_ALIGNMENT-1)) + EACCELERATOR_PLATFORM_ALIGNMENT)
#ifdef ZEND_ENGINE_2_3
#define RESET_PZVAL_REFCOUNT(z) Z_SET_REFCOUNT_P(z, 1)
#else
#define RESET_PZVAL_REFCOUNT(z) (z)->refcount = 1;
#endif
#define MAX_DUP_STR_LEN 256
/******************************************************************************/
/* get the type of the zvalue */
#ifdef ZEND_ENGINE_2_3
# define EA_ZV_TYPE_P(zv) (Z_TYPE_P(zv) & IS_CONSTANT_TYPE_MASK)
#else
# define EA_ZV_TYPE_P(zv) (Z_TYPE_P(zv) & ~IS_CONSTANT_INDEX)
#endif
#ifndef offsetof
# define offsetof(str,fld) ((size_t)&(((str*)NULL)->fld))
#endif
typedef struct _eaccelerator_op_array {
zend_uchar type;
#ifndef ZEND_ENGINE_2_3
zend_bool uses_this;
#endif
zend_uint num_args;
zend_uint required_num_args;
zend_arg_info *arg_info;
#ifdef ZEND_ENGINE_2_4
const char *function_name;
#else
zend_bool pass_rest_by_reference;
zend_bool return_reference;
char *function_name;
#endif
char *scope_name;
int scope_name_len;
zend_uint fn_flags;
zend_op *opcodes;
zend_uint last;
zend_compiled_variable *vars;
int last_var;
zend_uint T;
zend_brk_cont_element *brk_cont_array;
int last_brk_cont;
zend_try_catch_element *try_catch_array;
int last_try_catch;
HashTable *static_variables;
#ifdef ZEND_ENGINE_2_3
zend_uint this_var;
#endif
#ifdef ZEND_ENGINE_2_4
const char *filename;
#else
char *filename;
#endif
zend_uint line_start;
zend_uint line_end;
#ifdef INCLUDE_DOC_COMMENTS
# ifdef ZEND_ENGINE_2_4
const char *doc_comment;
# else
char *doc_comment;
# endif
zend_uint doc_comment_len;
#endif
#ifdef ZEND_ENGINE_2_3
zend_uint early_binding;
#endif
#ifdef ZEND_ENGINE_2_4
zend_literal *literals;
int last_literal;
int last_cache_slot;
#endif
} ea_op_array;
typedef struct _eaccelerator_class_entry {
char type;
#ifdef ZEND_ENGINE_2_4
const char *name;
#else
char *name;
#endif
zend_uint name_length;
char *parent;
HashTable function_table;
HashTable properties_info;
#ifdef ZEND_ENGINE_2_4
zval **default_properties_table;
zval **default_static_members_table;
zval **static_members_table;
#else
HashTable default_properties;
HashTable default_static_members;
HashTable *static_members;
#endif
HashTable constants_table;
#ifdef ZEND_ENGINE_2_4
int default_properties_count;
int default_static_members_count;
#endif
zend_uint ce_flags;
zend_uint num_interfaces;
#ifdef ZEND_ENGINE_2_4
const char *filename;
#else
char *filename;
#endif
zend_uint line_start;
zend_uint line_end;
#ifdef INCLUDE_DOC_COMMENTS
# ifdef ZEND_ENGINE_2_4
const char *doc_comment;
# else
char *doc_comment;
# endif
zend_uint doc_comment_len;
#endif
} ea_class_entry;
/*
* To cache functions and classes.
*/
typedef struct _ea_fc_entry {
void *fc;
struct _ea_fc_entry *next;
int htablen;
char htabkey[1]; /* must be last element */
} ea_fc_entry;
/*
* A ea_cache_entry is a bucket for one PHP script file.
* User functions and classes defined in the file go into
* the list of ea_fc_entry.
*/
typedef struct _ea_cache_entry {
struct _ea_cache_entry *next;
unsigned int hv; /* hash value */
off_t filesize; /* file size */
time_t mtime; /* file last modification time */
time_t ttl; /* expiration time (updated on each hit) */
time_t ts; /* timestamp of cache entry */
unsigned int size; /* entry size (bytes) */
unsigned int nhits; /* hits count */
unsigned int nreloads; /* count of reloads */
int use_cnt; /* how many processes uses the entry */
ea_op_array *op_array; /* script's global scope code */
ea_fc_entry *f_head; /* list of nested functions */
ea_fc_entry *c_head; /* list of nested classes */
zend_bool removed; /* the entry is scheduled to remove */
char realfilename[1]; /* real file name (must be last el.) */
} ea_cache_entry;
/*
* Linked list of ea_cache_entry which are used by process/thread
*/
typedef struct _ea_used_entry {
struct _ea_used_entry *next;
ea_cache_entry *entry;
} ea_used_entry;
typedef struct _ea_file_header {
char magic[8]; /* "EACCELERATOR" */
int eaccelerator_version[2];
int zend_version[2];
int php_version[2];
int size;
time_t mtime;
time_t ts;
unsigned int crc32;
} ea_file_header;
int check_header(ea_file_header *hdr);
void init_header(ea_file_header *hdr);
typedef struct {
MM *mm;
pid_t owner;
size_t total;
unsigned int hash_cnt;
zend_bool enabled;
zend_bool optimizer_enabled;
zend_bool check_mtime_enabled;
unsigned int rem_cnt;
time_t last_prune;
ea_cache_entry *removed;
uid_t cache_dir_uid;
ea_cache_entry *hash[EA_HASH_SIZE];
} eaccelerator_mm;
/*
* Where to cache
*/
typedef enum _ea_cache_place {
ea_shm_and_disk, /* in shm and in disk */
ea_shm, /* in shm, but if it is not possible then on disk */
ea_shm_only, /* in shm only */
ea_disk_only, /* on disk only */
ea_none /* don't cache */
} ea_cache_place;
typedef union align_union {
double d;
void *v;
int (*func)(int);
long l;
} align_union;
#ifdef ZEND_ENGINE_2_2
typedef union _align_test {
void *ptr;
double dbl;
long lng;
} align_test;
#endif
/******************************************************************************/
#ifdef ZTS
# ifdef __APPLE__
/* Workaround to prevent 'multiple definitions of symbol' during build on OSX */
static MUTEX_T ea_mutex;
# else
MUTEX_T ea_mutex;
# endif
#endif
/* needed to compile eA as a static php module */
extern zend_module_entry eaccelerator_module_entry;
#define phpext_eaccelerator_ptr &eaccelerator_module_entry
void format_size (char *s, unsigned int size, int legend);
void eaccelerator_prune (time_t t);
void *eaccelerator_malloc2 (size_t size TSRMLS_DC);
unsigned int eaccelerator_crc32 (const char *p, size_t n);
int eaccelerator_md5 (char *s, const char *prefix, const char *key TSRMLS_DC);
# ifdef WITH_EACCELERATOR_OPTIMIZER
void eaccelerator_optimize (zend_op_array * op_array);
# endif
#ifdef ZTS
# define EAG(v) TSRMG(eaccelerator_globals_id, zend_eaccelerator_globals*, v)
#else
# define EAG(v) (eaccelerator_globals.v)
#endif
struct ea_pattern_t {
struct ea_pattern_t *next;
char *pattern;
};
/*
* Globals (different for each process/thread)
*/
ZEND_BEGIN_MODULE_GLOBALS (eaccelerator)
void *used_entries; /* list of files which are used */
/* by process/thread */
zend_bool enabled;
zend_bool optimizer_enabled;
zend_bool check_mtime_enabled;
zend_bool compiler;
zend_bool in_request;
char *cache_dir;
char *ea_log_file;
char *mem;
char *allowed_admin_path;
time_t req_start; /* time of request start (set in RINIT) */
HashTable strings;
HashTable restored;
zend_class_entry *class_entry;
zend_uint refcount_helper;
struct ea_pattern_t *pattern_list;
#ifdef WITH_EACCELERATOR_CRASH_DETECTION
#ifdef SIGSEGV
void (*original_sigsegv_handler) (int);
#endif
#ifdef SIGFPE
void (*original_sigfpe_handler) (int);
#endif
#ifdef SIGBUS
void (*original_sigbus_handler) (int);
#endif
#ifdef SIGILL
void (*original_sigill_handler) (int);
#endif
#ifdef SIGABRT
void (*original_sigabrt_handler) (int);
#endif
#endif
#ifdef DEBUG
int xpad;
int profile_level;
long self_time[256];
#endif
ZEND_END_MODULE_GLOBALS (eaccelerator)
ZEND_EXTERN_MODULE_GLOBALS (eaccelerator)
#define EACCELERATOR_EXTENSION_NAME "eAccelerator"
#define EA_MAGIC "EACCELERATOR"
#define EACCELERATOR_VERSION_GUID "PHPE8EDA1B6-806A-4851-B1C8-A6B4712F44FB"
#define EACCELERATOR_LOGO_GUID "PHPE6F78DE9-13E4-4dee-8518-5FA2DACEA803"
#define EACCELERATOR_VERSION_STRING ("eAccelerator " EACCELERATOR_VERSION " (PHP " PHP_VERSION ")")
#endif /* HAVE_EACCELERATOR */
#endif /* #ifndef INCLUDED_EACCELERATOR_H */
/*
* Local variables:
* tab-width: 4
* c-basic-offset: 4
* End:
* vim>600: expandtab sw=4 ts=4 sts=4 fdm=marker
* vim<600: expandtab sw=4 ts=4 sts=4
*/