[1] | 1 | #ifndef __XCACHE_H |
---|
| 2 | #define __XCACHE_H |
---|
| 3 | #define XCACHE_NAME "XCache" |
---|
[494] | 4 | #define XCACHE_VERSION "1.3.0-dev" |
---|
[1] | 5 | #define XCACHE_AUTHOR "mOo" |
---|
[610] | 6 | #define XCACHE_COPYRIGHT "Copyright (c) 2005-2009" |
---|
[1] | 7 | #define XCACHE_URL "http://xcache.lighttpd.net" |
---|
| 8 | |
---|
| 9 | #include <php.h> |
---|
| 10 | #include <zend_compile.h> |
---|
| 11 | #include <zend_API.h> |
---|
[617] | 12 | #include <zend.h> |
---|
[1] | 13 | #include "php_ini.h" |
---|
| 14 | #include "zend_hash.h" |
---|
| 15 | |
---|
| 16 | #ifdef HAVE_CONFIG_H |
---|
| 17 | #include <config.h> |
---|
| 18 | #endif |
---|
[148] | 19 | #include "xc_shm.h" |
---|
[1] | 20 | #include "lock.h" |
---|
| 21 | |
---|
[165] | 22 | #define HAVE_INODE |
---|
[1] | 23 | #if !defined(ZEND_ENGINE_2_1) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1 || PHP_MAJOR_VERSION > 5) |
---|
| 24 | # define ZEND_ENGINE_2_1 |
---|
| 25 | #endif |
---|
[78] | 26 | #if !defined(ZEND_ENGINE_2_2) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2 || PHP_MAJOR_VERSION > 5) |
---|
| 27 | # define ZEND_ENGINE_2_2 |
---|
| 28 | #endif |
---|
[481] | 29 | #if !defined(ZEND_ENGINE_2_3) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 3 || PHP_MAJOR_VERSION > 5) |
---|
| 30 | # define ZEND_ENGINE_2_3 |
---|
| 31 | #endif |
---|
[1] | 32 | |
---|
[19] | 33 | #define NOTHING |
---|
[1] | 34 | /* ZendEngine code Switcher */ |
---|
| 35 | #ifndef ZEND_ENGINE_2 |
---|
| 36 | # define ZESW(v1, v2) v1 |
---|
| 37 | #else |
---|
| 38 | # define ZESW(v1, v2) v2 |
---|
| 39 | #endif |
---|
| 40 | |
---|
[617] | 41 | #ifdef ALLOCA_FLAG |
---|
| 42 | # define my_do_alloca(size, use_heap) do_alloca(size, use_heap) |
---|
| 43 | # define my_free_alloca(size, use_heap) free_alloca(size, use_heap) |
---|
| 44 | #else |
---|
| 45 | # define my_do_alloca(size, use_heap) do_alloca(size) |
---|
| 46 | # define my_free_alloca(size, use_heap) free_alloca(size) |
---|
| 47 | # define ALLOCA_FLAG(x) |
---|
| 48 | #endif |
---|
| 49 | #ifndef Z_SET_ISREF |
---|
| 50 | # define Z_SET_ISREF(z) (z).is_ref = 1; |
---|
| 51 | #endif |
---|
| 52 | #ifndef Z_UNSET_ISREF |
---|
| 53 | # define Z_UNSET_ISREF(z) (z).is_ref = 0; |
---|
| 54 | #endif |
---|
| 55 | #ifndef Z_SET_REFCOUNT |
---|
| 56 | # define Z_SET_REFCOUNT(z, rc) (z).refcount = rc; |
---|
| 57 | #endif |
---|
[618] | 58 | #ifndef IS_CONSTANT_TYPE_MASK |
---|
| 59 | # define IS_CONSTANT_TYPE_MASK 0xf |
---|
| 60 | #endif |
---|
[617] | 61 | |
---|
[263] | 62 | /* {{{ dirty fix for PHP 6 */ |
---|
| 63 | #ifdef add_assoc_long_ex |
---|
| 64 | static inline void my_add_assoc_long_ex(zval *arg, char *key, uint key_len, long value) |
---|
| 65 | { |
---|
| 66 | add_assoc_long_ex(arg, key, key_len, value); |
---|
| 67 | } |
---|
| 68 | # undef add_assoc_long_ex |
---|
| 69 | # define add_assoc_long_ex my_add_assoc_long_ex |
---|
| 70 | #endif |
---|
| 71 | #ifdef add_assoc_bool_ex |
---|
| 72 | static inline void my_add_assoc_bool_ex(zval *arg, char *key, uint key_len, zend_bool value) |
---|
| 73 | { |
---|
| 74 | add_assoc_bool_ex(arg, key, key_len, value); |
---|
| 75 | } |
---|
| 76 | # undef add_assoc_bool_ex |
---|
| 77 | # define add_assoc_bool_ex my_add_assoc_bool_ex |
---|
| 78 | #endif |
---|
| 79 | #ifdef add_assoc_null_ex |
---|
| 80 | static inline void my_add_assoc_null_ex(zval *arg, char *key, uint key_len) |
---|
| 81 | { |
---|
| 82 | add_assoc_null_ex(arg, key, key_len); |
---|
| 83 | } |
---|
| 84 | # undef add_assoc_null_ex |
---|
| 85 | # define add_assoc_null_ex my_add_assoc_null_ex |
---|
| 86 | #endif |
---|
| 87 | /* }}} */ |
---|
| 88 | |
---|
[1] | 89 | /* unicode */ |
---|
| 90 | #ifdef IS_UNICODE |
---|
| 91 | # define UNISW(text, unicode) unicode |
---|
| 92 | #else |
---|
| 93 | # define UNISW(text, unicode) text |
---|
| 94 | #endif |
---|
| 95 | #define BUCKET_KEY_SIZE(b) \ |
---|
| 96 | (UNISW( \ |
---|
| 97 | (b)->nKeyLength, \ |
---|
| 98 | ((b)->key.type == IS_UNICODE) \ |
---|
| 99 | ? UBYTES(b->nKeyLength) \ |
---|
| 100 | : b->nKeyLength \ |
---|
| 101 | )) |
---|
[200] | 102 | #define BUCKET_KEY_S(b) (UNISW((b)->arKey, (b)->key.arKey.s)) |
---|
| 103 | #define BUCKET_KEY_U(b) (UNISW((b)->arKey, (b)->key.arKey.u)) |
---|
| 104 | #define BUCKET_KEY_TYPE(b) (UNISW(IS_STRING, (b)->key.type)) |
---|
[2] | 105 | #ifdef IS_UNICODE |
---|
[104] | 106 | # define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, key.arKey) |
---|
[2] | 107 | #else |
---|
[11] | 108 | # define BUCKET_HEAD_SIZE(b) XtOffsetOf(Bucket, arKey) |
---|
[2] | 109 | #endif |
---|
[1] | 110 | #define BUCKET_SIZE(b) (BUCKET_HEAD_SIZE(b) + BUCKET_KEY_SIZE(b)) |
---|
| 111 | |
---|
| 112 | #ifndef IS_UNICODE |
---|
| 113 | typedef char *zstr; |
---|
[103] | 114 | # define ZSTR_S(s) (s) |
---|
| 115 | # define ZSTR_U(s) (s) |
---|
| 116 | # define ZSTR_V(s) (s) |
---|
| 117 | # define ZSTR_PS(s) (s) |
---|
| 118 | # define ZSTR_PU(s) (s) |
---|
| 119 | # define ZSTR_PV(s) (s) |
---|
[1] | 120 | #else |
---|
[103] | 121 | # define ZSTR_S(zs) ((zs).s) |
---|
| 122 | # define ZSTR_U(zs) ((zs).u) |
---|
| 123 | # define ZSTR_V(zs) ((zs).v) |
---|
| 124 | # define ZSTR_PS(pzs) ((pzs)->s) |
---|
| 125 | # define ZSTR_PU(pzs) ((pzs)->u) |
---|
| 126 | # define ZSTR_PV(pzs) ((pzs)->v) |
---|
[1] | 127 | #endif |
---|
| 128 | |
---|
[103] | 129 | #ifndef ZSTR |
---|
| 130 | # define ZSTR(s) (s) |
---|
| 131 | #endif |
---|
| 132 | |
---|
| 133 | #ifndef Z_UNIVAL |
---|
| 134 | # define Z_UNIVAL(zval) (zval).value.str.val |
---|
| 135 | # define Z_UNILEN(zval) (zval).value.str.len |
---|
| 136 | #endif |
---|
| 137 | |
---|
[1] | 138 | /* {{{ u hash wrapper */ |
---|
| 139 | #ifndef IS_UNICODE |
---|
| 140 | # define zend_u_hash_add(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \ |
---|
| 141 | zend_hash_add(ht, arKey, nKeyLength, pData, nDataSize, pDest) |
---|
| 142 | |
---|
[88] | 143 | # define zend_u_hash_update(ht, type, arKey, nKeyLength, pData, nDataSize, pDest) \ |
---|
| 144 | zend_hash_update(ht, arKey, nKeyLength, pData, nDataSize, pDest) |
---|
| 145 | |
---|
[1] | 146 | # define zend_u_hash_find(ht, type, arKey, nKeyLength, pData) \ |
---|
| 147 | zend_hash_find(ht, arKey, nKeyLength, pData) |
---|
| 148 | |
---|
[200] | 149 | # define zend_u_hash_quick_find(ht, type, arKey, nKeyLength, h, pData) \ |
---|
| 150 | zend_hash_quick_find(ht, arKey, nKeyLength, h, pData) |
---|
| 151 | |
---|
[1] | 152 | # define add_u_assoc_zval_ex(arg, type, key, key_len, value) \ |
---|
| 153 | add_assoc_zval_ex(arg, key, key_len, value) |
---|
| 154 | |
---|
[268] | 155 | # define zend_u_is_auto_global(type, name, name_len) \ |
---|
| 156 | zend_is_auto_global(name, name_len) |
---|
[1] | 157 | #endif |
---|
| 158 | /* }}} */ |
---|
| 159 | |
---|
| 160 | |
---|
| 161 | #define ECALLOC_N(x, n) ((x) = ecalloc(n, sizeof((x)[0]))) |
---|
| 162 | #define ECALLOC_ONE(x) ECALLOC_N(x, 1) |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | |
---|
| 166 | typedef ulong xc_hash_value_t; |
---|
| 167 | typedef struct { |
---|
| 168 | int bits; |
---|
| 169 | int size; |
---|
| 170 | int mask; |
---|
| 171 | } xc_hash_t; |
---|
| 172 | |
---|
| 173 | /* the class entry type to be stored in class_table */ |
---|
| 174 | typedef ZESW(zend_class_entry, zend_class_entry*) xc_cest_t; |
---|
| 175 | |
---|
| 176 | /* xc_cest_t to (zend_class_entry*) */ |
---|
| 177 | #define CestToCePtr(st) (ZESW(\ |
---|
| 178 | &(st), \ |
---|
| 179 | st \ |
---|
| 180 | ) ) |
---|
| 181 | |
---|
| 182 | /* ZCEP=zend class entry ptr */ |
---|
| 183 | #define ZCEP_REFCOUNT_PTR(pce) (ZESW( \ |
---|
| 184 | (pce)->refcount, \ |
---|
| 185 | &((pce)->refcount) \ |
---|
| 186 | )) |
---|
| 187 | |
---|
| 188 | #define ZCE_REFCOUNT_PTR(ce) ZCE_REFCOUNT_PTR(&ce) |
---|
| 189 | |
---|
| 190 | typedef zend_op_array *(zend_compile_file_t)(zend_file_handle *h, int type TSRMLS_DC); |
---|
| 191 | |
---|
| 192 | /* {{{ xc_cache_t */ |
---|
| 193 | typedef struct _xc_entry_t xc_entry_t; |
---|
[11] | 194 | typedef struct { |
---|
[1] | 195 | int cacheid; |
---|
| 196 | xc_hash_t *hcache; /* hash to cacheid */ |
---|
| 197 | |
---|
[11] | 198 | time_t compiling; |
---|
[1] | 199 | zend_ulong misses; |
---|
| 200 | zend_ulong hits; |
---|
| 201 | zend_ulong clogs; |
---|
| 202 | zend_ulong ooms; |
---|
[457] | 203 | zend_ulong errors; |
---|
[1] | 204 | xc_lock_t *lck; |
---|
| 205 | xc_shm_t *shm; /* to which shm contains us */ |
---|
| 206 | xc_mem_t *mem; /* to which mem contains us */ |
---|
| 207 | |
---|
| 208 | xc_entry_t **entries; |
---|
[32] | 209 | int entries_count; |
---|
[1] | 210 | xc_entry_t *deletes; |
---|
[32] | 211 | int deletes_count; |
---|
[1] | 212 | xc_hash_t *hentry; /* hash to entry */ |
---|
[114] | 213 | |
---|
| 214 | time_t last_gc_deletes; |
---|
| 215 | time_t last_gc_expires; |
---|
[1] | 216 | } xc_cache_t; |
---|
| 217 | /* }}} */ |
---|
| 218 | /* {{{ xc_classinfo_t */ |
---|
| 219 | typedef struct { |
---|
[14] | 220 | #ifdef IS_UNICODE |
---|
| 221 | zend_uchar type; |
---|
| 222 | #endif |
---|
[103] | 223 | zstr key; |
---|
[1] | 224 | zend_uint key_size; |
---|
| 225 | xc_cest_t cest; |
---|
[212] | 226 | int oplineno; |
---|
[1] | 227 | } xc_classinfo_t; |
---|
| 228 | /* }}} */ |
---|
[95] | 229 | #ifdef HAVE_XCACHE_CONSTANT |
---|
| 230 | /* {{{ xc_constinfo_t */ |
---|
| 231 | typedef struct { |
---|
| 232 | #ifdef IS_UNICODE |
---|
| 233 | zend_uchar type; |
---|
| 234 | #endif |
---|
[103] | 235 | zstr key; |
---|
[95] | 236 | zend_uint key_size; |
---|
| 237 | zend_constant constant; |
---|
| 238 | } xc_constinfo_t; |
---|
| 239 | /* }}} */ |
---|
| 240 | #endif |
---|
[1] | 241 | /* {{{ xc_funcinfo_t */ |
---|
| 242 | typedef struct { |
---|
[14] | 243 | #ifdef IS_UNICODE |
---|
| 244 | zend_uchar type; |
---|
| 245 | #endif |
---|
[103] | 246 | zstr key; |
---|
[1] | 247 | zend_uint key_size; |
---|
| 248 | zend_function func; |
---|
| 249 | } xc_funcinfo_t; |
---|
| 250 | /* }}} */ |
---|
[268] | 251 | #ifdef ZEND_ENGINE_2_1 |
---|
| 252 | /* {{{ xc_autoglobal_t */ |
---|
| 253 | typedef struct { |
---|
| 254 | #ifdef IS_UNICODE |
---|
| 255 | zend_uchar type; |
---|
| 256 | #endif |
---|
| 257 | zstr key; |
---|
| 258 | zend_uint key_len; |
---|
| 259 | } xc_autoglobal_t; |
---|
| 260 | /* }}} */ |
---|
| 261 | #endif |
---|
[1] | 262 | typedef enum { XC_TYPE_PHP, XC_TYPE_VAR } xc_entry_type_t; |
---|
| 263 | /* {{{ xc_entry_data_php_t */ |
---|
| 264 | typedef struct { |
---|
| 265 | size_t sourcesize; |
---|
| 266 | #ifdef HAVE_INODE |
---|
| 267 | int device; /* the filesystem device */ |
---|
| 268 | int inode; /* the filesystem inode */ |
---|
| 269 | #endif |
---|
| 270 | time_t mtime; /* the mtime of origin source file */ |
---|
| 271 | |
---|
| 272 | zend_op_array *op_array; |
---|
| 273 | |
---|
[95] | 274 | #ifdef HAVE_XCACHE_CONSTANT |
---|
| 275 | zend_uint constinfo_cnt; |
---|
| 276 | xc_constinfo_t *constinfos; |
---|
| 277 | #endif |
---|
| 278 | |
---|
[1] | 279 | zend_uint funcinfo_cnt; |
---|
| 280 | xc_funcinfo_t *funcinfos; |
---|
| 281 | |
---|
| 282 | zend_uint classinfo_cnt; |
---|
| 283 | xc_classinfo_t *classinfos; |
---|
[212] | 284 | zend_bool have_early_binding; |
---|
[268] | 285 | |
---|
| 286 | #ifdef ZEND_ENGINE_2_1 |
---|
| 287 | zend_uint autoglobal_cnt; |
---|
| 288 | xc_autoglobal_t *autoglobals; |
---|
| 289 | #endif |
---|
[1] | 290 | } xc_entry_data_php_t; |
---|
| 291 | /* }}} */ |
---|
| 292 | /* {{{ xc_entry_data_var_t */ |
---|
| 293 | typedef struct { |
---|
| 294 | zval *value; |
---|
| 295 | } xc_entry_data_var_t; |
---|
| 296 | /* }}} */ |
---|
| 297 | typedef zvalue_value xc_entry_name_t; |
---|
| 298 | /* {{{ xc_entry_t */ |
---|
| 299 | struct _xc_entry_t { |
---|
| 300 | xc_entry_type_t type; |
---|
| 301 | xc_hash_value_t hvalue; |
---|
| 302 | xc_entry_t *next; |
---|
| 303 | xc_cache_t *cache; /* which cache it's on */ |
---|
| 304 | |
---|
| 305 | size_t size; |
---|
| 306 | zend_ulong refcount; |
---|
| 307 | zend_ulong hits; |
---|
| 308 | time_t ctime; /* the ctime of this entry */ |
---|
| 309 | time_t atime; /* the atime of this entry */ |
---|
| 310 | time_t dtime; /* the deletion time of this entry */ |
---|
[114] | 311 | long ttl; /* ttl of time entry, var only */ |
---|
[1] | 312 | |
---|
| 313 | #ifdef IS_UNICODE |
---|
| 314 | zend_uchar name_type; |
---|
| 315 | #endif |
---|
| 316 | xc_entry_name_t name; |
---|
| 317 | |
---|
| 318 | union { |
---|
| 319 | xc_entry_data_php_t *php; |
---|
| 320 | xc_entry_data_var_t *var; |
---|
| 321 | } data; |
---|
[233] | 322 | |
---|
| 323 | zend_bool have_references; |
---|
[1] | 324 | }; |
---|
| 325 | /* }}} */ |
---|
| 326 | |
---|
| 327 | extern zend_module_entry xcache_module_entry; |
---|
| 328 | #define phpext_xcache_ptr &xcache_module_entry |
---|
| 329 | |
---|
| 330 | int xc_is_rw(const void *p); |
---|
| 331 | int xc_is_ro(const void *p); |
---|
| 332 | int xc_is_shm(const void *p); |
---|
| 333 | |
---|
| 334 | #endif /* __XCACHE_H */ |
---|