root/eaccelerator/tags/0.9.5.1/eaccelerator.h

Revision 270, 14.9 kB (checked in by bart, 2 years ago)

Add php 5.2 support. These are minimal changes so they shouldn't affect stability.

  • Property svn:eol-style set to native
  • Property svn:keywords set to svn:eol-style
Line 
1 /*
2    +----------------------------------------------------------------------+
3    | eAccelerator project                                                 |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 2004 - 2006 eAccelerator                               |
6    | http://eaccelerator.net                                                  |
7    +----------------------------------------------------------------------+
8    | This program is free software; you can redistribute it and/or        |
9    | modify it under the terms of the GNU General Public License          |
10    | as published by the Free Software Foundation; either version 2       |
11    | of the License, or (at your option) any later version.               |
12    |                                                                      |
13    | This program is distributed in the hope that it will be useful,      |
14    | but WITHOUT ANY WARRANTY; without even the implied warranty of       |
15    | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the        |
16    | GNU General Public License for more details.                         |
17    |                                                                      |
18    | You should have received a copy of the GNU General Public License    |
19    | along with this program; if not, write to the Free Software          |
20    | Foundation, Inc., 59 Temple Place - Suite 330, Boston,               |
21    | MA  02111-1307, USA.                                                 |
22    |                                                                      |
23    | A copy is availble at http://www.gnu.org/copyleft/gpl.txt            |
24    +----------------------------------------------------------------------+
25    $Id: eaccelerator.h 178 2006-03-06 09:08:40Z bart $
26 */
27
28 #ifndef INCLUDED_EACCELERATOR_H
29 #define INCLUDED_EACCELERATOR_H
30
31 #include "php.h"
32 #include "zend.h"
33 #include "zend_API.h"
34 #include "zend_extensions.h"
35
36 #if !defined(ZEND_WIN32) && defined(HAVE_CONFIG_H)
37 #  if ZEND_MODULE_API_NO >= 20001222
38 #    include "config.h"
39 #  else
40 #    include "php_config.h"
41 #  endif
42 #endif
43
44 #if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1
45 #   define ZEND_ENGINE_2_1
46 #endif
47
48 #if PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2
49 #   define ZEND_ENGINE_2_2
50 #endif
51
52 /* fixes compile errors on php5.1 */
53 #ifdef STR_EMPTY_ALLOC
54 #define empty_string STR_EMPTY_ALLOC()
55 #endif
56
57 #if !defined(ZEND_WIN32) && defined(WITH_EACCELERATOR_USE_INODE)
58 /* UnDefine if your filesystem doesn't support inodes */
59 #  define EACCELERATOR_USE_INODE
60 #endif
61
62 #ifdef WITH_EACCELERATOR_CRASH_DETECTION
63 #  include <signal.h>
64 #endif
65
66 #define EACCELERATOR_MM_FILE "/tmp/eaccelerator"
67
68 #ifdef EACCELERATOR_WITHOUT_FILE_LOCKING
69 #  ifndef LOCK_SH
70 #    define LOCK_SH 1
71 #    define LOCK_EX 2
72 #    define LOCK_UN 8
73 #  endif
74 #  define EACCELERATOR_FLOCK(FILE,OP)
75 #else
76 #  ifndef ZEND_WIN32
77 #    ifdef HAVE_FLOCK
78 #          include <sys/file.h>
79 #      define EACCELERATOR_FLOCK(FILE,OP) flock((FILE),(OP))
80 #    else
81 #      ifndef LOCK_SH
82 #        define LOCK_SH 1
83 #        define LOCK_EX 2
84 #        define LOCK_UN 8
85 #      endif
86 #      define EACCELERATOR_FLOCK(FILE,OP)
87 #    endif
88 #  else
89 #    define LOCK_SH 0
90 #    define LOCK_EX 1
91 #    define LOCK_UN 2
92 #    define EACCELERATOR_FLOCK(FILE,OP) {OVERLAPPED offset = {0,0,0,0,NULL};\
93                                    if ((OP) == LOCK_EX) {\
94                                      LockFileEx((HANDLE)_get_osfhandle(FILE), \
95                                        LOCKFILE_EXCLUSIVE_LOCK, 0,\
96                                        1, 0, &offset);\
97                                    } else if ((OP) == LOCK_SH) {\
98                                      LockFileEx((HANDLE)_get_osfhandle(FILE), \
99                                        0, 0,\
100                                        1, 0, &offset);\
101                                    } else if ((OP) == LOCK_UN) {\
102                                      UnlockFileEx((HANDLE)_get_osfhandle(FILE), \
103                                        0,\
104                                        1, 0, &offset);\
105                                    }}
106 #  endif
107 #endif
108
109 #if !defined(_INTPTR_T_DEFINED) && ZEND_WIN32
110         typedef intptr_t;
111         #define _INTPTR_T_DEFINED
112 #endif
113
114 #if !defined(ssize_t) && ZEND_WIN32
115         /* define ssize_t for Win32. */
116         #define ssize_t int
117 #endif
118
119 #ifdef HAVE_EACCELERATOR
120 #ifndef HAVE_EACCELERATOR_STANDALONE_LOADER
121
122 #include "mm.h"
123
124 #ifdef ZEND_WIN32
125 #  include <process.h>
126 #  ifndef S_ISREG
127 #    define S_ISREG(mode) (((mode)&S_IFMT) & S_IFREG)
128 #  endif
129 #  ifndef S_IRUSR
130 #    define S_IRUSR S_IREAD
131 #  endif
132 #  ifndef S_IWUSR
133 #    define S_IWUSR S_IWRITE
134 #  endif
135 #else
136 #  include <dirent.h>
137 #endif
138
139 #ifdef ZTS
140 #  define ZTS_LOCK()    tsrm_mutex_lock(ea_mutex)
141 #  define ZTS_UNLOCK()  tsrm_mutex_unlock(ea_mutex)
142 #else
143 #  define ZTS_LOCK()
144 #  define ZTS_UNLOCK()
145 #endif
146
147 #if defined(EACCELERATOR_PROTECT_SHM)
148 #  define EACCELERATOR_PROTECT()    do {mm_protect(eaccelerator_mm_instance->mm, MM_PROT_READ);} while(0)
149 #  define EACCELERATOR_UNPROTECT()  do {mm_protect(eaccelerator_mm_instance->mm, MM_PROT_READ|MM_PROT_WRITE);} while(0)
150 #else
151 #  define EACCELERATOR_PROTECT()
152 #  define EACCELERATOR_UNPROTECT()
153 #endif
154
155 #define EACCELERATOR_LOCK_RW()    do {ZTS_LOCK(); mm_lock(eaccelerator_mm_instance->mm, MM_LOCK_RW);} while(0)
156 #define EACCELERATOR_LOCK_RD()    do {ZTS_LOCK(); mm_lock(eaccelerator_mm_instance->mm, MM_LOCK_RD);} while(0)
157 #define EACCELERATOR_UNLOCK()     do {mm_unlock(eaccelerator_mm_instance->mm); ZTS_UNLOCK();} while(0)
158 #define EACCELERATOR_UNLOCK_RW()  EACCELERATOR_UNLOCK()
159 #define EACCELERATOR_UNLOCK_RD()  EACCELERATOR_UNLOCK()
160
161 #define EACCELERATOR_BLOCK_INTERRUPTIONS()   HANDLE_BLOCK_INTERRUPTIONS()
162 #define EACCELERATOR_UNBLOCK_INTERRUPTIONS() HANDLE_UNBLOCK_INTERRUPTIONS()
163
164 #define EACCELERATOR_HASH_LEVEL 2
165 #define EA_HASH_SIZE      512
166 #define EA_USER_HASH_SIZE 512
167
168 #define EA_HASH_MAX       (EA_HASH_SIZE-1)
169 #define EA_USER_HASH_MAX  (EA_USER_HASH_SIZE-1)
170
171 #define eaccelerator_malloc(size)        mm_malloc_lock(eaccelerator_mm_instance->mm, size)
172 #define eaccelerator_free(x)             mm_free_lock(eaccelerator_mm_instance->mm, x)
173 #define eaccelerator_malloc_nolock(size) mm_malloc_nolock(eaccelerator_mm_instance->mm, size)
174 #define eaccelerator_free_nolock(x)      mm_free_nolock(eaccelerator_mm_instance->mm, x)
175
176 #if (defined (__GNUC__) && __GNUC__ >= 2)
177 #define EACCELERATOR_PLATFORM_ALIGNMENT (__alignof__ (align_test))
178 #else
179 #define EACCELERATOR_PLATFORM_ALIGNMENT (sizeof(align_union))
180 #endif
181
182 #define EACCELERATOR_ALIGN(n) (n) = (void*)((((size_t)(n)-1) & ~(EACCELERATOR_PLATFORM_ALIGNMENT-1)) + EACCELERATOR_PLATFORM_ALIGNMENT)
183
184 #define MAX_DUP_STR_LEN 256
185
186 /******************************************************************************/
187
188 #endif /* HAVE_EACCELERATOR_STANDALONE_LOADER */
189
190 #ifndef offsetof
191 #  define offsetof(str,fld) ((size_t)&(((str*)NULL)->fld))
192 #endif
193
194 typedef struct _eaccelerator_op_array {
195         zend_uchar type;
196 #ifdef ZEND_ENGINE_2
197         zend_bool uses_this;
198 #else
199         zend_bool uses_globals;
200 #endif
201         zend_bool return_reference;
202 #ifdef ZEND_ENGINE_2
203         zend_uint num_args;
204         zend_uint required_num_args;
205         zend_arg_info *arg_info;
206         zend_bool pass_rest_by_reference;
207 #else
208         zend_uchar *arg_types;
209 #endif
210         char *function_name;
211 #ifdef ZEND_ENGINE_2
212         char *scope_name;
213         int scope_name_len;
214         zend_uint fn_flags;
215 #endif
216         zend_op *opcodes;
217         zend_uint last;
218 #ifdef ZEND_ENGINE_2_1
219         zend_compiled_variable *vars;
220     int last_var;
221 #endif
222         zend_uint T;
223         zend_brk_cont_element *brk_cont_array;
224         zend_uint last_brk_cont;
225 #ifdef ZEND_ENGINE_2
226         zend_try_catch_element *try_catch_array;
227         int last_try_catch;
228 #endif
229         HashTable *static_variables;
230         char *filename;
231 #ifdef ZEND_ENGINE_2
232         zend_uint line_start;
233         zend_uint line_end;
234 #ifdef INCLUDE_DOC_COMMENTS
235     char *doc_comment;
236     zend_uint doc_comment_len;
237 #endif
238 #endif
239 } eaccelerator_op_array;
240
241 typedef struct _eaccelerator_class_entry {
242         char type;
243         char *name;
244         zend_uint name_length;
245         char *parent;
246         HashTable function_table;
247         HashTable default_properties;
248 #ifdef ZEND_ENGINE_2
249         HashTable properties_info;
250 #  ifdef ZEND_ENGINE_2_1
251         HashTable default_static_members;
252 #  endif
253         HashTable *static_members;
254         HashTable constants_table;
255         zend_uint ce_flags;
256         zend_uint num_interfaces;
257
258         char *filename;
259         zend_uint line_start;
260         zend_uint line_end;
261 #ifdef INCLUDE_DOC_COMMENTS
262     char *doc_comment;
263     zend_uint doc_comment_len;
264 #endif
265 #endif
266 } eaccelerator_class_entry;
267
268 /*
269  * To cache functions and classes.
270  */
271 typedef struct _mm_fc_entry {
272         void *fc;
273         struct _mm_fc_entry *next;
274         int htablen;
275         char htabkey[1];                        /* must be last element */
276 } mm_fc_entry;
277
278 #ifndef HAVE_EACCELERATOR_STANDALONE_LOADER
279
280 /*
281  * A mm_cache_entry is a bucket for one PHP script file.
282  * Nested  functions and classes which defined in the file goes
283  * into the list of mm_fc_entry.
284  */
285 typedef struct _mm_cache_entry {
286         struct _mm_cache_entry *next;
287 #ifdef EACCELERATOR_USE_INODE
288         dev_t st_dev;                           /* file's device                     */
289         ino_t st_ino;                           /* file's inode                      */
290 #else
291         unsigned int hv;                        /* hash value                        */
292 #endif
293         off_t filesize;                         /* file size */
294         time_t mtime;                           /* file last modification time       */
295         time_t ttl;                                     /* expiration time                   */
296         int size;                                       /* entry size (bytes)                */
297         int nhits;                                      /* hits count                        */
298         int nreloads;                           /* count of reloads                  */
299         int use_cnt;                            /* how many processes uses the entry */
300         eaccelerator_op_array *op_array;        /* script's global scope code        */
301         mm_fc_entry *f_head;            /* list of nested functions          */
302         mm_fc_entry *c_head;            /* list of nested classes            */
303         zend_bool removed;                      /* the entry is scheduled to remove  */
304         char realfilename[1];           /* real file name (must be last el.) */
305 } mm_cache_entry;
306
307 /*
308  * bucket for user's cache
309  */
310 typedef struct _mm_user_cache_entry {
311         struct _mm_user_cache_entry *next;
312         unsigned int hv;                        /* hash value                  */
313         long ttl;                                       /* expiration time             */
314         long create;
315         int size;
316         zval value;                                     /* value                       */
317         char key[1];                            /* key value (must be last el) */
318 } mm_user_cache_entry;
319
320 /*
321  * Linked list of mm_cache_entry which are used by process/thread
322  */
323 typedef struct _mm_used_entry {
324         struct _mm_used_entry *next;
325         mm_cache_entry *entry;
326 } mm_used_entry;
327
328 /*
329  * Linked list of locks
330  */
331 typedef struct _mm_lock_entry {
332         struct _mm_lock_entry *next;
333         pid_t pid;
334 #ifdef ZTS
335         THREAD_T thread;
336 #endif
337         char key[1];
338 } mm_lock_entry;
339
340 typedef struct _mm_file_header {
341         char magic[8];                          /* "EACCELERATOR" */
342         int eaccelerator_version;
343         int zend_version;
344         int php_version;
345         int size;
346         time_t mtime;
347         unsigned int crc32;
348 } mm_file_header;
349
350 typedef struct {
351         MM *mm;
352         pid_t owner;
353         size_t total;
354         unsigned int hash_cnt;
355         unsigned int user_hash_cnt;
356         zend_bool enabled;
357         zend_bool optimizer_enabled;
358         unsigned int rem_cnt;
359         time_t last_prune;
360         mm_cache_entry *removed;
361         mm_lock_entry *locks;
362
363         mm_cache_entry *hash[EA_HASH_SIZE];
364         mm_user_cache_entry *user_hash[EA_USER_HASH_SIZE];
365 } eaccelerator_mm;
366
367 /*
368  * Where to cache
369  */
370 typedef enum _eaccelerator_cache_place {
371         eaccelerator_shm_and_disk,      /* in shm and in disk */
372         eaccelerator_shm,                       /* in shm, but if it is not possible then on disk */
373         eaccelerator_shm_only,          /* in shm only  */
374         eaccelerator_disk_only,         /* on disk only */
375         eaccelerator_none                       /* don't cache  */
376 } eaccelerator_cache_place;
377
378 typedef union align_union {
379   double d;
380   void *v;
381   int (*func)(int);
382   long l;
383 } align_union;
384
385 #ifdef ZEND_ENGINE_2_2
386 typedef union _align_test {
387   void *ptr;
388   double dbl;
389   long lng;
390 } align_test;
391 #endif
392
393 /******************************************************************************/
394
395 #ifdef ZTS
396 #  ifdef __APPLE__
397 /* Workaround to prevent 'multiple definitions of symbol' during build on OSX */
398 static MUTEX_T ea_mutex;
399 #  else
400 MUTEX_T ea_mutex;
401 #  endif
402 #endif
403
404 /* needed to compile eA as a static php module */
405 extern zend_module_entry eaccelerator_module_entry;
406 #define phpext_eaccelerator_ptr &eaccelerator_module_entry
407
408
409 void format_size (char *s, unsigned int size, int legend);
410 void eaccelerator_prune (time_t t);
411
412 int eaccelerator_lock (const char *key, int key_len TSRMLS_DC);
413 int eaccelerator_unlock (const char *key, int key_len TSRMLS_DC);
414
415 void *eaccelerator_malloc2 (size_t size TSRMLS_DC);
416
417 unsigned int eaccelerator_crc32 (const char *p, size_t n);
418 int eaccelerator_md5 (char *s, const char *prefix, const char *key TSRMLS_DC);
419
420 unsigned int hash_mm(const char *data, int len);
421
422 #  ifdef WITH_EACCELERATOR_OPTIMIZER
423 void eaccelerator_optimize (zend_op_array * op_array);
424 #  endif
425
426 #ifdef WITH_EACCELERATOR_ENCODER
427 PHP_FUNCTION (eaccelerator_encode);
428 #endif
429 #endif /* HAVE_EACCELERATOR_STANDALONE_LOADER */
430
431 #ifdef ZTS
432 #  define EAG(v) TSRMG(eaccelerator_globals_id, zend_eaccelerator_globals*, v)
433 #else
434 #  define EAG(v) (eaccelerator_globals.v)
435 #endif
436
437 /*
438  * conditional filter
439  */
440 typedef struct _mm_cond_entry {
441         char *str;
442         int len;
443         zend_bool not;
444         struct _mm_cond_entry *next;
445 } mm_cond_entry;
446
447 #ifdef WITH_EACCELERATOR_LOADER
448 zend_op_array *eaccelerator_load (char *src, int src_len TSRMLS_DC);
449 PHP_FUNCTION (eaccelerator_load);
450 PHP_FUNCTION (_eaccelerator_loader_file);
451 PHP_FUNCTION (_eaccelerator_loader_line);
452 #endif
453
454 /*
455  * Globals (different for each process/thread)
456  */
457 ZEND_BEGIN_MODULE_GLOBALS (eaccelerator)
458 void *used_entries;                             /* list of files which are used     */
459                                                                 /* by process/thread                */
460 zend_bool enabled;
461 zend_bool optimizer_enabled;
462 zend_bool compression_enabled;
463 zend_bool compiler;
464 zend_bool encoder;
465 zend_bool compress;
466 zend_bool compress_content;
467 zend_bool in_request;
468 zend_llist *content_headers;
469 long compress_level;
470 char *cache_dir;
471 char *eaccelerator_log_file;
472 char *name_space;
473 char *mem;
474 char *allowed_admin_path;
475 HashTable strings;
476 HashTable restored;
477 zend_class_entry *class_entry;
478 mm_cond_entry *cond_list;
479 zend_uint refcount_helper;
480 char hostname[32];
481 #ifdef WITH_EACCELERATOR_CRASH_DETECTION
482 #ifdef SIGSEGV
483 void (*original_sigsegv_handler) (int);
484 #endif
485 #ifdef SIGFPE
486 void (*original_sigfpe_handler) (int);
487 #endif
488 #ifdef SIGBUS
489 void (*original_sigbus_handler) (int);
490 #endif
491 #ifdef SIGILL
492 void (*original_sigill_handler) (int);
493 #endif
494 #ifdef SIGABRT
495 void (*original_sigabrt_handler) (int);
496 #endif
497 #endif
498 #ifdef DEBUG
499 int xpad;
500 int profile_level;
501 long self_time[256];
502 #endif
503 #ifdef WITH_EACCELERATOR_SESSIONS
504 char *session;
505 #endif
506 ZEND_END_MODULE_GLOBALS (eaccelerator)
507
508 ZEND_EXTERN_MODULE_GLOBALS (eaccelerator)
509
510 #define EACCELERATOR_EXTENSION_NAME "eAccelerator"
511 #define EACCELERATOR_LOADER_EXTENSION_NAME "eLoader"
512
513 #define EA_MAGIC "EACCELERATOR"
514
515 #define EA_ENCODER_VERSION   0x00000004
516 #define EA_ENCODER_END       0x00
517 #define EA_ENCODER_NAMESPACE 0x01
518 #define EA_ENCODER_CLASS     0x02
519 #define EA_ENCODER_FUNCTION  0x03
520
521 #define EACCELERATOR_VERSION_GUID   "PHPE8EDA1B6-806A-4851-B1C8-A6B4712F44FB"
522 #define EACCELERATOR_LOGO_GUID      "PHPE6F78DE9-13E4-4dee-8518-5FA2DACEA803"
523 #define EACCELERATOR_VERSION_STRING ("eAccelerator " EACCELERATOR_VERSION " (PHP " PHP_VERSION ")")
524
525 #endif          /* HAVE_EACCELERATOR */
526 #endif          /* #ifndef INCLUDED_EACCELERATOR_H */
Note: See TracBrowser for help on using the browser.