source: tags/2.0.0/xcache.h @ 899

Last change on this file since 899 was 899, checked in by moo, 2 years ago

bump version, updated release date

  • Property svn:eol-style set to native
File size: 12.3 KB
RevLine 
[1]1#ifndef __XCACHE_H
2#define __XCACHE_H
3#define XCACHE_NAME       "XCache"
[899]4#define XCACHE_VERSION    "2.0.0"
[1]5#define XCACHE_AUTHOR     "mOo"
[883]6#define XCACHE_COPYRIGHT  "Copyright (c) 2005-2012"
[1]7#define XCACHE_URL        "http://xcache.lighttpd.net"
[547]8#define XCACHE_WIKI_URL   XCACHE_URL "/wiki"
[1]9
10#include <php.h>
11#include <zend_compile.h>
12#include <zend_API.h>
[485]13#include <zend.h>
[1]14#include "php_ini.h"
15#include "zend_hash.h"
16
17#ifdef HAVE_CONFIG_H
18#include <config.h>
19#endif
[148]20#include "xc_shm.h"
[1]21#include "lock.h"
22
[165]23#define HAVE_INODE
[822]24#if !defined(ZEND_ENGINE_2_4) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4 || PHP_MAJOR_VERSION > 5)
[716]25#   define ZEND_ENGINE_2_4
[1]26#endif
[716]27#if !defined(ZEND_ENGINE_2_3) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 3 || defined(ZEND_ENGINE_2_4))
28#   define ZEND_ENGINE_2_3
29#endif
30#if !defined(ZEND_ENGINE_2_2) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 2 || defined(ZEND_ENGINE_2_3))
[78]31#   define ZEND_ENGINE_2_2
32#endif
[716]33#if !defined(ZEND_ENGINE_2_1) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 1 || defined(ZEND_ENGINE_2_2))
34#   define ZEND_ENGINE_2_1
[480]35#endif
[1]36
[19]37#define NOTHING
[1]38/* ZendEngine code Switcher */
39#ifndef ZEND_ENGINE_2
40#   define ZESW(v1, v2) v1
41#else
42#   define ZESW(v1, v2) v2
43#endif
[846]44#ifdef ZEND_ENGINE_2_4
[860]45#   define ZEND_24(pre24, v24) v24
[846]46#else
[860]47#   define ZEND_24(pre24, v24) pre24
[846]48#endif
[1]49
[550]50#ifdef do_alloca_with_limit
51#   define my_do_alloca(size, use_heap) do_alloca_with_limit(size, use_heap)
52#   define my_free_alloca(size, use_heap) free_alloca_with_limit(size, use_heap)
53#elif defined(ALLOCA_FLAG)
[485]54#   define my_do_alloca(size, use_heap) do_alloca(size, use_heap)
55#   define my_free_alloca(size, use_heap) free_alloca(size, use_heap)
56#else
57#   define my_do_alloca(size, use_heap) do_alloca(size)
58#   define my_free_alloca(size, use_heap) free_alloca(size)
59#   define ALLOCA_FLAG(x)
60#endif
[798]61#ifndef Z_ISREF
62#   define Z_ISREF(z) (z).is_ref
63#endif
[485]64#ifndef Z_SET_ISREF
[562]65#   define Z_SET_ISREF(z) (z).is_ref = 1
[485]66#endif
67#ifndef Z_UNSET_ISREF
[562]68#   define Z_UNSET_ISREF(z) (z).is_ref = 0
[485]69#endif
[798]70#ifndef Z_REFCOUNT
71#   define Z_REFCOUNT(z) (z).refcount
72#endif
[485]73#ifndef Z_SET_REFCOUNT
[562]74#   define Z_SET_REFCOUNT(z, rc) (z).refcount = rc
[485]75#endif
[491]76#ifndef IS_CONSTANT_TYPE_MASK
[649]77#   define IS_CONSTANT_TYPE_MASK (~IS_CONSTANT_INDEX)
[491]78#endif
[485]79
[263]80/* {{{ dirty fix for PHP 6 */
81#ifdef add_assoc_long_ex
82static inline void my_add_assoc_long_ex(zval *arg, char *key, uint key_len, long value)
83{
84    add_assoc_long_ex(arg, key, key_len, value);
85}
86#   undef add_assoc_long_ex
87#   define add_assoc_long_ex my_add_assoc_long_ex
88#endif
89#ifdef add_assoc_bool_ex
90static inline void my_add_assoc_bool_ex(zval *arg, char *key, uint key_len, zend_bool value)
91{
92    add_assoc_bool_ex(arg, key, key_len, value);
93}
94#   undef add_assoc_bool_ex
95#   define add_assoc_bool_ex my_add_assoc_bool_ex
96#endif
97#ifdef add_assoc_null_ex
98static inline void my_add_assoc_null_ex(zval *arg, char *key, uint key_len)
99{
100    add_assoc_null_ex(arg, key, key_len);
101}
102#   undef add_assoc_null_ex
103#   define add_assoc_null_ex my_add_assoc_null_ex
104#endif
[716]105
106#ifdef ZEND_ENGINE_2_4
107#   define Z_OP(op) (op)
108#   define Z_OP_CONSTANT(op) (op).literal->constant
109#   define Z_OP_TYPE(op) op##_##type
[769]110#   define Z_OP_TYPEOF_TYPE zend_uchar
[716]111
112#   define Z_CLASS_INFO(className) (className).info.user
113#else
114#   define Z_OP(op) (op).u
115#   define Z_OP_CONSTANT(op) (op).u.constant
116#   define Z_OP_TYPE(op) (op).op_type
[769]117#   define Z_OP_TYPEOF_TYPE int
[716]118typedef znode znode_op;
119
120#   define Z_CLASS_INFO(className) (className)
121#endif
122
[263]123/* }}} */
124
[1]125/* unicode */
126#ifdef IS_UNICODE
127#   define UNISW(text, unicode) unicode
128#else
129#   define UNISW(text, unicode) text
130#endif
131#define BUCKET_KEY_SIZE(b) \
132        (UNISW( \
133            (b)->nKeyLength, \
134                ((b)->key.type == IS_UNICODE) \
135                ? UBYTES(b->nKeyLength) \
136                : b->nKeyLength \
137                ))
[659]138#define BUCKET_KEY(b)      (UNISW((b)->arKey, (b)->key.arKey))
139#define BUCKET_KEY_S(b)    ZSTR_S(BUCKET_KEY(b))
140#define BUCKET_KEY_U(b)    ZSTR_U(BUCKET_KEY(b))
[200]141#define BUCKET_KEY_TYPE(b) (UNISW(IS_STRING,  (b)->key.type))
[2]142#ifdef IS_UNICODE
[104]143#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key.arKey)
[2]144#else
[11]145#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey)
[2]146#endif
[1]147
[823]148#ifdef ZEND_ENGINE_2_4
149#   define BUCKET_SIZE(b) (sizeof(Bucket) + BUCKET_KEY_SIZE(b))
150#else
151#   define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b))
152#endif
153
[1]154#ifndef IS_UNICODE
155typedef char *zstr;
[770]156typedef const char *const_zstr;
[846]157#ifdef ZEND_ENGINE_2_4
158typedef const char *const24_zstr;
159typedef const char *const24_str;
160#else
161typedef char *const24_zstr;
162typedef char *const24_str;
163#endif
164
[103]165#   define ZSTR_S(s)     (s)
166#   define ZSTR_U(s)     (s)
167#   define ZSTR_V(s)     (s)
168#   define ZSTR_PS(s)    (s)
169#   define ZSTR_PU(s)    (s)
170#   define ZSTR_PV(s)    (s)
[1]171#else
[770]172typedef const zstr const_zstr;
[103]173#   define ZSTR_S(zs)    ((zs).s)
174#   define ZSTR_U(zs)    ((zs).u)
175#   define ZSTR_V(zs)    ((zs).v)
176#   define ZSTR_PS(pzs)  ((pzs)->s)
177#   define ZSTR_PU(pzs)  ((pzs)->u)
178#   define ZSTR_PV(pzs)  ((pzs)->v)
[1]179#endif
180
[103]181#ifndef ZSTR
182#   define ZSTR(s)      (s)
183#endif
184
185#ifndef Z_UNIVAL
186#   define Z_UNIVAL(zval) (zval).value.str.val
187#   define Z_UNILEN(zval) (zval).value.str.len
188#endif
189
[1]190/* {{{ u hash wrapper */
191#ifndef IS_UNICODE
192#   define zend_u_hash_add(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
[860]193       zend_hash_add(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, pData, nDataSize, pDest)
[1]194
[506]195#   define zend_u_hash_quick_add(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
[860]196       zend_hash_quick_add(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, h, pData, nDataSize, pDest)
[506]197
[88]198#   define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
[860]199       zend_hash_update(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, pData, nDataSize, pDest)
[88]200
[506]201#   define zend_u_hash_quick_update(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
[860]202       zend_hash_quick_update(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, h, pData, nDataSize, pDest)
[506]203
[1]204#   define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
[860]205       zend_hash_find(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, pData)
[1]206
[200]207#   define zend_u_hash_quick_find(ht, type, arKey, nKeyLength, h, pData) \
[860]208       zend_hash_quick_find(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength, h, pData)
[200]209
[860]210#   define zend_u_hash_exists(ht, type, arKey, nKeyLength) \
211       zend_hash_exists(ht, ZEND_24((char *), NOTHING) arKey, nKeyLength)
212
[1]213#   define add_u_assoc_zval_ex(arg, type, key, key_len, value) \
214        add_assoc_zval_ex(arg, key, key_len, value)
215
[268]216#   define zend_u_is_auto_global(type, name, name_len) \
217        zend_is_auto_global(name, name_len)
[1]218#endif
219/* }}} */
220
221
222#define ECALLOC_N(x, n) ((x) = ecalloc(n, sizeof((x)[0])))
223#define ECALLOC_ONE(x) ECALLOC_N(x, 1)
224
225
226
227typedef ulong xc_hash_value_t;
228typedef struct {
229    int bits;
230    int size;
231    int mask;
232} xc_hash_t;
233
234/* the class entry type to be stored in class_table */
235typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t;
236
237/* xc_cest_t to (zend_class_entry*) */
238#define CestToCePtr(st) (ZESW(\
239            &(st), \
240            st \
241            ) )
242
243/* ZCEP=zend class entry ptr */
244#define ZCEP_REFCOUNT_PTR(pce) (ZESW( \
245            (pce)->refcount, \
246            &((pce)->refcount) \
247            ))
248
249#define ZCE_REFCOUNT_PTR(ce) ZCE_REFCOUNT_PTR(&ce)
250
251typedef zend_op_array *(zend_compile_file_t)(zend_file_handle *h, int type TSRMLS_DC);
252
[311]253typedef struct _xc_entry_t xc_entry_t;
254typedef struct _xc_entry_data_php_t xc_entry_data_php_t;
[1]255/* {{{ xc_cache_t */
[11]256typedef struct {
[1]257    int cacheid;
258    xc_hash_t  *hcache; /* hash to cacheid */
259
[11]260    time_t     compiling;
[1]261    zend_ulong misses;
262    zend_ulong hits;
263    zend_ulong clogs;
264    zend_ulong ooms;
[456]265    zend_ulong errors;
[1]266    xc_lock_t  *lck;
[851]267    xc_shm_t   *shm; /* which shm contains us */
268    xc_mem_t   *mem; /* which mem contains us */
[1]269
270    xc_entry_t **entries;
[32]271    int entries_count;
[311]272    xc_entry_data_php_t **phps;
273    int phps_count;
[1]274    xc_entry_t *deletes;
[32]275    int deletes_count;
[311]276    xc_hash_t  *hentry; /* hash settings to entry */
277    xc_hash_t  *hphp;   /* hash settings to php */
[114]278
279    time_t     last_gc_deletes;
280    time_t     last_gc_expires;
[522]281
282    time_t     hits_by_hour_cur_time;
283    zend_uint  hits_by_hour_cur_slot;
284    zend_ulong hits_by_hour[24];
285    time_t     hits_by_second_cur_time;
286    zend_uint  hits_by_second_cur_slot;
287    zend_ulong hits_by_second[5];
[1]288} xc_cache_t;
289/* }}} */
[832]290/* {{{ xc_op_array_info_detail_t */
291typedef struct {
292    zend_uint index;
293    zend_uint info;
294} xc_op_array_info_detail_t;
295/* }}} */
[662]296/* {{{ xc_op_array_info_t */
297typedef struct {
[721]298#ifdef ZEND_ENGINE_2_4
299    zend_uint literalinfo_cnt;
[832]300    xc_op_array_info_detail_t *literalinfos;
[721]301#else
[662]302    zend_uint oplineinfo_cnt;
[832]303    xc_op_array_info_detail_t *oplineinfos;
[721]304#endif
[662]305} xc_op_array_info_t;
306/* }}} */
[1]307/* {{{ xc_classinfo_t */
308typedef struct {
[14]309#ifdef IS_UNICODE
[846]310    zend_uchar   type;
[14]311#endif
[846]312    const24_zstr key;
313    zend_uint    key_size;
314    ulong        h;
315    zend_uint  methodinfo_cnt;
[662]316    xc_op_array_info_t *methodinfos;
[846]317    xc_cest_t    cest;
[548]318#ifndef ZEND_COMPILE_DELAYED_BINDING
[846]319    int          oplineno;
[548]320#endif
[1]321} xc_classinfo_t;
322/* }}} */
[95]323#ifdef HAVE_XCACHE_CONSTANT
324/* {{{ xc_constinfo_t */
325typedef struct {
326#ifdef IS_UNICODE
[846]327    zend_uchar    type;
[95]328#endif
[846]329    const24_zstr  key;
330    zend_uint     key_size;
331    ulong         h;
[95]332    zend_constant constant;
333} xc_constinfo_t;
334/* }}} */
335#endif
[1]336/* {{{ xc_funcinfo_t */
337typedef struct {
[14]338#ifdef IS_UNICODE
[846]339    zend_uchar     type;
[14]340#endif
[846]341    const24_zstr   key;
342    zend_uint      key_size;
343    ulong          h;
[662]344    xc_op_array_info_t op_array_info;
[1]345    zend_function func;
346} xc_funcinfo_t;
347/* }}} */
[268]348#ifdef ZEND_ENGINE_2_1
349/* {{{ xc_autoglobal_t */
350typedef struct {
351#ifdef IS_UNICODE
[846]352    zend_uchar   type;
[268]353#endif
[846]354    const24_zstr key;
355    zend_uint    key_len;
356    ulong        h;
[268]357} xc_autoglobal_t;
358/* }}} */
359#endif
[840]360typedef struct {
361    char digest[16];
362} xc_md5sum_t;
[496]363/* {{{ xc_compilererror_t */
364typedef struct {
[648]365    int type;
[496]366    uint lineno;
367    int error_len;
368    char *error;
369} xc_compilererror_t;
370/* }}} */
[1]371/* {{{ xc_entry_data_php_t */
[311]372struct _xc_entry_data_php_t {
373    xc_entry_data_php_t *next;
[854]374    xc_hash_value_t      hvalue;
[311]375
376    xc_md5sum_t md5;        /* md5sum of the source */
377    zend_ulong  refcount;   /* count of entries referencing to this data */
378
379    zend_ulong hits;        /* hits of this php */
380    size_t     size;
[1]381
[662]382    xc_op_array_info_t op_array_info;
[1]383    zend_op_array *op_array;
384
[95]385#ifdef HAVE_XCACHE_CONSTANT
386    zend_uint constinfo_cnt;
387    xc_constinfo_t *constinfos;
388#endif
389
[1]390    zend_uint funcinfo_cnt;
391    xc_funcinfo_t *funcinfos;
392
393    zend_uint classinfo_cnt;
394    xc_classinfo_t *classinfos;
[548]395#ifndef ZEND_COMPILE_DELAYED_BINDING
[212]396    zend_bool have_early_binding;
[548]397#endif
[268]398
399#ifdef ZEND_ENGINE_2_1
400    zend_uint autoglobal_cnt;
401    xc_autoglobal_t *autoglobals;
402#endif
[311]403
[496]404#ifdef E_STRICT
405    zend_uint compilererror_cnt;
406    xc_compilererror_t *compilererrors;
407#endif
408
[311]409    zend_bool  have_references;
410};
[1]411/* }}} */
412typedef zvalue_value xc_entry_name_t;
413/* {{{ xc_entry_t */
414struct _xc_entry_t {
[854]415    xc_entry_t *next;
[1]416
[854]417    size_t     size;
[851]418    time_t     ctime;           /* creation ctime of this entry */
419    time_t     atime;           /*   access atime of this entry */
420    time_t     dtime;           /*  deletion time of this entry */
[1]421    zend_ulong hits;
[851]422    long       ttl;
[1]423
424    xc_entry_name_t name;
[851]425};
[233]426
[851]427typedef struct {
428    xc_entry_t entry;
[854]429    xc_entry_data_php_t *php;
[851]430
431    zend_ulong refcount;    /* count of php instances holding this entry */
432    time_t file_mtime;
[859]433    size_t file_size;
[311]434#ifdef HAVE_INODE
[851]435    int file_device;
436    int file_inode;
[311]437#endif
[684]438
439    int    filepath_len;
[860]440    ZEND_24(NOTHING, const) char *filepath;
[684]441    int    dirpath_len;
442    char  *dirpath;
443#ifdef IS_UNICODE
[851]444    int    ufilepath_len;
[684]445    UChar *ufilepath;
[851]446    int    udirpath_len;
[684]447    UChar *udirpath;
448#endif
[851]449} xc_entry_php_t;
[855]450
[854]451typedef struct {
452    xc_entry_t entry;
[866]453#ifdef IS_UNICODE
454    zend_uchar name_type;
455#endif
[854]456    zval      *value;
457    zend_bool  have_references;
458} xc_entry_var_t;
459/* }}} */
460typedef struct xc_entry_hash_t { /* {{{ */
[859]461    xc_hash_value_t cacheid;
[854]462    xc_hash_value_t entryslotid;
463} xc_entry_hash_t;
464/* }}} */
[859]465typedef struct xc_compiler_t { /* {{{ */
466    const char *filename;
[870]467    size_t filename_len;
[859]468    const char *opened_path;
469    char opened_path_buffer[MAXPATHLEN];
[1]470
[859]471    xc_entry_hash_t entry_hash;
472    xc_entry_php_t new_entry;
473    xc_entry_data_php_t new_php;
474} xc_compiler_t;
475/* }}} */
476
[1]477extern zend_module_entry xcache_module_entry;
478#define phpext_xcache_ptr &xcache_module_entry
479
480int xc_is_rw(const void *p);
481int xc_is_ro(const void *p);
482int xc_is_shm(const void *p);
[662]483/* {{{ xc_gc_op_array_t */
484typedef struct {
485#ifdef ZEND_ENGINE_2
486    zend_uint num_args;
487    zend_arg_info *arg_info;
488#endif
489    zend_op *opcodes;
490} xc_gc_op_array_t;
491/* }}} */
492void xc_gc_add_op_array(xc_gc_op_array_t *gc_op_array TSRMLS_DC);
[851]493void xc_fix_op_array_info(const xc_entry_php_t *xce, const xc_entry_data_php_t *php, zend_op_array *op_array, int shallow_copy, const xc_op_array_info_t *op_array_info TSRMLS_DC);
[1]494
495#endif /* __XCACHE_H */
Note: See TracBrowser for help on using the repository browser.