source: trunk/xcache.h @ 609

Last change on this file since 609 was 609, checked in by moo, 5 years ago

bump year

  • Property svn:eol-style set to native
File size: 9.7 KB
RevLine 
[1]1#ifndef __XCACHE_H
2#define __XCACHE_H
3#define XCACHE_NAME       "XCache"
[309]4#define XCACHE_VERSION    "2.0.0-dev"
[1]5#define XCACHE_AUTHOR     "mOo"
[609]6#define XCACHE_COPYRIGHT  "Copyright (c) 2005-2009"
[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
[1]24#if !defined(ZEND_ENGINE_2_1) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1 || PHP_MAJOR_VERSION > 5)
25#   define ZEND_ENGINE_2_1
26#endif
[78]27#if !defined(ZEND_ENGINE_2_2) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2 || PHP_MAJOR_VERSION > 5)
28#   define ZEND_ENGINE_2_2
29#endif
[480]30#if !defined(ZEND_ENGINE_2_3) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3 || PHP_MAJOR_VERSION > 5)
31#   define ZEND_ENGINE_2_3
32#endif
[1]33
[19]34#define NOTHING
[1]35/* ZendEngine code Switcher */
36#ifndef ZEND_ENGINE_2
37#   define ZESW(v1, v2) v1
38#else
39#   define ZESW(v1, v2) v2
40#endif
41
[550]42#ifdef do_alloca_with_limit
43#   define my_do_alloca(size, use_heap) do_alloca_with_limit(size, use_heap)
44#   define my_free_alloca(size, use_heap) free_alloca_with_limit(size, use_heap)
45#elif defined(ALLOCA_FLAG)
[485]46#   define my_do_alloca(size, use_heap) do_alloca(size, use_heap)
47#   define my_free_alloca(size, use_heap) free_alloca(size, use_heap)
48#else
49#   define my_do_alloca(size, use_heap) do_alloca(size)
50#   define my_free_alloca(size, use_heap) free_alloca(size)
51#   define ALLOCA_FLAG(x)
52#endif
53#ifndef Z_SET_ISREF
[562]54#   define Z_SET_ISREF(z) (z).is_ref = 1
[485]55#endif
56#ifndef Z_UNSET_ISREF
[562]57#   define Z_UNSET_ISREF(z) (z).is_ref = 0
[485]58#endif
59#ifndef Z_SET_REFCOUNT
[562]60#   define Z_SET_REFCOUNT(z, rc) (z).refcount = rc
[485]61#endif
[491]62#ifndef IS_CONSTANT_TYPE_MASK
63#   define IS_CONSTANT_TYPE_MASK 0xf
64#endif
[485]65
[263]66/* {{{ dirty fix for PHP 6 */
67#ifdef add_assoc_long_ex
68static inline void my_add_assoc_long_ex(zval *arg, char *key, uint key_len, long value)
69{
70    add_assoc_long_ex(arg, key, key_len, value);
71}
72#   undef add_assoc_long_ex
73#   define add_assoc_long_ex my_add_assoc_long_ex
74#endif
75#ifdef add_assoc_bool_ex
76static inline void my_add_assoc_bool_ex(zval *arg, char *key, uint key_len, zend_bool value)
77{
78    add_assoc_bool_ex(arg, key, key_len, value);
79}
80#   undef add_assoc_bool_ex
81#   define add_assoc_bool_ex my_add_assoc_bool_ex
82#endif
83#ifdef add_assoc_null_ex
84static inline void my_add_assoc_null_ex(zval *arg, char *key, uint key_len)
85{
86    add_assoc_null_ex(arg, key, key_len);
87}
88#   undef add_assoc_null_ex
89#   define add_assoc_null_ex my_add_assoc_null_ex
90#endif
91/* }}} */
92
[1]93/* unicode */
94#ifdef IS_UNICODE
95#   define UNISW(text, unicode) unicode
96#else
97#   define UNISW(text, unicode) text
98#endif
99#define BUCKET_KEY_SIZE(b) \
100        (UNISW( \
101            (b)->nKeyLength, \
102                ((b)->key.type == IS_UNICODE) \
103                ? UBYTES(b->nKeyLength) \
104                : b->nKeyLength \
105                ))
[200]106#define BUCKET_KEY_S(b)    (UNISW((b)->arKey, (b)->key.arKey.s))
107#define BUCKET_KEY_U(b)    (UNISW((b)->arKey, (b)->key.arKey.u))
108#define BUCKET_KEY_TYPE(b) (UNISW(IS_STRING,  (b)->key.type))
[2]109#ifdef IS_UNICODE
[104]110#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key.arKey)
[2]111#else
[11]112#   define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey)
[2]113#endif
[1]114#define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b))
115
116#ifndef IS_UNICODE
117typedef char *zstr;
[103]118#   define ZSTR_S(s)     (s)
119#   define ZSTR_U(s)     (s)
120#   define ZSTR_V(s)     (s)
121#   define ZSTR_PS(s)    (s)
122#   define ZSTR_PU(s)    (s)
123#   define ZSTR_PV(s)    (s)
[1]124#else
[103]125#   define ZSTR_S(zs)    ((zs).s)
126#   define ZSTR_U(zs)    ((zs).u)
127#   define ZSTR_V(zs)    ((zs).v)
128#   define ZSTR_PS(pzs)  ((pzs)->s)
129#   define ZSTR_PU(pzs)  ((pzs)->u)
130#   define ZSTR_PV(pzs)  ((pzs)->v)
[1]131#endif
132
[103]133#ifndef ZSTR
134#   define ZSTR(s)      (s)
135#endif
136
137#ifndef Z_UNIVAL
138#   define Z_UNIVAL(zval) (zval).value.str.val
139#   define Z_UNILEN(zval) (zval).value.str.len
140#endif
141
[1]142/* {{{ u hash wrapper */
143#ifndef IS_UNICODE
144#   define zend_u_hash_add(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
145       zend_hash_add(ht, arKey, nKeyLength, pData, nDataSize, pDest)
146
[506]147#   define zend_u_hash_quick_add(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
148       zend_hash_quick_add(ht, arKey, nKeyLength, h, pData, nDataSize, pDest)
149
[88]150#   define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \
151       zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest)
152
[506]153#   define zend_u_hash_quick_update(ht, type, arKey, nKeyLength, h, pData, nDataSize, pDest) \
154       zend_hash_quick_update(ht, arKey, nKeyLength, h, pData, nDataSize, pDest)
155
[1]156#   define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \
157       zend_hash_find(ht, arKey, nKeyLength, pData)
158
[200]159#   define zend_u_hash_quick_find(ht, type, arKey, nKeyLength, h, pData) \
160       zend_hash_quick_find(ht, arKey, nKeyLength, h, pData)
161
[1]162#   define add_u_assoc_zval_ex(arg, type, key, key_len, value) \
163        add_assoc_zval_ex(arg, key, key_len, value)
164
[268]165#   define zend_u_is_auto_global(type, name, name_len) \
166        zend_is_auto_global(name, name_len)
[1]167#endif
168/* }}} */
169
170
171#define ECALLOC_N(x, n) ((x) = ecalloc(n, sizeof((x)[0])))
172#define ECALLOC_ONE(x) ECALLOC_N(x, 1)
173
174
175
176typedef ulong xc_hash_value_t;
177typedef struct {
178    int bits;
179    int size;
180    int mask;
181} xc_hash_t;
182
183/* the class entry type to be stored in class_table */
184typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t;
185
186/* xc_cest_t to (zend_class_entry*) */
187#define CestToCePtr(st) (ZESW(\
188            &(st), \
189            st \
190            ) )
191
192/* ZCEP=zend class entry ptr */
193#define ZCEP_REFCOUNT_PTR(pce) (ZESW( \
194            (pce)->refcount, \
195            &((pce)->refcount) \
196            ))
197
198#define ZCE_REFCOUNT_PTR(ce) ZCE_REFCOUNT_PTR(&ce)
199
200typedef zend_op_array *(zend_compile_file_t)(zend_file_handle *h, int type TSRMLS_DC);
201
[311]202typedef struct _xc_entry_t xc_entry_t;
203typedef struct _xc_entry_data_php_t xc_entry_data_php_t;
[1]204/* {{{ xc_cache_t */
[11]205typedef struct {
[1]206    int cacheid;
207    xc_hash_t  *hcache; /* hash to cacheid */
208
[11]209    time_t     compiling;
[1]210    zend_ulong misses;
211    zend_ulong hits;
212    zend_ulong clogs;
213    zend_ulong ooms;
[456]214    zend_ulong errors;
[1]215    xc_lock_t  *lck;
216    xc_shm_t   *shm; /* to which shm contains us */
217    xc_mem_t   *mem; /* to which mem contains us */
218
219    xc_entry_t **entries;
[32]220    int entries_count;
[311]221    xc_entry_data_php_t **phps;
222    int phps_count;
[1]223    xc_entry_t *deletes;
[32]224    int deletes_count;
[311]225    xc_hash_t  *hentry; /* hash settings to entry */
226    xc_hash_t  *hphp;   /* hash settings to php */
[114]227
228    time_t     last_gc_deletes;
229    time_t     last_gc_expires;
[522]230
231    time_t     hits_by_hour_cur_time;
232    zend_uint  hits_by_hour_cur_slot;
233    zend_ulong hits_by_hour[24];
234    time_t     hits_by_second_cur_time;
235    zend_uint  hits_by_second_cur_slot;
236    zend_ulong hits_by_second[5];
[1]237} xc_cache_t;
238/* }}} */
239/* {{{ xc_classinfo_t */
240typedef struct {
[14]241#ifdef IS_UNICODE
242    zend_uchar type;
243#endif
[103]244    zstr      key;
[1]245    zend_uint key_size;
[506]246    ulong     h;
[1]247    xc_cest_t cest;
[548]248#ifndef ZEND_COMPILE_DELAYED_BINDING
[212]249    int       oplineno;
[548]250#endif
[1]251} xc_classinfo_t;
252/* }}} */
[95]253#ifdef HAVE_XCACHE_CONSTANT
254/* {{{ xc_constinfo_t */
255typedef struct {
256#ifdef IS_UNICODE
257    zend_uchar type;
258#endif
[103]259    zstr      key;
[95]260    zend_uint key_size;
[506]261    ulong     h;
[95]262    zend_constant constant;
263} xc_constinfo_t;
264/* }}} */
265#endif
[1]266/* {{{ xc_funcinfo_t */
267typedef struct {
[14]268#ifdef IS_UNICODE
269    zend_uchar type;
270#endif
[103]271    zstr      key;
[1]272    zend_uint key_size;
[506]273    ulong     h;
[1]274    zend_function func;
275} xc_funcinfo_t;
276/* }}} */
[268]277#ifdef ZEND_ENGINE_2_1
278/* {{{ xc_autoglobal_t */
279typedef struct {
280#ifdef IS_UNICODE
281    zend_uchar type;
282#endif
283    zstr       key;
284    zend_uint  key_len;
[506]285    ulong      h;
[268]286} xc_autoglobal_t;
287/* }}} */
288#endif
[1]289typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t;
[311]290typedef char xc_md5sum_t[16];
[496]291/* {{{ xc_compilererror_t */
292typedef struct {
293    uint lineno;
294    int error_len;
295    char *error;
296} xc_compilererror_t;
297/* }}} */
[1]298/* {{{ xc_entry_data_php_t */
[311]299struct _xc_entry_data_php_t {
300    xc_hash_value_t hvalue; /* hash of md5 */
301    xc_entry_data_php_t *next;
302    xc_cache_t *cache;      /* which cache it's on */
303
304    xc_md5sum_t md5;        /* md5sum of the source */
305    zend_ulong  refcount;   /* count of entries referencing to this data */
306
[1]307    size_t sourcesize;
[311]308    zend_ulong hits;        /* hits of this php */
309    size_t     size;
[1]310
311    zend_op_array *op_array;
312
[95]313#ifdef HAVE_XCACHE_CONSTANT
314    zend_uint constinfo_cnt;
315    xc_constinfo_t *constinfos;
316#endif
317
[1]318    zend_uint funcinfo_cnt;
319    xc_funcinfo_t *funcinfos;
320
321    zend_uint classinfo_cnt;
322    xc_classinfo_t *classinfos;
[548]323#ifndef ZEND_COMPILE_DELAYED_BINDING
[212]324    zend_bool have_early_binding;
[548]325#endif
[268]326
327#ifdef ZEND_ENGINE_2_1
328    zend_uint autoglobal_cnt;
329    xc_autoglobal_t *autoglobals;
330#endif
[311]331
[496]332#ifdef E_STRICT
333    zend_uint compilererror_cnt;
334    xc_compilererror_t *compilererrors;
335#endif
336
[311]337    zend_bool  have_references;
338};
[1]339/* }}} */
340/* {{{ xc_entry_data_var_t */
341typedef struct {
342    zval   *value;
[311]343
344    zend_bool  have_references;
[1]345} xc_entry_data_var_t;
346/* }}} */
347typedef zvalue_value xc_entry_name_t;
348/* {{{ xc_entry_t */
349struct _xc_entry_t {
350    xc_entry_type_t type;
351    xc_hash_value_t hvalue;
352    xc_entry_t *next;
353    xc_cache_t *cache;      /* which cache it's on */
354
355    size_t     size;
[311]356    zend_ulong refcount;    /* count of instances holding this entry */
[1]357    zend_ulong hits;
358    time_t     ctime;           /* the ctime of this entry */
359    time_t     atime;           /* the atime of this entry */
360    time_t     dtime;           /* the deletion time of this entry */
[114]361    long       ttl;             /* ttl of time entry, var only */
[1]362
363#ifdef IS_UNICODE
364    zend_uchar name_type;
365#endif
366    xc_entry_name_t name;
367
368    union {
369        xc_entry_data_php_t *php;
370        xc_entry_data_var_t *var;
371    } data;
[233]372
[311]373    time_t mtime;           /* the mtime of origin source file */
374#ifdef HAVE_INODE
375    int device;             /* the filesystem device */
376    int inode;              /* the filesystem inode */
377#endif
[1]378};
379/* }}} */
380
381extern zend_module_entry xcache_module_entry;
382#define phpext_xcache_ptr &xcache_module_entry
383
384int xc_is_rw(const void *p);
385int xc_is_ro(const void *p);
386int xc_is_shm(const void *p);
[498]387void xc_gc_add_op_array(zend_op_array *op_array TSRMLS_DC);
[1]388
389#endif /* __XCACHE_H */
Note: See TracBrowser for help on using the repository browser.