root/eaccelerator/tags/0.9.4/eaccelerator.h

Revision 140, 14.7 kB (checked in by zoeloelip, 3 years ago)

* Disabled the cache dir check, to much people complaining
* fixed eLoader

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 /*
2    +----------------------------------------------------------------------+
3    | eAccelerator project                                                 |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 2004 - 2005 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    | Author(s): Dmitry Stogov <dstogov@users.sourceforge.net>             |
26    |            Everaldo Canuto <everaldo_canuto@yahoo.com.br>            |
27    +----------------------------------------------------------------------+
28    $Id$
29 */
30
31 #ifndef INCLUDED_EACCELERATOR_H
32 #define INCLUDED_EACCELERATOR_H
33
34 #include "php.h"
35 #include "zend.h"
36 #include "zend_API.h"
37 #include "zend_extensions.h"
38
39 #if !defined(ZEND_WIN32) && defined(HAVE_CONFIG_H)
40 #  if ZEND_MODULE_API_NO >= 20001222
41 #    include "config.h"
42 #  else
43 #    include "php_config.h"
44 #  endif
45 #endif
46
47 /* fixes compile errors on php5.1 */
48 #ifdef STR_EMPTY_ALLOC
49 #define empty_string STR_EMPTY_ALLOC()
50 #endif
51
52 #if !defined(ZEND_WIN32) && defined(WITH_EACCELERATOR_USE_INODE)
53 /* UnDefine if your filesystem doesn't support inodes */
54 #  define EACCELERATOR_USE_INODE
55 #endif
56
57 #ifdef WITH_EACCELERATOR_CRASH_DETECTION
58 #  include <signal.h>
59 #endif
60
61 #define EACCELERATOR_MM_FILE "/tmp/eaccelerator"
62
63 #ifdef HAVE_EACCELERATOR
64 #ifndef HAVE_EACCELERATOR_STANDALONE_LOADER
65
66 #include "mm.h"
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 #ifdef ZEND_WIN32
110 #  include <process.h>
111 #  ifndef S_ISREG
112 #    define S_ISREG(mode) (((mode)&S_IFMT) & S_IFREG)
113 #  endif
114 #  ifndef S_IRUSR
115 #    define S_IRUSR S_IREAD
116 #  endif
117 #  ifndef S_IWUSR
118 #    define S_IWUSR S_IWRITE
119 #  endif
120 #else
121 #  include <dirent.h>
122 #endif
123
124 #ifdef ZTS
125 #  define ZTS_LOCK()    tsrm_mutex_lock(mm_mutex)
126 #  define ZTS_UNLOCK()  tsrm_mutex_unlock(mm_mutex)
127 #else
128 #  define ZTS_LOCK()
129 #  define ZTS_UNLOCK()
130 #endif
131
132 #if defined(EACCELERATOR_PROTECT_SHM)
133 #  define EACCELERATOR_PROTECT()    do {mm_protect(eaccelerator_mm_instance->mm, MM_PROT_READ);} while(0)
134 #  define EACCELERATOR_UNPROTECT()  do {mm_protect(eaccelerator_mm_instance->mm, MM_PROT_READ|MM_PROT_WRITE);} while(0)
135 #else
136 #  define EACCELERATOR_PROTECT()
137 #  define EACCELERATOR_UNPROTECT()
138 #endif
139
140 #define EACCELERATOR_LOCK_RW()    do {ZTS_LOCK(); mm_lock(eaccelerator_mm_instance->mm, MM_LOCK_RW);} while(0)
141 #define EACCELERATOR_LOCK_RD()    do {ZTS_LOCK(); mm_lock(eaccelerator_mm_instance->mm, MM_LOCK_RD);} while(0)
142 #define EACCELERATOR_UNLOCK()     do {mm_unlock(eaccelerator_mm_instance->mm); ZTS_UNLOCK();} while(0)
143 #define EACCELERATOR_UNLOCK_RW()  EACCELERATOR_UNLOCK()
144 #define EACCELERATOR_UNLOCK_RD()  EACCELERATOR_UNLOCK()
145
146 #define EACCELERATOR_BLOCK_INTERRUPTIONS()   HANDLE_BLOCK_INTERRUPTIONS()
147 #define EACCELERATOR_UNBLOCK_INTERRUPTIONS() HANDLE_UNBLOCK_INTERRUPTIONS()
148
149 #define MM_HASH_SIZE      256
150 #define MM_USER_HASH_SIZE 256
151 #define MM_HASH_MAX       (MM_HASH_SIZE-1)
152 #define MM_USER_HASH_MAX  (MM_USER_HASH_SIZE-1)
153
154 #define eaccelerator_malloc(size)        mm_malloc_lock(eaccelerator_mm_instance->mm, size)
155 #define eaccelerator_free(x)             mm_free_lock(eaccelerator_mm_instance->mm, x)
156 #define eaccelerator_malloc_nolock(size) mm_malloc_nolock(eaccelerator_mm_instance->mm, size)
157 #define eaccelerator_free_nolock(x)      mm_free_nolock(eaccelerator_mm_instance->mm, x)
158
159 #if (defined (__GNUC__) && __GNUC__ >= 2)
160 #define EACCELERATOR_PLATFORM_ALIGNMENT (__alignof__ (align_test))
161 #else
162 #define EACCELERATOR_PLATFORM_ALIGNMENT (sizeof(align_union))
163 #endif
164
165 #define EACCELERATOR_ALIGN(n) (n) = (void*)((((size_t)(n)-1) & ~(EACCELERATOR_PLATFORM_ALIGNMENT-1)) + EACCELERATOR_PLATFORM_ALIGNMENT)
166
167 #define MAX_DUP_STR_LEN 256
168
169 /******************************************************************************/
170
171 #endif /* HAVE_EACCELERATOR_STANDALONE_LOADER */
172
173 #ifndef offsetof
174 #  define offsetof(str,fld) ((size_t)&(((str*)NULL)->fld))
175 #endif
176
177 typedef struct _eaccelerator_op_array {
178         zend_uchar type;
179 #ifdef ZEND_ENGINE_2
180         zend_bool uses_this;
181 #else
182         zend_bool uses_globals;
183 #endif
184         zend_bool return_reference;
185 #ifdef ZEND_ENGINE_2
186         zend_uint num_args;
187         zend_uint required_num_args;
188         zend_arg_info *arg_info;
189         zend_bool pass_rest_by_reference;
190 #else
191         zend_uchar *arg_types;
192 #endif
193         char *function_name;
194         char *function_name_lc;
195 #ifdef ZEND_ENGINE_2
196         char *scope_name;
197         int scope_name_len;
198         zend_uint fn_flags;
199 #endif
200         zend_op *opcodes;
201         zend_uint last;
202         zend_uint T;
203         zend_brk_cont_element *brk_cont_array;
204         zend_uint last_brk_cont;
205 #ifdef ZEND_ENGINE_2
206         zend_try_catch_element *try_catch_array;
207         int last_try_catch;
208 #endif
209         HashTable *static_variables;
210         char *filename;
211 #ifdef ZEND_ENGINE_2
212         zend_uint line_start;
213         zend_uint line_end;
214         char *doc_comment;
215         zend_uint doc_comment_len;
216 #endif
217 } eaccelerator_op_array;
218
219 typedef struct _eaccelerator_class_entry {
220         char type;
221         char *name;
222         char *name_lc;
223         uint name_length;
224         char *parent;
225         HashTable function_table;
226         HashTable default_properties;
227 #ifdef ZEND_ENGINE_2
228         zend_uint ce_flags;
229         HashTable *static_members;
230         HashTable properties_info;
231         HashTable constants_table;
232         zend_uint num_interfaces;
233         char **interfaces;
234         zend_class_iterator_funcs iterator_funcs;
235
236          zend_object_value (*create_object) (zend_class_entry *
237                                                                                  class_type TSRMLS_DC);
238         zend_object_iterator *(*get_iterator) (zend_class_entry * ce,
239                                                                                    zval * object TSRMLS_DC);
240         int (*interface_gets_implemented) (zend_class_entry * iface, zend_class_entry * class_type TSRMLS_DC);  /* a class implements this interface */
241
242         char *filename;
243         zend_uint line_start;
244         zend_uint line_end;
245         char *doc_comment;
246         zend_uint doc_comment_len;
247 #endif
248 } eaccelerator_class_entry;
249
250 /*
251  * To cache functions and classes.
252  */
253 typedef struct _mm_fc_entry {
254         void *fc;
255         struct _mm_fc_entry *next;
256         int htablen;
257         char htabkey[1];                        /* must be last element */
258 } mm_fc_entry;
259
260 #ifndef HAVE_EACCELERATOR_STANDALONE_LOADER
261
262 /*
263  * A mm_cache_entry is a bucket for one PHP script file.
264  * Nested  functions and classes which defined in the file goes
265  * into the list of mm_fc_entry.
266  */
267 typedef struct _mm_cache_entry {
268         struct _mm_cache_entry *next;
269 #ifdef EACCELERATOR_USE_INODE
270         dev_t st_dev;                           /* file's device                     */
271         ino_t st_ino;                           /* file's inode                      */
272 #else
273         unsigned int hv;                        /* hash value                        */
274 #endif
275         off_t filesize;                         /* file size */
276         time_t mtime;                           /* file last modification time       */
277         time_t ttl;                                     /* expiration time                   */
278         int size;                                       /* entry size (bytes)                */
279         int nhits;                                      /* hits count                        */
280         int nreloads;                           /* count of reloads                  */
281         int use_cnt;                            /* how many processes uses the entry */
282         eaccelerator_op_array *op_array;        /* script's global scope code        */
283         mm_fc_entry *f_head;            /* list of nested functions          */
284         mm_fc_entry *c_head;            /* list of nested classes            */
285         zend_bool removed;                      /* the entry is scheduled to remove  */
286         char realfilename[1];           /* real file name (must be last el.) */
287 } mm_cache_entry;
288
289 /*
290  * bucket for user's cache
291  */
292 typedef struct _mm_user_cache_entry {
293         struct _mm_user_cache_entry *next;
294         unsigned int hv;                        /* hash value                  */
295         long ttl;                                       /* expiration time             */
296         int size;
297         zval value;                                     /* value                       */
298         char key[1];                            /* key value (must be last el) */
299 } mm_user_cache_entry;
300
301 /*
302  * Linked list of mm_cache_entry which are used by process/thread
303  */
304 typedef struct _mm_used_entry {
305         struct _mm_used_entry *next;
306         mm_cache_entry *entry;
307 } mm_used_entry;
308
309 /*
310  * Linked list of locks
311  */
312 typedef struct _mm_lock_entry {
313         struct _mm_lock_entry *next;
314         pid_t pid;
315 #ifdef ZTS
316         THREAD_T thread;
317 #endif
318         char key[1];
319 } mm_lock_entry;
320
321 typedef struct _mm_file_header {
322         char magic[8];                          /* "EACCELERATOR" */
323         int eaccelerator_version;
324         int zend_version;
325         int php_version;
326         int size;
327         time_t mtime;
328         unsigned int crc32;
329 } mm_file_header;
330
331 typedef struct {
332         MM *mm;
333         pid_t owner;
334         size_t total;
335         unsigned int hash_cnt;
336         unsigned int user_hash_cnt;
337         zend_bool enabled;
338         zend_bool optimizer_enabled;
339         unsigned int rem_cnt;
340         time_t last_prune;
341         mm_cache_entry *removed;
342         mm_lock_entry *locks;
343
344         mm_cache_entry *hash[MM_HASH_SIZE];
345         mm_user_cache_entry *user_hash[MM_USER_HASH_SIZE];
346 } eaccelerator_mm;
347
348 /*
349  * Where to cache
350  */
351 typedef enum _eaccelerator_cache_place {
352         eaccelerator_shm_and_disk,      /* in shm and in disk */
353         eaccelerator_shm,                       /* in shm, but if it is not possible then on disk */
354         eaccelerator_shm_only,          /* in shm only  */
355         eaccelerator_disk_only,         /* on disk only */
356         eaccelerator_none                       /* don't cache  */
357 } eaccelerator_cache_place;
358
359 typedef union align_union {
360   double d;
361   void *v;
362   int (*func)(int);
363   long l;
364 } align_union;
365
366 /******************************************************************************/
367
368 #ifdef ZTS
369 MUTEX_T mm_mutex;
370 #endif
371
372 /* needed to compile eA as a static php module */
373 extern zend_module_entry eaccelerator_module_entry;
374 #define phpext_eaccelerator_ptr &eaccelerator_module_entry
375
376
377 void format_size (char *s, unsigned int size, int legend);
378 void eaccelerator_prune (time_t t);
379
380 int eaccelerator_lock (const char *key, int key_len TSRMLS_DC);
381 int eaccelerator_unlock (const char *key, int key_len TSRMLS_DC);
382
383 void *eaccelerator_malloc2 (size_t size TSRMLS_DC);
384
385 unsigned int eaccelerator_crc32 (const char *p, size_t n);
386 int eaccelerator_md5 (char *s, const char *prefix, const char *key TSRMLS_DC);
387
388 void calc_zval (zval * z TSRMLS_DC);
389 void store_zval (zval * z TSRMLS_DC);
390 void fixup_zval (zval * z TSRMLS_DC);
391 void restore_zval (zval * TSRMLS_DC);
392
393 unsigned int hash_mm(const char *data, int len);
394
395 #  ifdef WITH_EACCELERATOR_OPTIMIZER
396 void eaccelerator_optimize (zend_op_array * op_array);
397 #  endif
398
399 #ifdef WITH_EACCELERATOR_ENCODER
400 PHP_FUNCTION (eaccelerator_encode);
401 #endif
402 #endif /* HAVE_EACCELERATOR_STANDALONE_LOADER */
403
404 #ifdef ZTS
405 #  define EAG(v) TSRMG(eaccelerator_globals_id, zend_eaccelerator_globals*, v)
406 #else
407 #  define EAG(v) (eaccelerator_globals.v)
408 #endif
409
410 /*
411  * conditional filter
412  */
413 typedef struct _mm_cond_entry {
414         char *str;
415         int len;
416         zend_bool not;
417         struct _mm_cond_entry *next;
418 } mm_cond_entry;
419
420 #ifdef WITH_EACCELERATOR_LOADER
421 zend_op_array *eaccelerator_load (char *src, int src_len TSRMLS_DC);
422 PHP_FUNCTION (eaccelerator_load);
423 PHP_FUNCTION (_eaccelerator_loader_file);
424 PHP_FUNCTION (_eaccelerator_loader_line);
425 #endif
426
427 /*
428  * Globals (different for each process/thread)
429  */
430 ZEND_BEGIN_MODULE_GLOBALS (eaccelerator)
431 void *used_entries;                             /* list of files which are used     */
432                                                                 /* by process/thread                */
433 zend_bool enabled;
434 zend_bool optimizer_enabled;
435 zend_bool compression_enabled;
436 zend_bool compiler;
437 zend_bool encoder;
438 zend_bool compress;
439 zend_bool compress_content;
440 zend_bool in_request;
441 zend_llist *content_headers;
442 long compress_level;
443 char *cache_dir;
444 char *eaccelerator_log_file;
445 char *name_space;
446 char *mem;
447 HashTable strings;
448 zend_class_entry *class_entry;
449 mm_cond_entry *cond_list;
450 zend_uint refcount_helper;
451 char hostname[32];
452 #ifdef WITH_EACCELERATOR_CRASH_DETECTION
453 #ifdef SIGSEGV
454 void (*original_sigsegv_handler) (int);
455 #endif
456 #ifdef SIGFPE
457 void (*original_sigfpe_handler) (int);
458 #endif
459 #ifdef SIGBUS
460 void (*original_sigbus_handler) (int);
461 #endif
462 #ifdef SIGILL
463 void (*original_sigill_handler) (int);
464 #endif
465 #ifdef SIGABRT
466 void (*original_sigabrt_handler) (int);
467 #endif
468 #endif
469 #ifdef DEBUG
470 int xpad;
471 int profile_level;
472 long self_time[256];
473 #endif
474 #ifdef WITH_EACCELERATOR_SESSIONS
475 char *session;
476 #endif
477 ZEND_END_MODULE_GLOBALS (eaccelerator)
478
479 ZEND_EXTERN_MODULE_GLOBALS (eaccelerator)
480
481 #define EACCELERATOR_EXTENSION_NAME "eAccelerator"
482 #define EACCELERATOR_LOADER_EXTENSION_NAME "eLoader"
483
484 #define EA_ENCODER_VERSION   0x00000004
485 #define EA_ENCODER_END       0x00
486 #define EA_ENCODER_NAMESPACE 0x01
487 #define EA_ENCODER_CLASS     0x02
488 #define EA_ENCODER_FUNCTION  0x03
489
490 #define EACCELERATOR_VERSION_GUID   "PHPE8EDA1B6-806A-4851-B1C8-A6B4712F44FB"
491 #define EACCELERATOR_LOGO_GUID      "PHPE6F78DE9-13E4-4dee-8518-5FA2DACEA803"
492 #define EACCELERATOR_VERSION_STRING ("eAccelerator " EACCELERATOR_VERSION " (PHP " PHP_VERSION ")")
493
494 #endif          /* HAVE_EACCELERATOR */
495 #endif          /* #ifndef INCLUDED_EACCELERATOR_H */
Note: See TracBrowser for help on using the browser.