| 1 | |
|---|
| 2 | #if 0 |
|---|
| 3 | #define XCACHE_DEBUG |
|---|
| 4 | #endif |
|---|
| 5 | |
|---|
| 6 | #if 0 |
|---|
| 7 | #define SHOW_DPRINT |
|---|
| 8 | #endif |
|---|
| 9 | |
|---|
| 10 | /* {{{ macros */ |
|---|
| 11 | #include <stdlib.h> |
|---|
| 12 | #include <stdio.h> |
|---|
| 13 | #include <string.h> |
|---|
| 14 | |
|---|
| 15 | #include <signal.h> |
|---|
| 16 | |
|---|
| 17 | #include "php.h" |
|---|
| 18 | #include "ext/standard/info.h" |
|---|
| 19 | #include "ext/standard/md5.h" |
|---|
| 20 | #include "ext/standard/php_math.h" |
|---|
| 21 | #include "ext/standard/php_string.h" |
|---|
| 22 | #include "zend_extensions.h" |
|---|
| 23 | #include "SAPI.h" |
|---|
| 24 | |
|---|
| 25 | #include "xcache.h" |
|---|
| 26 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 27 | #include "ext/date/php_date.h" |
|---|
| 28 | #endif |
|---|
| 29 | #include "optimizer.h" |
|---|
| 30 | #include "coverager.h" |
|---|
| 31 | #include "disassembler.h" |
|---|
| 32 | #include "align.h" |
|---|
| 33 | #include "stack.h" |
|---|
| 34 | #include "xcache_globals.h" |
|---|
| 35 | #include "processor.h" |
|---|
| 36 | #include "const_string.h" |
|---|
| 37 | #include "opcode_spec.h" |
|---|
| 38 | #include "utils.h" |
|---|
| 39 | |
|---|
| 40 | #define VAR_ENTRY_EXPIRED(pentry) ((pentry)->ttl && XG(request_time) > pentry->ctime + (pentry)->ttl) |
|---|
| 41 | #define CHECK(x, e) do { if ((x) == NULL) { zend_error(E_ERROR, "XCache: " e); goto err; } } while (0) |
|---|
| 42 | #define LOCK(x) xc_lock(x->lck) |
|---|
| 43 | #define UNLOCK(x) xc_unlock(x->lck) |
|---|
| 44 | |
|---|
| 45 | #define ENTER_LOCK_EX(x) \ |
|---|
| 46 | xc_lock(x->lck); \ |
|---|
| 47 | zend_try { \ |
|---|
| 48 | do |
|---|
| 49 | #define LEAVE_LOCK_EX(x) \ |
|---|
| 50 | while (0); \ |
|---|
| 51 | } zend_catch { \ |
|---|
| 52 | catched = 1; \ |
|---|
| 53 | } zend_end_try(); \ |
|---|
| 54 | xc_unlock(x->lck) |
|---|
| 55 | |
|---|
| 56 | #define ENTER_LOCK(x) do { \ |
|---|
| 57 | int catched = 0; \ |
|---|
| 58 | ENTER_LOCK_EX(x) |
|---|
| 59 | #define LEAVE_LOCK(x) \ |
|---|
| 60 | LEAVE_LOCK_EX(x); \ |
|---|
| 61 | if (catched) { \ |
|---|
| 62 | zend_bailout(); \ |
|---|
| 63 | } \ |
|---|
| 64 | } while(0) |
|---|
| 65 | |
|---|
| 66 | /* }}} */ |
|---|
| 67 | |
|---|
| 68 | /* {{{ globals */ |
|---|
| 69 | static char *xc_shm_scheme = NULL; |
|---|
| 70 | static char *xc_mmap_path = NULL; |
|---|
| 71 | static char *xc_coredump_dir = NULL; |
|---|
| 72 | |
|---|
| 73 | static xc_hash_t xc_php_hcache = {0}; |
|---|
| 74 | static xc_hash_t xc_php_hentry = {0}; |
|---|
| 75 | static xc_hash_t xc_var_hcache = {0}; |
|---|
| 76 | static xc_hash_t xc_var_hentry = {0}; |
|---|
| 77 | |
|---|
| 78 | static zend_ulong xc_php_ttl = 0; |
|---|
| 79 | static zend_ulong xc_var_maxttl = 0; |
|---|
| 80 | |
|---|
| 81 | enum { xc_deletes_gc_interval = 120 }; |
|---|
| 82 | static zend_ulong xc_php_gc_interval = 0; |
|---|
| 83 | static zend_ulong xc_var_gc_interval = 0; |
|---|
| 84 | |
|---|
| 85 | /* total size */ |
|---|
| 86 | static zend_ulong xc_php_size = 0; |
|---|
| 87 | static zend_ulong xc_var_size = 0; |
|---|
| 88 | |
|---|
| 89 | static xc_cache_t **xc_php_caches = NULL; |
|---|
| 90 | static xc_cache_t **xc_var_caches = NULL; |
|---|
| 91 | |
|---|
| 92 | static zend_bool xc_initized = 0; |
|---|
| 93 | static time_t xc_init_time = 0; |
|---|
| 94 | static long unsigned xc_init_instance_id = 0; |
|---|
| 95 | #ifdef ZTS |
|---|
| 96 | static long unsigned xc_init_instance_subid = 0; |
|---|
| 97 | #endif |
|---|
| 98 | static zend_compile_file_t *origin_compile_file = NULL; |
|---|
| 99 | static zend_compile_file_t *old_compile_file = NULL; |
|---|
| 100 | static zend_llist_element *xc_llist_zend_extension = NULL; |
|---|
| 101 | |
|---|
| 102 | static zend_bool xc_test = 0; |
|---|
| 103 | static zend_bool xc_readonly_protection = 0; |
|---|
| 104 | |
|---|
| 105 | zend_bool xc_have_op_array_ctor = 0; |
|---|
| 106 | |
|---|
| 107 | static zend_bool xc_module_gotup = 0; |
|---|
| 108 | static zend_bool xc_zend_extension_gotup = 0; |
|---|
| 109 | static zend_bool xc_zend_extension_faked = 0; |
|---|
| 110 | #if !COMPILE_DL_XCACHE |
|---|
| 111 | # define zend_extension_entry xcache_zend_extension_entry |
|---|
| 112 | #endif |
|---|
| 113 | ZEND_DLEXPORT zend_extension zend_extension_entry; |
|---|
| 114 | ZEND_DECLARE_MODULE_GLOBALS(xcache); |
|---|
| 115 | /* }}} */ |
|---|
| 116 | |
|---|
| 117 | /* any function in *_dmz is only safe be called within locked(single thread) area */ |
|---|
| 118 | |
|---|
| 119 | static void xc_php_add_dmz(xc_entry_data_php_t *php) /* {{{ */ |
|---|
| 120 | { |
|---|
| 121 | xc_entry_data_php_t **head = &(php->cache->phps[php->hvalue]); |
|---|
| 122 | php->next = *head; |
|---|
| 123 | *head = php; |
|---|
| 124 | php->cache->phps_count ++; |
|---|
| 125 | } |
|---|
| 126 | /* }}} */ |
|---|
| 127 | static xc_entry_data_php_t *xc_php_store_dmz(xc_entry_data_php_t *php TSRMLS_DC) /* {{{ */ |
|---|
| 128 | { |
|---|
| 129 | xc_entry_data_php_t *stored_php; |
|---|
| 130 | |
|---|
| 131 | php->hits = 0; |
|---|
| 132 | php->refcount = 0; |
|---|
| 133 | stored_php = xc_processor_store_xc_entry_data_php_t(php TSRMLS_CC); |
|---|
| 134 | if (stored_php) { |
|---|
| 135 | xc_php_add_dmz(stored_php); |
|---|
| 136 | return stored_php; |
|---|
| 137 | } |
|---|
| 138 | else { |
|---|
| 139 | php->cache->ooms ++; |
|---|
| 140 | return NULL; |
|---|
| 141 | } |
|---|
| 142 | } |
|---|
| 143 | /* }}} */ |
|---|
| 144 | static xc_entry_data_php_t *xc_php_find_dmz(xc_entry_data_php_t *php TSRMLS_DC) /* {{{ */ |
|---|
| 145 | { |
|---|
| 146 | xc_entry_data_php_t *p; |
|---|
| 147 | for (p = php->cache->phps[php->hvalue]; p; p = p->next) { |
|---|
| 148 | if (memcmp(php->md5, p->md5, sizeof(php->md5)) == 0) { |
|---|
| 149 | p->hits ++; |
|---|
| 150 | return p; |
|---|
| 151 | } |
|---|
| 152 | } |
|---|
| 153 | return NULL; |
|---|
| 154 | } |
|---|
| 155 | /* }}} */ |
|---|
| 156 | static void xc_php_free_dmz(xc_entry_data_php_t *php) /* {{{ */ |
|---|
| 157 | { |
|---|
| 158 | php->cache->mem->handlers->free(php->cache->mem, (xc_entry_data_php_t *)php); |
|---|
| 159 | } |
|---|
| 160 | /* }}} */ |
|---|
| 161 | static void xc_php_addref_dmz(xc_entry_data_php_t *php) /* {{{ */ |
|---|
| 162 | { |
|---|
| 163 | php->refcount ++; |
|---|
| 164 | } |
|---|
| 165 | /* }}} */ |
|---|
| 166 | static void xc_php_release_dmz(xc_entry_data_php_t *php) /* {{{ */ |
|---|
| 167 | { |
|---|
| 168 | if (-- php->refcount == 0) { |
|---|
| 169 | xc_entry_data_php_t **pp = &(php->cache->phps[php->hvalue]); |
|---|
| 170 | xc_entry_data_php_t *p; |
|---|
| 171 | for (p = *pp; p; pp = &(p->next), p = p->next) { |
|---|
| 172 | if (memcmp(php->md5, p->md5, sizeof(php->md5)) == 0) { |
|---|
| 173 | /* unlink */ |
|---|
| 174 | *pp = p->next; |
|---|
| 175 | xc_php_free_dmz(php); |
|---|
| 176 | return; |
|---|
| 177 | } |
|---|
| 178 | } |
|---|
| 179 | assert(0); |
|---|
| 180 | } |
|---|
| 181 | } |
|---|
| 182 | /* }}} */ |
|---|
| 183 | |
|---|
| 184 | static inline int xc_entry_equal_dmz(xc_entry_t *a, xc_entry_t *b) /* {{{ */ |
|---|
| 185 | { |
|---|
| 186 | /* this function isn't required but can be in dmz */ |
|---|
| 187 | |
|---|
| 188 | if (a->type != b->type) { |
|---|
| 189 | return 0; |
|---|
| 190 | } |
|---|
| 191 | switch (a->type) { |
|---|
| 192 | case XC_TYPE_PHP: |
|---|
| 193 | #ifdef HAVE_INODE |
|---|
| 194 | do { |
|---|
| 195 | if (a->inode) { |
|---|
| 196 | return a->inode == b->inode |
|---|
| 197 | && a->device == b->device; |
|---|
| 198 | } |
|---|
| 199 | } while(0); |
|---|
| 200 | #endif |
|---|
| 201 | /* fall */ |
|---|
| 202 | |
|---|
| 203 | case XC_TYPE_VAR: |
|---|
| 204 | do { |
|---|
| 205 | #ifdef IS_UNICODE |
|---|
| 206 | if (a->name_type == IS_UNICODE) { |
|---|
| 207 | if (a->name.ustr.len != b->name.ustr.len) { |
|---|
| 208 | return 0; |
|---|
| 209 | } |
|---|
| 210 | return memcmp(a->name.ustr.val, b->name.ustr.val, (a->name.ustr.len + 1) * sizeof(UChar)) == 0; |
|---|
| 211 | } |
|---|
| 212 | #endif |
|---|
| 213 | if (a->name.str.len != b->name.str.len) { |
|---|
| 214 | return 0; |
|---|
| 215 | } |
|---|
| 216 | return memcmp(a->name.str.val, b->name.str.val, a->name.str.len + 1) == 0; |
|---|
| 217 | |
|---|
| 218 | } while(0); |
|---|
| 219 | default: |
|---|
| 220 | assert(0); |
|---|
| 221 | } |
|---|
| 222 | return 0; |
|---|
| 223 | } |
|---|
| 224 | /* }}} */ |
|---|
| 225 | static inline int xc_entry_has_prefix_dmz(xc_entry_t *entry, zval *prefix) /* {{{ */ |
|---|
| 226 | { |
|---|
| 227 | /* this function isn't required but can be in dmz */ |
|---|
| 228 | |
|---|
| 229 | switch (entry->type) { |
|---|
| 230 | case XC_TYPE_PHP: |
|---|
| 231 | case XC_TYPE_VAR: |
|---|
| 232 | do { |
|---|
| 233 | #ifdef IS_UNICODE |
|---|
| 234 | if (entry->name_type != prefix->type) { |
|---|
| 235 | return 0; |
|---|
| 236 | } |
|---|
| 237 | |
|---|
| 238 | if (entry->name_type == IS_UNICODE) { |
|---|
| 239 | if (entry->name.ustr.len < Z_USTRLEN_P(prefix)) { |
|---|
| 240 | return 0; |
|---|
| 241 | } |
|---|
| 242 | return memcmp(entry->name.ustr.val, Z_USTRVAL_P(prefix), Z_USTRLEN_P(prefix) * sizeof(UChar)) == 0; |
|---|
| 243 | } |
|---|
| 244 | #endif |
|---|
| 245 | if (prefix->type != IS_STRING) { |
|---|
| 246 | return 0; |
|---|
| 247 | } |
|---|
| 248 | |
|---|
| 249 | if (entry->name.str.len < Z_STRLEN_P(prefix)) { |
|---|
| 250 | return 0; |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | return memcmp(entry->name.str.val, Z_STRVAL_P(prefix), Z_STRLEN_P(prefix)) == 0; |
|---|
| 254 | |
|---|
| 255 | } while(0); |
|---|
| 256 | default: |
|---|
| 257 | assert(0); |
|---|
| 258 | } |
|---|
| 259 | return 0; |
|---|
| 260 | } |
|---|
| 261 | /* }}} */ |
|---|
| 262 | static void xc_entry_add_dmz(xc_entry_t *xce) /* {{{ */ |
|---|
| 263 | { |
|---|
| 264 | xc_entry_t **head = &(xce->cache->entries[xce->hvalue]); |
|---|
| 265 | xce->next = *head; |
|---|
| 266 | *head = xce; |
|---|
| 267 | xce->cache->entries_count ++; |
|---|
| 268 | } |
|---|
| 269 | /* }}} */ |
|---|
| 270 | static xc_entry_t *xc_entry_store_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */ |
|---|
| 271 | { |
|---|
| 272 | xc_entry_t *stored_xce; |
|---|
| 273 | |
|---|
| 274 | xce->hits = 0; |
|---|
| 275 | xce->ctime = XG(request_time); |
|---|
| 276 | xce->atime = XG(request_time); |
|---|
| 277 | stored_xce = xc_processor_store_xc_entry_t(xce TSRMLS_CC); |
|---|
| 278 | if (stored_xce) { |
|---|
| 279 | xc_entry_add_dmz(stored_xce); |
|---|
| 280 | return stored_xce; |
|---|
| 281 | } |
|---|
| 282 | else { |
|---|
| 283 | xce->cache->ooms ++; |
|---|
| 284 | return NULL; |
|---|
| 285 | } |
|---|
| 286 | } |
|---|
| 287 | /* }}} */ |
|---|
| 288 | static void xc_entry_free_real_dmz(volatile xc_entry_t *xce) /* {{{ */ |
|---|
| 289 | { |
|---|
| 290 | if (xce->type == XC_TYPE_PHP) { |
|---|
| 291 | xc_php_release_dmz(xce->data.php); |
|---|
| 292 | } |
|---|
| 293 | xce->cache->mem->handlers->free(xce->cache->mem, (xc_entry_t *)xce); |
|---|
| 294 | } |
|---|
| 295 | /* }}} */ |
|---|
| 296 | static void xc_entry_free_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */ |
|---|
| 297 | { |
|---|
| 298 | xce->cache->entries_count --; |
|---|
| 299 | if (xce->refcount == 0) { |
|---|
| 300 | xc_entry_free_real_dmz(xce); |
|---|
| 301 | } |
|---|
| 302 | else { |
|---|
| 303 | xce->next = xce->cache->deletes; |
|---|
| 304 | xce->cache->deletes = xce; |
|---|
| 305 | xce->dtime = XG(request_time); |
|---|
| 306 | xce->cache->deletes_count ++; |
|---|
| 307 | } |
|---|
| 308 | return; |
|---|
| 309 | } |
|---|
| 310 | /* }}} */ |
|---|
| 311 | static void xc_entry_remove_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */ |
|---|
| 312 | { |
|---|
| 313 | xc_entry_t **pp = &(xce->cache->entries[xce->hvalue]); |
|---|
| 314 | xc_entry_t *p; |
|---|
| 315 | for (p = *pp; p; pp = &(p->next), p = p->next) { |
|---|
| 316 | if (xc_entry_equal_dmz(xce, p)) { |
|---|
| 317 | /* unlink */ |
|---|
| 318 | *pp = p->next; |
|---|
| 319 | xc_entry_free_dmz(xce TSRMLS_CC); |
|---|
| 320 | return; |
|---|
| 321 | } |
|---|
| 322 | } |
|---|
| 323 | assert(0); |
|---|
| 324 | } |
|---|
| 325 | /* }}} */ |
|---|
| 326 | static xc_entry_t *xc_entry_find_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */ |
|---|
| 327 | { |
|---|
| 328 | xc_entry_t *p; |
|---|
| 329 | for (p = xce->cache->entries[xce->hvalue]; p; p = p->next) { |
|---|
| 330 | if (xc_entry_equal_dmz(xce, p)) { |
|---|
| 331 | if (p->type == XC_TYPE_VAR || /* PHP */ (p->mtime == xce->mtime && p->data.php->sourcesize == xce->data.php->sourcesize)) { |
|---|
| 332 | p->hits ++; |
|---|
| 333 | p->atime = XG(request_time); |
|---|
| 334 | return p; |
|---|
| 335 | } |
|---|
| 336 | else { |
|---|
| 337 | xc_entry_remove_dmz(p TSRMLS_CC); |
|---|
| 338 | return NULL; |
|---|
| 339 | } |
|---|
| 340 | } |
|---|
| 341 | } |
|---|
| 342 | return NULL; |
|---|
| 343 | } |
|---|
| 344 | /* }}} */ |
|---|
| 345 | static void xc_entry_hold_php_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */ |
|---|
| 346 | { |
|---|
| 347 | TRACE("hold %s", xce->name.str.val); |
|---|
| 348 | xce->refcount ++; |
|---|
| 349 | xc_stack_push(&XG(php_holds)[xce->cache->cacheid], (void *)xce); |
|---|
| 350 | } |
|---|
| 351 | /* }}} */ |
|---|
| 352 | #if 0 |
|---|
| 353 | static void xc_entry_hold_var_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */ |
|---|
| 354 | { |
|---|
| 355 | xce->refcount ++; |
|---|
| 356 | xc_stack_push(&XG(var_holds)[xce->cache->cacheid], (void *)xce); |
|---|
| 357 | } |
|---|
| 358 | /* }}} */ |
|---|
| 359 | #endif |
|---|
| 360 | static inline zend_uint advance_wrapped(zend_uint val, zend_uint count) /* {{{ */ |
|---|
| 361 | { |
|---|
| 362 | if (val + 1 >= count) { |
|---|
| 363 | return 0; |
|---|
| 364 | } |
|---|
| 365 | return val + 1; |
|---|
| 366 | } |
|---|
| 367 | /* }}} */ |
|---|
| 368 | static void xc_counters_inc(time_t *curtime, zend_uint *curslot, time_t period, zend_ulong *counters, zend_uint count TSRMLS_DC) /* {{{ */ |
|---|
| 369 | { |
|---|
| 370 | time_t n = XG(request_time) / period; |
|---|
| 371 | if (*curtime != n) { |
|---|
| 372 | zend_uint target_slot = n % count; |
|---|
| 373 | if (n - *curtime > period) { |
|---|
| 374 | memset(counters, 0, sizeof(counters[0]) * count); |
|---|
| 375 | } |
|---|
| 376 | else { |
|---|
| 377 | zend_uint slot; |
|---|
| 378 | for (slot = advance_wrapped(*curslot, count); |
|---|
| 379 | slot != target_slot; |
|---|
| 380 | slot = advance_wrapped(slot, count)) { |
|---|
| 381 | counters[slot] = 0; |
|---|
| 382 | } |
|---|
| 383 | counters[target_slot] = 0; |
|---|
| 384 | } |
|---|
| 385 | *curtime = n; |
|---|
| 386 | *curslot = target_slot; |
|---|
| 387 | } |
|---|
| 388 | counters[*curslot] ++; |
|---|
| 389 | } |
|---|
| 390 | /* }}} */ |
|---|
| 391 | static void xc_cache_hit_dmz(xc_cache_t *cache TSRMLS_DC) /* {{{ */ |
|---|
| 392 | { |
|---|
| 393 | cache->hits ++; |
|---|
| 394 | |
|---|
| 395 | xc_counters_inc(&cache->hits_by_hour_cur_time |
|---|
| 396 | , &cache->hits_by_hour_cur_slot, 60 * 60 |
|---|
| 397 | , cache->hits_by_hour |
|---|
| 398 | , sizeof(cache->hits_by_hour) / sizeof(cache->hits_by_hour[0]) |
|---|
| 399 | TSRMLS_CC); |
|---|
| 400 | |
|---|
| 401 | xc_counters_inc(&cache->hits_by_second_cur_time |
|---|
| 402 | , &cache->hits_by_second_cur_slot |
|---|
| 403 | , 1 |
|---|
| 404 | , cache->hits_by_second |
|---|
| 405 | , sizeof(cache->hits_by_second) / sizeof(cache->hits_by_second[0]) |
|---|
| 406 | TSRMLS_CC); |
|---|
| 407 | } |
|---|
| 408 | /* }}} */ |
|---|
| 409 | |
|---|
| 410 | /* helper function that loop through each entry */ |
|---|
| 411 | #define XC_ENTRY_APPLY_FUNC(name) int name(xc_entry_t *entry TSRMLS_DC) |
|---|
| 412 | typedef XC_ENTRY_APPLY_FUNC((*cache_apply_dmz_func_t)); |
|---|
| 413 | static void xc_entry_apply_dmz(xc_cache_t *cache, cache_apply_dmz_func_t apply_func TSRMLS_DC) /* {{{ */ |
|---|
| 414 | { |
|---|
| 415 | xc_entry_t *p, **pp; |
|---|
| 416 | int i, c; |
|---|
| 417 | |
|---|
| 418 | for (i = 0, c = cache->hentry->size; i < c; i ++) { |
|---|
| 419 | pp = &(cache->entries[i]); |
|---|
| 420 | for (p = *pp; p; p = *pp) { |
|---|
| 421 | if (apply_func(p TSRMLS_CC)) { |
|---|
| 422 | /* unlink */ |
|---|
| 423 | *pp = p->next; |
|---|
| 424 | xc_entry_free_dmz(p TSRMLS_CC); |
|---|
| 425 | } |
|---|
| 426 | else { |
|---|
| 427 | pp = &(p->next); |
|---|
| 428 | } |
|---|
| 429 | } |
|---|
| 430 | } |
|---|
| 431 | } |
|---|
| 432 | /* }}} */ |
|---|
| 433 | |
|---|
| 434 | #define XC_CACHE_APPLY_FUNC(name) void name(xc_cache_t *cache TSRMLS_DC) |
|---|
| 435 | /* call graph: |
|---|
| 436 | * xc_gc_expires_php -> xc_gc_expires_one -> xc_entry_apply_dmz -> xc_gc_expires_php_entry_dmz |
|---|
| 437 | * xc_gc_expires_var -> xc_gc_expires_one -> xc_entry_apply_dmz -> xc_gc_expires_var_entry_dmz |
|---|
| 438 | */ |
|---|
| 439 | static XC_ENTRY_APPLY_FUNC(xc_gc_expires_php_entry_dmz) /* {{{ */ |
|---|
| 440 | { |
|---|
| 441 | TRACE("ttl %lu, %lu %lu", (zend_ulong) XG(request_time), (zend_ulong) entry->atime, xc_php_ttl); |
|---|
| 442 | if (XG(request_time) > entry->atime + xc_php_ttl) { |
|---|
| 443 | return 1; |
|---|
| 444 | } |
|---|
| 445 | return 0; |
|---|
| 446 | } |
|---|
| 447 | /* }}} */ |
|---|
| 448 | static XC_ENTRY_APPLY_FUNC(xc_gc_expires_var_entry_dmz) /* {{{ */ |
|---|
| 449 | { |
|---|
| 450 | if (VAR_ENTRY_EXPIRED(entry)) { |
|---|
| 451 | return 1; |
|---|
| 452 | } |
|---|
| 453 | return 0; |
|---|
| 454 | } |
|---|
| 455 | /* }}} */ |
|---|
| 456 | static void xc_gc_expires_one(xc_cache_t *cache, zend_ulong gc_interval, cache_apply_dmz_func_t apply_func TSRMLS_DC) /* {{{ */ |
|---|
| 457 | { |
|---|
| 458 | TRACE("interval %lu, %lu %lu", (zend_ulong) XG(request_time), (zend_ulong) cache->last_gc_expires, gc_interval); |
|---|
| 459 | if (XG(request_time) - cache->last_gc_expires >= gc_interval) { |
|---|
| 460 | ENTER_LOCK(cache) { |
|---|
| 461 | if (XG(request_time) - cache->last_gc_expires >= gc_interval) { |
|---|
| 462 | cache->last_gc_expires = XG(request_time); |
|---|
| 463 | xc_entry_apply_dmz(cache, apply_func TSRMLS_CC); |
|---|
| 464 | } |
|---|
| 465 | } LEAVE_LOCK(cache); |
|---|
| 466 | } |
|---|
| 467 | } |
|---|
| 468 | /* }}} */ |
|---|
| 469 | static void xc_gc_expires_php(TSRMLS_D) /* {{{ */ |
|---|
| 470 | { |
|---|
| 471 | int i, c; |
|---|
| 472 | |
|---|
| 473 | if (!xc_php_ttl || !xc_php_gc_interval || !xc_php_caches) { |
|---|
| 474 | return; |
|---|
| 475 | } |
|---|
| 476 | |
|---|
| 477 | for (i = 0, c = xc_php_hcache.size; i < c; i ++) { |
|---|
| 478 | xc_gc_expires_one(xc_php_caches[i], xc_php_gc_interval, xc_gc_expires_php_entry_dmz TSRMLS_CC); |
|---|
| 479 | } |
|---|
| 480 | } |
|---|
| 481 | /* }}} */ |
|---|
| 482 | static void xc_gc_expires_var(TSRMLS_D) /* {{{ */ |
|---|
| 483 | { |
|---|
| 484 | int i, c; |
|---|
| 485 | |
|---|
| 486 | if (!xc_var_gc_interval || !xc_var_caches) { |
|---|
| 487 | return; |
|---|
| 488 | } |
|---|
| 489 | |
|---|
| 490 | for (i = 0, c = xc_var_hcache.size; i < c; i ++) { |
|---|
| 491 | xc_gc_expires_one(xc_var_caches[i], xc_var_gc_interval, xc_gc_expires_var_entry_dmz TSRMLS_CC); |
|---|
| 492 | } |
|---|
| 493 | } |
|---|
| 494 | /* }}} */ |
|---|
| 495 | |
|---|
| 496 | static XC_CACHE_APPLY_FUNC(xc_gc_delete_dmz) /* {{{ */ |
|---|
| 497 | { |
|---|
| 498 | xc_entry_t *p, **pp; |
|---|
| 499 | |
|---|
| 500 | pp = &cache->deletes; |
|---|
| 501 | for (p = *pp; p; p = *pp) { |
|---|
| 502 | if (XG(request_time) - p->dtime > 3600) { |
|---|
| 503 | p->refcount = 0; |
|---|
| 504 | /* issue warning here */ |
|---|
| 505 | } |
|---|
| 506 | if (p->refcount == 0) { |
|---|
| 507 | /* unlink */ |
|---|
| 508 | *pp = p->next; |
|---|
| 509 | cache->deletes_count --; |
|---|
| 510 | xc_entry_free_real_dmz(p); |
|---|
| 511 | } |
|---|
| 512 | else { |
|---|
| 513 | pp = &(p->next); |
|---|
| 514 | } |
|---|
| 515 | } |
|---|
| 516 | } |
|---|
| 517 | /* }}} */ |
|---|
| 518 | static XC_CACHE_APPLY_FUNC(xc_gc_deletes_one) /* {{{ */ |
|---|
| 519 | { |
|---|
| 520 | if (cache->deletes && XG(request_time) - cache->last_gc_deletes > xc_deletes_gc_interval) { |
|---|
| 521 | ENTER_LOCK(cache) { |
|---|
| 522 | if (cache->deletes && XG(request_time) - cache->last_gc_deletes > xc_deletes_gc_interval) { |
|---|
| 523 | cache->last_gc_deletes = XG(request_time); |
|---|
| 524 | xc_gc_delete_dmz(cache TSRMLS_CC); |
|---|
| 525 | } |
|---|
| 526 | } LEAVE_LOCK(cache); |
|---|
| 527 | } |
|---|
| 528 | } |
|---|
| 529 | /* }}} */ |
|---|
| 530 | static void xc_gc_deletes(TSRMLS_D) /* {{{ */ |
|---|
| 531 | { |
|---|
| 532 | int i, c; |
|---|
| 533 | |
|---|
| 534 | if (xc_php_caches) { |
|---|
| 535 | for (i = 0, c = xc_php_hcache.size; i < c; i ++) { |
|---|
| 536 | xc_gc_deletes_one(xc_php_caches[i] TSRMLS_CC); |
|---|
| 537 | } |
|---|
| 538 | } |
|---|
| 539 | |
|---|
| 540 | if (xc_var_caches) { |
|---|
| 541 | for (i = 0, c = xc_var_hcache.size; i < c; i ++) { |
|---|
| 542 | xc_gc_deletes_one(xc_var_caches[i] TSRMLS_CC); |
|---|
| 543 | } |
|---|
| 544 | } |
|---|
| 545 | } |
|---|
| 546 | /* }}} */ |
|---|
| 547 | |
|---|
| 548 | /* helper functions for user functions */ |
|---|
| 549 | static void xc_fillinfo_dmz(int cachetype, xc_cache_t *cache, zval *return_value TSRMLS_DC) /* {{{ */ |
|---|
| 550 | { |
|---|
| 551 | zval *blocks, *hits; |
|---|
| 552 | int i; |
|---|
| 553 | const xc_block_t *b; |
|---|
| 554 | #ifndef NDEBUG |
|---|
| 555 | xc_memsize_t avail = 0; |
|---|
| 556 | #endif |
|---|
| 557 | xc_mem_t *mem = cache->mem; |
|---|
| 558 | const xc_mem_handlers_t *handlers = mem->handlers; |
|---|
| 559 | zend_ulong interval; |
|---|
| 560 | if (cachetype == XC_TYPE_PHP) { |
|---|
| 561 | interval = xc_php_ttl ? xc_php_gc_interval : 0; |
|---|
| 562 | } |
|---|
| 563 | else { |
|---|
| 564 | interval = xc_var_gc_interval; |
|---|
| 565 | } |
|---|
| 566 | |
|---|
| 567 | add_assoc_long_ex(return_value, ZEND_STRS("slots"), cache->hentry->size); |
|---|
| 568 | add_assoc_long_ex(return_value, ZEND_STRS("compiling"), cache->compiling); |
|---|
| 569 | add_assoc_long_ex(return_value, ZEND_STRS("misses"), cache->misses); |
|---|
| 570 | add_assoc_long_ex(return_value, ZEND_STRS("hits"), cache->hits); |
|---|
| 571 | add_assoc_long_ex(return_value, ZEND_STRS("clogs"), cache->clogs); |
|---|
| 572 | add_assoc_long_ex(return_value, ZEND_STRS("ooms"), cache->ooms); |
|---|
| 573 | add_assoc_long_ex(return_value, ZEND_STRS("errors"), cache->errors); |
|---|
| 574 | |
|---|
| 575 | add_assoc_long_ex(return_value, ZEND_STRS("cached"), cache->entries_count); |
|---|
| 576 | add_assoc_long_ex(return_value, ZEND_STRS("deleted"), cache->deletes_count); |
|---|
| 577 | if (interval) { |
|---|
| 578 | time_t gc = (cache->last_gc_expires + interval) - XG(request_time); |
|---|
| 579 | add_assoc_long_ex(return_value, ZEND_STRS("gc"), gc > 0 ? gc : 0); |
|---|
| 580 | } |
|---|
| 581 | else { |
|---|
| 582 | add_assoc_null_ex(return_value, ZEND_STRS("gc")); |
|---|
| 583 | } |
|---|
| 584 | MAKE_STD_ZVAL(hits); |
|---|
| 585 | array_init(hits); |
|---|
| 586 | for (i = 0; i < sizeof(cache->hits_by_hour) / sizeof(cache->hits_by_hour[0]); i ++) { |
|---|
| 587 | add_next_index_long(hits, (long) cache->hits_by_hour[i]); |
|---|
| 588 | } |
|---|
| 589 | add_assoc_zval_ex(return_value, ZEND_STRS("hits_by_hour"), hits); |
|---|
| 590 | |
|---|
| 591 | MAKE_STD_ZVAL(hits); |
|---|
| 592 | array_init(hits); |
|---|
| 593 | for (i = 0; i < sizeof(cache->hits_by_second) / sizeof(cache->hits_by_second[0]); i ++) { |
|---|
| 594 | add_next_index_long(hits, (long) cache->hits_by_second[i]); |
|---|
| 595 | } |
|---|
| 596 | add_assoc_zval_ex(return_value, ZEND_STRS("hits_by_second"), hits); |
|---|
| 597 | |
|---|
| 598 | MAKE_STD_ZVAL(blocks); |
|---|
| 599 | array_init(blocks); |
|---|
| 600 | |
|---|
| 601 | add_assoc_long_ex(return_value, ZEND_STRS("size"), handlers->size(mem)); |
|---|
| 602 | add_assoc_long_ex(return_value, ZEND_STRS("avail"), handlers->avail(mem)); |
|---|
| 603 | add_assoc_bool_ex(return_value, ZEND_STRS("can_readonly"), xc_readonly_protection); |
|---|
| 604 | |
|---|
| 605 | for (b = handlers->freeblock_first(mem); b; b = handlers->freeblock_next(b)) { |
|---|
| 606 | zval *bi; |
|---|
| 607 | |
|---|
| 608 | MAKE_STD_ZVAL(bi); |
|---|
| 609 | array_init(bi); |
|---|
| 610 | |
|---|
| 611 | add_assoc_long_ex(bi, ZEND_STRS("size"), handlers->block_size(b)); |
|---|
| 612 | add_assoc_long_ex(bi, ZEND_STRS("offset"), handlers->block_offset(mem, b)); |
|---|
| 613 | add_next_index_zval(blocks, bi); |
|---|
| 614 | #ifndef NDEBUG |
|---|
| 615 | avail += handlers->block_size(b); |
|---|
| 616 | #endif |
|---|
| 617 | } |
|---|
| 618 | add_assoc_zval_ex(return_value, ZEND_STRS("free_blocks"), blocks); |
|---|
| 619 | #ifndef NDEBUG |
|---|
| 620 | assert(avail == handlers->avail(mem)); |
|---|
| 621 | #endif |
|---|
| 622 | } |
|---|
| 623 | /* }}} */ |
|---|
| 624 | static void xc_fillentry_dmz(xc_entry_t *entry, int del, zval *list TSRMLS_DC) /* {{{ */ |
|---|
| 625 | { |
|---|
| 626 | zval* ei; |
|---|
| 627 | xc_entry_data_php_t *php; |
|---|
| 628 | xc_entry_data_var_t *var; |
|---|
| 629 | |
|---|
| 630 | ALLOC_INIT_ZVAL(ei); |
|---|
| 631 | array_init(ei); |
|---|
| 632 | |
|---|
| 633 | add_assoc_long_ex(ei, ZEND_STRS("refcount"), entry->refcount); |
|---|
| 634 | add_assoc_long_ex(ei, ZEND_STRS("hits"), entry->hits); |
|---|
| 635 | add_assoc_long_ex(ei, ZEND_STRS("ctime"), entry->ctime); |
|---|
| 636 | add_assoc_long_ex(ei, ZEND_STRS("atime"), entry->atime); |
|---|
| 637 | add_assoc_long_ex(ei, ZEND_STRS("hvalue"), entry->hvalue); |
|---|
| 638 | if (del) { |
|---|
| 639 | add_assoc_long_ex(ei, ZEND_STRS("dtime"), entry->dtime); |
|---|
| 640 | } |
|---|
| 641 | #ifdef IS_UNICODE |
|---|
| 642 | do { |
|---|
| 643 | zval *zv; |
|---|
| 644 | ALLOC_INIT_ZVAL(zv); |
|---|
| 645 | switch (entry->name_type) { |
|---|
| 646 | case IS_UNICODE: |
|---|
| 647 | ZVAL_UNICODEL(zv, entry->name.ustr.val, entry->name.ustr.len, 1); |
|---|
| 648 | break; |
|---|
| 649 | case IS_STRING: |
|---|
| 650 | ZVAL_STRINGL(zv, entry->name.str.val, entry->name.str.len, 1); |
|---|
| 651 | break; |
|---|
| 652 | default: |
|---|
| 653 | assert(0); |
|---|
| 654 | } |
|---|
| 655 | zv->type = entry->name_type; |
|---|
| 656 | add_assoc_zval_ex(ei, ZEND_STRS("name"), zv); |
|---|
| 657 | } while (0); |
|---|
| 658 | #else |
|---|
| 659 | add_assoc_stringl_ex(ei, ZEND_STRS("name"), entry->name.str.val, entry->name.str.len, 1); |
|---|
| 660 | #endif |
|---|
| 661 | switch (entry->type) { |
|---|
| 662 | case XC_TYPE_PHP: |
|---|
| 663 | php = entry->data.php; |
|---|
| 664 | add_assoc_long_ex(ei, ZEND_STRS("size"), entry->size + php->size); |
|---|
| 665 | add_assoc_long_ex(ei, ZEND_STRS("phprefcount"), php->refcount); |
|---|
| 666 | add_assoc_long_ex(ei, ZEND_STRS("sourcesize"), php->sourcesize); |
|---|
| 667 | #ifdef HAVE_INODE |
|---|
| 668 | add_assoc_long_ex(ei, ZEND_STRS("device"), entry->device); |
|---|
| 669 | add_assoc_long_ex(ei, ZEND_STRS("inode"), entry->inode); |
|---|
| 670 | #endif |
|---|
| 671 | add_assoc_long_ex(ei, ZEND_STRS("mtime"), entry->mtime); |
|---|
| 672 | |
|---|
| 673 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 674 | add_assoc_long_ex(ei, ZEND_STRS("constinfo_cnt"), php->constinfo_cnt); |
|---|
| 675 | #endif |
|---|
| 676 | add_assoc_long_ex(ei, ZEND_STRS("function_cnt"), php->funcinfo_cnt); |
|---|
| 677 | add_assoc_long_ex(ei, ZEND_STRS("class_cnt"), php->classinfo_cnt); |
|---|
| 678 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 679 | add_assoc_long_ex(ei, ZEND_STRS("autoglobal_cnt"),php->autoglobal_cnt); |
|---|
| 680 | #endif |
|---|
| 681 | break; |
|---|
| 682 | |
|---|
| 683 | case XC_TYPE_VAR: |
|---|
| 684 | var = entry->data.var; |
|---|
| 685 | add_assoc_long_ex(ei, ZEND_STRS("size"), entry->size); |
|---|
| 686 | break; |
|---|
| 687 | |
|---|
| 688 | default: |
|---|
| 689 | assert(0); |
|---|
| 690 | } |
|---|
| 691 | |
|---|
| 692 | add_next_index_zval(list, ei); |
|---|
| 693 | } |
|---|
| 694 | /* }}} */ |
|---|
| 695 | static void xc_filllist_dmz(xc_cache_t *cache, zval *return_value TSRMLS_DC) /* {{{ */ |
|---|
| 696 | { |
|---|
| 697 | zval* list; |
|---|
| 698 | int i, c; |
|---|
| 699 | xc_entry_t *e; |
|---|
| 700 | |
|---|
| 701 | ALLOC_INIT_ZVAL(list); |
|---|
| 702 | array_init(list); |
|---|
| 703 | |
|---|
| 704 | for (i = 0, c = cache->hentry->size; i < c; i ++) { |
|---|
| 705 | for (e = cache->entries[i]; e; e = e->next) { |
|---|
| 706 | xc_fillentry_dmz(e, 0, list TSRMLS_CC); |
|---|
| 707 | } |
|---|
| 708 | } |
|---|
| 709 | add_assoc_zval(return_value, "cache_list", list); |
|---|
| 710 | |
|---|
| 711 | ALLOC_INIT_ZVAL(list); |
|---|
| 712 | array_init(list); |
|---|
| 713 | for (e = cache->deletes; e; e = e->next) { |
|---|
| 714 | xc_fillentry_dmz(e, 1, list TSRMLS_CC); |
|---|
| 715 | } |
|---|
| 716 | add_assoc_zval(return_value, "deleted_list", list); |
|---|
| 717 | } |
|---|
| 718 | /* }}} */ |
|---|
| 719 | |
|---|
| 720 | static zend_op_array *xc_entry_install(xc_entry_t *xce, zend_file_handle *h TSRMLS_DC) /* {{{ */ |
|---|
| 721 | { |
|---|
| 722 | zend_uint i; |
|---|
| 723 | xc_entry_data_php_t *p = xce->data.php; |
|---|
| 724 | zend_op_array *old_active_op_array = CG(active_op_array); |
|---|
| 725 | #ifndef ZEND_ENGINE_2 |
|---|
| 726 | ALLOCA_FLAG(use_heap) |
|---|
| 727 | /* new ptr which is stored inside CG(class_table) */ |
|---|
| 728 | xc_cest_t **new_cest_ptrs = (xc_cest_t **)my_do_alloca(sizeof(xc_cest_t*) * p->classinfo_cnt, use_heap); |
|---|
| 729 | #endif |
|---|
| 730 | |
|---|
| 731 | CG(active_op_array) = p->op_array; |
|---|
| 732 | |
|---|
| 733 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 734 | /* install constant */ |
|---|
| 735 | for (i = 0; i < p->constinfo_cnt; i ++) { |
|---|
| 736 | xc_constinfo_t *ci = &p->constinfos[i]; |
|---|
| 737 | xc_install_constant(xce->name.str.val, &ci->constant, |
|---|
| 738 | UNISW(0, ci->type), ci->key, ci->key_size, ci->h TSRMLS_CC); |
|---|
| 739 | } |
|---|
| 740 | #endif |
|---|
| 741 | |
|---|
| 742 | /* install function */ |
|---|
| 743 | for (i = 0; i < p->funcinfo_cnt; i ++) { |
|---|
| 744 | xc_funcinfo_t *fi = &p->funcinfos[i]; |
|---|
| 745 | xc_install_function(xce->name.str.val, &fi->func, |
|---|
| 746 | UNISW(0, fi->type), fi->key, fi->key_size, fi->h TSRMLS_CC); |
|---|
| 747 | } |
|---|
| 748 | |
|---|
| 749 | /* install class */ |
|---|
| 750 | for (i = 0; i < p->classinfo_cnt; i ++) { |
|---|
| 751 | xc_classinfo_t *ci = &p->classinfos[i]; |
|---|
| 752 | #ifndef ZEND_ENGINE_2 |
|---|
| 753 | zend_class_entry *ce = CestToCePtr(ci->cest); |
|---|
| 754 | /* fix pointer to the be which inside class_table */ |
|---|
| 755 | if (ce->parent) { |
|---|
| 756 | zend_uint class_idx = (/* class_num */ (int) (long) ce->parent) - 1; |
|---|
| 757 | assert(class_idx < i); |
|---|
| 758 | ci->cest.parent = new_cest_ptrs[class_idx]; |
|---|
| 759 | } |
|---|
| 760 | new_cest_ptrs[i] = |
|---|
| 761 | #endif |
|---|
| 762 | #ifdef ZEND_COMPILE_DELAYED_BINDING |
|---|
| 763 | xc_install_class(xce->name.str.val, &ci->cest, -1, |
|---|
| 764 | UNISW(0, ci->type), ci->key, ci->key_size, ci->h TSRMLS_CC); |
|---|
| 765 | #else |
|---|
| 766 | xc_install_class(xce->name.str.val, &ci->cest, ci->oplineno, |
|---|
| 767 | UNISW(0, ci->type), ci->key, ci->key_size, ci->h TSRMLS_CC); |
|---|
| 768 | #endif |
|---|
| 769 | } |
|---|
| 770 | |
|---|
| 771 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 772 | /* trigger auto_globals jit */ |
|---|
| 773 | for (i = 0; i < p->autoglobal_cnt; i ++) { |
|---|
| 774 | xc_autoglobal_t *aginfo = &p->autoglobals[i]; |
|---|
| 775 | /* |
|---|
| 776 | zend_auto_global *auto_global; |
|---|
| 777 | if (zend_u_hash_quick_find(CG(auto_globals), aginfo->type, aginfo->key, aginfo->key_len+1, aginfo->h, (void **) &auto_global)==SUCCESS) { |
|---|
| 778 | if (auto_global->armed) { |
|---|
| 779 | auto_global->armed = auto_global->auto_global_callback(auto_global->name, auto_global->name_len TSRMLS_CC); |
|---|
| 780 | } |
|---|
| 781 | } |
|---|
| 782 | */ |
|---|
| 783 | zend_u_is_auto_global(aginfo->type, aginfo->key, aginfo->key_len TSRMLS_CC); |
|---|
| 784 | } |
|---|
| 785 | #endif |
|---|
| 786 | #ifdef XCACHE_ERROR_CACHING |
|---|
| 787 | /* restore trigger errors */ |
|---|
| 788 | for (i = 0; i < p->compilererror_cnt; i ++) { |
|---|
| 789 | xc_compilererror_t *error = &p->compilererrors[i]; |
|---|
| 790 | CG(zend_lineno) = error->lineno; |
|---|
| 791 | zend_error(error->type, "%s", error->error); |
|---|
| 792 | } |
|---|
| 793 | CG(zend_lineno) = 0; |
|---|
| 794 | #endif |
|---|
| 795 | |
|---|
| 796 | i = 1; |
|---|
| 797 | zend_hash_add(&EG(included_files), xce->name.str.val, xce->name.str.len+1, (void *)&i, sizeof(int), NULL); |
|---|
| 798 | if (h) { |
|---|
| 799 | zend_llist_add_element(&CG(open_files), h); |
|---|
| 800 | } |
|---|
| 801 | |
|---|
| 802 | #ifndef ZEND_ENGINE_2 |
|---|
| 803 | my_free_alloca(new_cest_ptrs, use_heap); |
|---|
| 804 | #endif |
|---|
| 805 | CG(active_op_array) = old_active_op_array; |
|---|
| 806 | return p->op_array; |
|---|
| 807 | } |
|---|
| 808 | /* }}} */ |
|---|
| 809 | |
|---|
| 810 | static inline void xc_entry_unholds_real(xc_stack_t *holds, xc_cache_t **caches, int cachecount TSRMLS_DC) /* {{{ */ |
|---|
| 811 | { |
|---|
| 812 | int i; |
|---|
| 813 | xc_stack_t *s; |
|---|
| 814 | xc_cache_t *cache; |
|---|
| 815 | xc_entry_t *xce; |
|---|
| 816 | |
|---|
| 817 | for (i = 0; i < cachecount; i ++) { |
|---|
| 818 | s = &holds[i]; |
|---|
| 819 | TRACE("holded %d", xc_stack_count(s)); |
|---|
| 820 | if (xc_stack_count(s)) { |
|---|
| 821 | cache = ((xc_entry_t *)xc_stack_top(s))->cache; |
|---|
| 822 | ENTER_LOCK(cache) { |
|---|
| 823 | while (xc_stack_count(s)) { |
|---|
| 824 | xce = (xc_entry_t*) xc_stack_pop(s); |
|---|
| 825 | TRACE("unhold %s", xce->name.str.val); |
|---|
| 826 | xce->refcount --; |
|---|
| 827 | assert(xce->refcount >= 0); |
|---|
| 828 | } |
|---|
| 829 | } LEAVE_LOCK(cache); |
|---|
| 830 | } |
|---|
| 831 | } |
|---|
| 832 | } |
|---|
| 833 | /* }}} */ |
|---|
| 834 | static void xc_entry_unholds(TSRMLS_D) /* {{{ */ |
|---|
| 835 | { |
|---|
| 836 | if (xc_php_caches) { |
|---|
| 837 | xc_entry_unholds_real(XG(php_holds), xc_php_caches, xc_php_hcache.size TSRMLS_CC); |
|---|
| 838 | } |
|---|
| 839 | |
|---|
| 840 | if (xc_var_caches) { |
|---|
| 841 | xc_entry_unholds_real(XG(var_holds), xc_var_caches, xc_var_hcache.size TSRMLS_CC); |
|---|
| 842 | } |
|---|
| 843 | } |
|---|
| 844 | /* }}} */ |
|---|
| 845 | static int xc_stat(const char *filename, const char *include_path, struct stat *pbuf TSRMLS_DC) /* {{{ */ |
|---|
| 846 | { |
|---|
| 847 | char filepath[MAXPATHLEN]; |
|---|
| 848 | char *paths, *path; |
|---|
| 849 | char *tokbuf; |
|---|
| 850 | int size = strlen(include_path) + 1; |
|---|
| 851 | char tokens[] = { DEFAULT_DIR_SEPARATOR, '\0' }; |
|---|
| 852 | int ret; |
|---|
| 853 | ALLOCA_FLAG(use_heap) |
|---|
| 854 | |
|---|
| 855 | paths = (char *)my_do_alloca(size, use_heap); |
|---|
| 856 | memcpy(paths, include_path, size); |
|---|
| 857 | |
|---|
| 858 | for (path = php_strtok_r(paths, tokens, &tokbuf); path; path = php_strtok_r(NULL, tokens, &tokbuf)) { |
|---|
| 859 | if (snprintf(filepath, sizeof(filepath), "%s/%s", path, filename) < MAXPATHLEN - 1) { |
|---|
| 860 | if (VCWD_STAT(filepath, pbuf) == 0) { |
|---|
| 861 | ret = SUCCESS; |
|---|
| 862 | goto finish; |
|---|
| 863 | } |
|---|
| 864 | } |
|---|
| 865 | } |
|---|
| 866 | |
|---|
| 867 | /* fall back to current directory */ |
|---|
| 868 | if (zend_is_executing(TSRMLS_C)) { |
|---|
| 869 | char *path = zend_get_executed_filename(TSRMLS_C); |
|---|
| 870 | if (path && path[0] != '[') { |
|---|
| 871 | int len = strlen(path); |
|---|
| 872 | while ((--len >= 0) && !IS_SLASH(path[len])) { |
|---|
| 873 | /* skipped */ |
|---|
| 874 | } |
|---|
| 875 | if (len > 0 && len + strlen(filename) + 1 < MAXPATHLEN - 1) { |
|---|
| 876 | strcpy(filepath, path); |
|---|
| 877 | strcpy(filepath + len + 1, filename); |
|---|
| 878 | if (VCWD_STAT(filepath, pbuf) == 0) { |
|---|
| 879 | ret = SUCCESS; |
|---|
| 880 | goto finish; |
|---|
| 881 | } |
|---|
| 882 | } |
|---|
| 883 | } |
|---|
| 884 | } |
|---|
| 885 | |
|---|
| 886 | ret = FAILURE; |
|---|
| 887 | |
|---|
| 888 | finish: |
|---|
| 889 | my_free_alloca(paths, use_heap); |
|---|
| 890 | |
|---|
| 891 | return ret; |
|---|
| 892 | } |
|---|
| 893 | /* }}} */ |
|---|
| 894 | |
|---|
| 895 | #define HASH(i) (i) |
|---|
| 896 | #define HASH_ZSTR_L(t, s, l) HASH(zend_u_inline_hash_func(t, s, (l + 1) * sizeof(UChar))) |
|---|
| 897 | #define HASH_STR_S(s, l) HASH(zend_inline_hash_func(s, l)) |
|---|
| 898 | #define HASH_STR_L(s, l) HASH_STR_S(s, l + 1) |
|---|
| 899 | #define HASH_STR(s) HASH_STR_L(s, strlen(s) + 1) |
|---|
| 900 | #define HASH_NUM(n) HASH(n) |
|---|
| 901 | static inline xc_hash_value_t xc_hash_fold(xc_hash_value_t hvalue, const xc_hash_t *hasher) /* {{{ fold hash bits as needed */ |
|---|
| 902 | { |
|---|
| 903 | xc_hash_value_t folded = 0; |
|---|
| 904 | while (hvalue) { |
|---|
| 905 | folded ^= (hvalue & hasher->mask); |
|---|
| 906 | hvalue >>= hasher->bits; |
|---|
| 907 | } |
|---|
| 908 | return folded; |
|---|
| 909 | } |
|---|
| 910 | /* }}} */ |
|---|
| 911 | static inline xc_hash_value_t xc_entry_hash_name(xc_entry_t *xce TSRMLS_DC) /* {{{ */ |
|---|
| 912 | { |
|---|
| 913 | return UNISW(NOTHING, UG(unicode) ? HASH_ZSTR_L(xce->name_type, xce->name.uni.val, xce->name.uni.len) :) |
|---|
| 914 | HASH_STR_L(xce->name.str.val, xce->name.str.len); |
|---|
| 915 | } |
|---|
| 916 | /* }}} */ |
|---|
| 917 | #define xc_entry_hash_var xc_entry_hash_name |
|---|
| 918 | static inline xc_hash_value_t xc_entry_hash_php(xc_entry_t *xce TSRMLS_DC) /* {{{ */ |
|---|
| 919 | { |
|---|
| 920 | #ifdef HAVE_INODE |
|---|
| 921 | if (xce->inode) { |
|---|
| 922 | return HASH(xce->device + xce->inode); |
|---|
| 923 | } |
|---|
| 924 | #endif |
|---|
| 925 | return xc_entry_hash_name(xce TSRMLS_CC); |
|---|
| 926 | } |
|---|
| 927 | /* }}} */ |
|---|
| 928 | static inline xc_hash_value_t xc_entry_hash_php_basename(xc_entry_t *xce TSRMLS_DC) /* {{{ */ |
|---|
| 929 | { |
|---|
| 930 | #ifdef IS_UNICODE |
|---|
| 931 | if (UG(unicode) && xce->name_type == IS_UNICODE) { |
|---|
| 932 | zstr basename; |
|---|
| 933 | size_t basename_len; |
|---|
| 934 | php_u_basename(xce->name.ustr.val, xce->name.ustr.len, NULL, 0, &basename.u, &basename_len TSRMLS_CC); |
|---|
| 935 | return HASH_ZSTR_L(IS_UNICODE, basename, basename_len); |
|---|
| 936 | } |
|---|
| 937 | else |
|---|
| 938 | #endif |
|---|
| 939 | { |
|---|
| 940 | char *basename; |
|---|
| 941 | xc_hash_value_t h; |
|---|
| 942 | size_t basename_len; |
|---|
| 943 | #ifdef ZEND_ENGINE_2 |
|---|
| 944 | php_basename(xce->name.str.val, xce->name.str.len, "", 0, &basename, &basename_len TSRMLS_CC); |
|---|
| 945 | #else |
|---|
| 946 | basename = php_basename(xce->name.str.val, xce->name.str.len, "", 0); |
|---|
| 947 | basename_len = strlen(basename); |
|---|
| 948 | #endif |
|---|
| 949 | h = HASH_STR_L(basename, basename_len); |
|---|
| 950 | efree(basename); |
|---|
| 951 | return h; |
|---|
| 952 | } |
|---|
| 953 | } |
|---|
| 954 | /* }}} */ |
|---|
| 955 | static int xc_entry_init_key_php(xc_entry_t *xce, char *filename, char *opened_path_buffer TSRMLS_DC) /* {{{ */ |
|---|
| 956 | { |
|---|
| 957 | struct stat buf, *pbuf; |
|---|
| 958 | xc_hash_value_t hv; |
|---|
| 959 | int cacheid; |
|---|
| 960 | xc_entry_data_php_t *php; |
|---|
| 961 | char *ptr; |
|---|
| 962 | time_t delta; |
|---|
| 963 | |
|---|
| 964 | if (!filename || !SG(request_info).path_translated) { |
|---|
| 965 | return FAILURE; |
|---|
| 966 | } |
|---|
| 967 | |
|---|
| 968 | if (strstr(filename, "://") != NULL) { |
|---|
| 969 | return FAILURE; |
|---|
| 970 | } |
|---|
| 971 | |
|---|
| 972 | php = xce->data.php; |
|---|
| 973 | |
|---|
| 974 | if (XG(stat)) { |
|---|
| 975 | if (strcmp(SG(request_info).path_translated, filename) == 0) { |
|---|
| 976 | /* sapi has already done this stat() for us */ |
|---|
| 977 | pbuf = sapi_get_stat(TSRMLS_C); |
|---|
| 978 | if (pbuf) { |
|---|
| 979 | goto stat_done; |
|---|
| 980 | } |
|---|
| 981 | } |
|---|
| 982 | |
|---|
| 983 | /* absolute path */ |
|---|
| 984 | pbuf = &buf; |
|---|
| 985 | if (IS_ABSOLUTE_PATH(filename, strlen(filename))) { |
|---|
| 986 | if (VCWD_STAT(filename, pbuf) != 0) { |
|---|
| 987 | return FAILURE; |
|---|
| 988 | } |
|---|
| 989 | goto stat_done; |
|---|
| 990 | } |
|---|
| 991 | |
|---|
| 992 | /* relative path */ |
|---|
| 993 | if (*filename == '.' && (IS_SLASH(filename[1]) || filename[1] == '.')) { |
|---|
| 994 | ptr = filename + 1; |
|---|
| 995 | if (*ptr == '.') { |
|---|
| 996 | while (*(++ptr) == '.'); |
|---|
| 997 | if (!IS_SLASH(*ptr)) { |
|---|
| 998 | goto not_relative_path; |
|---|
| 999 | } |
|---|
| 1000 | } |
|---|
| 1001 | |
|---|
| 1002 | if (VCWD_STAT(filename, pbuf) != 0) { |
|---|
| 1003 | return FAILURE; |
|---|
| 1004 | } |
|---|
| 1005 | goto stat_done; |
|---|
| 1006 | } |
|---|
| 1007 | not_relative_path: |
|---|
| 1008 | |
|---|
| 1009 | /* use include_path */ |
|---|
| 1010 | if (xc_stat(filename, PG(include_path), pbuf TSRMLS_CC) != SUCCESS) { |
|---|
| 1011 | return FAILURE; |
|---|
| 1012 | } |
|---|
| 1013 | |
|---|
| 1014 | /* fall */ |
|---|
| 1015 | |
|---|
| 1016 | stat_done: |
|---|
| 1017 | delta = XG(request_time) - pbuf->st_mtime; |
|---|
| 1018 | if (abs(delta) < 2 && !xc_test) { |
|---|
| 1019 | return FAILURE; |
|---|
| 1020 | } |
|---|
| 1021 | |
|---|
| 1022 | xce->mtime = pbuf->st_mtime; |
|---|
| 1023 | #ifdef HAVE_INODE |
|---|
| 1024 | xce->device = pbuf->st_dev; |
|---|
| 1025 | xce->inode = pbuf->st_ino; |
|---|
| 1026 | #endif |
|---|
| 1027 | php->sourcesize = pbuf->st_size; |
|---|
| 1028 | } |
|---|
| 1029 | else { /* XG(inode) */ |
|---|
| 1030 | xce->mtime = 0; |
|---|
| 1031 | #ifdef HAVE_INODE |
|---|
| 1032 | xce->device = 0; |
|---|
| 1033 | xce->inode = 0; |
|---|
| 1034 | #endif |
|---|
| 1035 | php->sourcesize = 0; |
|---|
| 1036 | } |
|---|
| 1037 | |
|---|
| 1038 | #ifdef HAVE_INODE |
|---|
| 1039 | if (!xce->inode) |
|---|
| 1040 | #endif |
|---|
| 1041 | { |
|---|
| 1042 | /* hash on filename, let's expand it to real path */ |
|---|
| 1043 | /* FIXME */ |
|---|
| 1044 | filename = expand_filepath(filename, opened_path_buffer TSRMLS_CC); |
|---|
| 1045 | if (filename == NULL) { |
|---|
| 1046 | return FAILURE; |
|---|
| 1047 | } |
|---|
| 1048 | } |
|---|
| 1049 | |
|---|
| 1050 | UNISW(NOTHING, xce->name_type = IS_STRING;) |
|---|
| 1051 | xce->name.str.val = filename; |
|---|
| 1052 | xce->name.str.len = strlen(filename); |
|---|
| 1053 | |
|---|
| 1054 | if (xc_php_hcache.size > 1) { |
|---|
| 1055 | hv = xc_entry_hash_php_basename(xce TSRMLS_CC); |
|---|
| 1056 | cacheid = xc_hash_fold(hv, &xc_php_hcache); |
|---|
| 1057 | } |
|---|
| 1058 | else { |
|---|
| 1059 | cacheid = 0; |
|---|
| 1060 | } |
|---|
| 1061 | xce->cache = xc_php_caches[cacheid]; |
|---|
| 1062 | |
|---|
| 1063 | hv = xc_entry_hash_php(xce TSRMLS_CC); |
|---|
| 1064 | xce->hvalue = xc_hash_fold(hv, &xc_php_hentry); |
|---|
| 1065 | |
|---|
| 1066 | xce->type = XC_TYPE_PHP; |
|---|
| 1067 | return SUCCESS; |
|---|
| 1068 | } |
|---|
| 1069 | /* }}} */ |
|---|
| 1070 | static inline xc_hash_value_t xc_php_hash_md5(xc_entry_data_php_t *php TSRMLS_DC) /* {{{ */ |
|---|
| 1071 | { |
|---|
| 1072 | return HASH_STR_S(php->md5, sizeof(php->md5)); |
|---|
| 1073 | } |
|---|
| 1074 | /* }}} */ |
|---|
| 1075 | static int xc_entry_init_key_php_md5(xc_entry_data_php_t *php, xc_entry_t *xce TSRMLS_DC) /* {{{ */ |
|---|
| 1076 | { |
|---|
| 1077 | unsigned char buf[1024]; |
|---|
| 1078 | PHP_MD5_CTX context; |
|---|
| 1079 | int n; |
|---|
| 1080 | php_stream *stream; |
|---|
| 1081 | xc_hash_value_t hv; |
|---|
| 1082 | ulong old_rsid = EG(regular_list).nNextFreeElement; |
|---|
| 1083 | |
|---|
| 1084 | stream = php_stream_open_wrapper(xce->name.str.val, "rb", USE_PATH | REPORT_ERRORS | ENFORCE_SAFE_MODE | STREAM_DISABLE_OPEN_BASEDIR, NULL); |
|---|
| 1085 | if (!stream) { |
|---|
| 1086 | return FAILURE; |
|---|
| 1087 | } |
|---|
| 1088 | |
|---|
| 1089 | PHP_MD5Init(&context); |
|---|
| 1090 | while ((n = php_stream_read(stream, (char *) buf, sizeof(buf))) > 0) { |
|---|
| 1091 | PHP_MD5Update(&context, buf, n); |
|---|
| 1092 | } |
|---|
| 1093 | PHP_MD5Final((unsigned char *) php->md5, &context); |
|---|
| 1094 | |
|---|
| 1095 | php_stream_close(stream); |
|---|
| 1096 | if (EG(regular_list).nNextFreeElement == old_rsid + 1) { |
|---|
| 1097 | EG(regular_list).nNextFreeElement = old_rsid; |
|---|
| 1098 | } |
|---|
| 1099 | |
|---|
| 1100 | if (n < 0) { |
|---|
| 1101 | return FAILURE; |
|---|
| 1102 | } |
|---|
| 1103 | |
|---|
| 1104 | hv = xc_php_hash_md5(php TSRMLS_CC); |
|---|
| 1105 | php->cache = xce->cache; |
|---|
| 1106 | php->hvalue = (hv & php->cache->hphp->mask); |
|---|
| 1107 | #ifdef XCACHE_DEBUG |
|---|
| 1108 | { |
|---|
| 1109 | char md5str[33]; |
|---|
| 1110 | make_digest(md5str, (unsigned char *) php->md5); |
|---|
| 1111 | TRACE("md5 %s", md5str); |
|---|
| 1112 | } |
|---|
| 1113 | #endif |
|---|
| 1114 | |
|---|
| 1115 | return SUCCESS; |
|---|
| 1116 | } |
|---|
| 1117 | /* }}} */ |
|---|
| 1118 | #ifndef ZEND_COMPILE_DELAYED_BINDING |
|---|
| 1119 | static void xc_cache_early_binding_class_cb(zend_op *opline, int oplineno, void *data TSRMLS_DC) /* {{{ */ |
|---|
| 1120 | { |
|---|
| 1121 | char *class_name; |
|---|
| 1122 | int i, class_len; |
|---|
| 1123 | xc_cest_t cest; |
|---|
| 1124 | xc_entry_data_php_t *php = (xc_entry_data_php_t *) data; |
|---|
| 1125 | |
|---|
| 1126 | class_name = opline->op1.u.constant.value.str.val; |
|---|
| 1127 | class_len = opline->op1.u.constant.value.str.len; |
|---|
| 1128 | if (zend_hash_find(CG(class_table), class_name, class_len, (void **) &cest) == FAILURE) { |
|---|
| 1129 | assert(0); |
|---|
| 1130 | } |
|---|
| 1131 | TRACE("got ZEND_DECLARE_INHERITED_CLASS: %s", class_name + 1); |
|---|
| 1132 | /* let's see which class */ |
|---|
| 1133 | for (i = 0; i < php->classinfo_cnt; i ++) { |
|---|
| 1134 | if (memcmp(ZSTR_S(php->classinfos[i].key), class_name, class_len) == 0) { |
|---|
| 1135 | php->classinfos[i].oplineno = oplineno; |
|---|
| 1136 | php->have_early_binding = 1; |
|---|
| 1137 | break; |
|---|
| 1138 | } |
|---|
| 1139 | } |
|---|
| 1140 | |
|---|
| 1141 | if (i == php->classinfo_cnt) { |
|---|
| 1142 | assert(0); |
|---|
| 1143 | } |
|---|
| 1144 | } |
|---|
| 1145 | /* }}} */ |
|---|
| 1146 | #endif |
|---|
| 1147 | |
|---|
| 1148 | /* {{{ Constant Usage */ |
|---|
| 1149 | #define xcache_op1_is_file 1 |
|---|
| 1150 | #define xcache_op1_is_dir 2 |
|---|
| 1151 | #define xcache_op2_is_file 4 |
|---|
| 1152 | #define xcache_op2_is_dir 8 |
|---|
| 1153 | typedef struct { |
|---|
| 1154 | zend_bool filepath_used; |
|---|
| 1155 | zend_bool dirpath_used; |
|---|
| 1156 | zend_bool ufilepath_used; |
|---|
| 1157 | zend_bool udirpath_used; |
|---|
| 1158 | } xc_const_usage_t; |
|---|
| 1159 | /* }}} */ |
|---|
| 1160 | static void xc_collect_op_array_info(xc_entry_data_php_t *php, xc_const_usage_t *usage, xc_op_array_info_t *op_array_info, zend_op_array *op_array TSRMLS_DC) /* {{{ */ |
|---|
| 1161 | { |
|---|
| 1162 | int oplineno; |
|---|
| 1163 | xc_vector_t vector_int; |
|---|
| 1164 | |
|---|
| 1165 | xc_vector_init(int, &vector_int); |
|---|
| 1166 | |
|---|
| 1167 | #define XCACHE_CHECK_OP(type, op) \ |
|---|
| 1168 | if (zend_binary_strcmp(Z_STRVAL(opline->op.u.constant), Z_STRLEN(opline->op.u.constant), php->type##path, php->type##path_len) == 0) { \ |
|---|
| 1169 | usage->type##path_used = 1; \ |
|---|
| 1170 | oplineinfo |= xcache_##op##_is_##type; \ |
|---|
| 1171 | } |
|---|
| 1172 | |
|---|
| 1173 | #define XCACHE_U_CHECK_OP(type, op) \ |
|---|
| 1174 | if (zend_u_##binary_strcmp(Z_USTRVAL(opline->op.u.constant), Z_USTRLEN(opline->op.u.constant), php->u##type##path, php->u##type##path_len) == 0) { \ |
|---|
| 1175 | usage->u##type##path_used = 1; \ |
|---|
| 1176 | oplineinfo |= xcache_##op##_is_##type; \ |
|---|
| 1177 | } |
|---|
| 1178 | |
|---|
| 1179 | for (oplineno = 0; oplineno < op_array->last; oplineno++) { |
|---|
| 1180 | zend_op *opline = &op_array->opcodes[oplineno]; |
|---|
| 1181 | int oplineinfo = 0; |
|---|
| 1182 | if (opline->op1.op_type == IS_CONST) { |
|---|
| 1183 | if (Z_TYPE(opline->op1.u.constant) == IS_STRING) { |
|---|
| 1184 | XCACHE_CHECK_OP(file, op1) |
|---|
| 1185 | else XCACHE_CHECK_OP(dir, op1) |
|---|
| 1186 | } |
|---|
| 1187 | |
|---|
| 1188 | #ifdef IS_UNICODE |
|---|
| 1189 | else if (Z_TYPE(opline->op1.u.constant) == IS_UNICODE) { |
|---|
| 1190 | XCACHE_U_CHECK_OP(file, op1) |
|---|
| 1191 | else XCACHE_U_CHECK_OP(dir, op1) |
|---|
| 1192 | } |
|---|
| 1193 | #endif |
|---|
| 1194 | } |
|---|
| 1195 | if (opline->op2.op_type == IS_CONST) { |
|---|
| 1196 | if (Z_TYPE(opline->op2.u.constant) == IS_STRING) { |
|---|
| 1197 | XCACHE_CHECK_OP(file, op2) |
|---|
| 1198 | else XCACHE_CHECK_OP(dir, op2) |
|---|
| 1199 | } |
|---|
| 1200 | |
|---|
| 1201 | #ifdef IS_UNICODE |
|---|
| 1202 | else if (Z_TYPE(opline->op2.u.constant) == IS_UNICODE) { |
|---|
| 1203 | XCACHE_U_CHECK_OP(file, op2) |
|---|
| 1204 | else XCACHE_U_CHECK_OP(dir, op2) |
|---|
| 1205 | } |
|---|
| 1206 | #endif |
|---|
| 1207 | } |
|---|
| 1208 | if (oplineinfo) { |
|---|
| 1209 | xc_vector_add(int, &vector_int, oplineno); |
|---|
| 1210 | xc_vector_add(int, &vector_int, oplineinfo); |
|---|
| 1211 | } |
|---|
| 1212 | } |
|---|
| 1213 | |
|---|
| 1214 | op_array_info->oplineinfo_cnt = vector_int.cnt; |
|---|
| 1215 | op_array_info->oplineinfos = xc_vector_detach(int, &vector_int); |
|---|
| 1216 | xc_vector_free(int, &vector_int); |
|---|
| 1217 | } |
|---|
| 1218 | /* }}} */ |
|---|
| 1219 | void xc_fix_op_array_info(const xc_entry_data_php_t *php, zend_op_array *op_array, int copy, const xc_op_array_info_t *op_array_info TSRMLS_DC) /* {{{ */ |
|---|
| 1220 | { |
|---|
| 1221 | int i; |
|---|
| 1222 | if (!op_array_info->oplineinfo_cnt) { |
|---|
| 1223 | return; |
|---|
| 1224 | } |
|---|
| 1225 | |
|---|
| 1226 | for (i = 0; i < op_array_info->oplineinfo_cnt; i += 2) { |
|---|
| 1227 | int oplineno = op_array_info->oplineinfos[i]; |
|---|
| 1228 | int oplineinfo = op_array_info->oplineinfos[i + 1]; |
|---|
| 1229 | zend_op *opline = &op_array->opcodes[oplineno]; |
|---|
| 1230 | if ((oplineinfo & xcache_op1_is_file)) { |
|---|
| 1231 | assert(opline->op1.op_type == IS_CONST); |
|---|
| 1232 | if (copy) { |
|---|
| 1233 | efree(Z_STRVAL(opline->op1.u.constant)); |
|---|
| 1234 | } |
|---|
| 1235 | if (Z_TYPE(opline->op1.u.constant) == IS_STRING) { |
|---|
| 1236 | assert(php->filepath); |
|---|
| 1237 | ZVAL_STRINGL(&opline->op1.u.constant, php->filepath, php->filepath_len, copy); |
|---|
| 1238 | } |
|---|
| 1239 | #ifdef IS_UNICODE |
|---|
| 1240 | else if (Z_TYPE(opline->op1.u.constant) == IS_UNICODE) { |
|---|
| 1241 | assert(php->ufilepath); |
|---|
| 1242 | ZVAL_UNICODEL(&opline->op1.u.constant, php->ufilepath, php->ufilepath_len, copy); |
|---|
| 1243 | } |
|---|
| 1244 | #endif |
|---|
| 1245 | else { |
|---|
| 1246 | assert(0); |
|---|
| 1247 | } |
|---|
| 1248 | } |
|---|
| 1249 | else if ((oplineinfo & xcache_op1_is_dir)) { |
|---|
| 1250 | assert(opline->op1.op_type == IS_CONST); |
|---|
| 1251 | if (copy) { |
|---|
| 1252 | efree(Z_STRVAL(opline->op1.u.constant)); |
|---|
| 1253 | } |
|---|
| 1254 | if (Z_TYPE(opline->op1.u.constant) == IS_STRING) { |
|---|
| 1255 | assert(php->dirpath); |
|---|
| 1256 | ZVAL_STRINGL(&opline->op1.u.constant, php->dirpath, php->dirpath_len, copy); |
|---|
| 1257 | } |
|---|
| 1258 | #ifdef IS_UNICODE |
|---|
| 1259 | else if (Z_TYPE(opline->op1.u.constant) == IS_UNICODE) { |
|---|
| 1260 | assert(!php->udirpath); |
|---|
| 1261 | ZVAL_UNICODEL(&opline->op1.u.constant, php->udirpath, php->udirpath_len, copy); |
|---|
| 1262 | } |
|---|
| 1263 | #endif |
|---|
| 1264 | else { |
|---|
| 1265 | assert(0); |
|---|
| 1266 | } |
|---|
| 1267 | } |
|---|
| 1268 | |
|---|
| 1269 | if ((oplineinfo & xcache_op2_is_file)) { |
|---|
| 1270 | assert(opline->op2.op_type == IS_CONST); |
|---|
| 1271 | if (copy) { |
|---|
| 1272 | efree(Z_STRVAL(opline->op2.u.constant)); |
|---|
| 1273 | } |
|---|
| 1274 | if (Z_TYPE(opline->op2.u.constant) == IS_STRING) { |
|---|
| 1275 | assert(php->filepath); |
|---|
| 1276 | ZVAL_STRINGL(&opline->op2.u.constant, php->filepath, php->filepath_len, copy); |
|---|
| 1277 | } |
|---|
| 1278 | #ifdef IS_UNICODE |
|---|
| 1279 | else if (Z_TYPE(opline->op2.u.constant) == IS_UNICODE) { |
|---|
| 1280 | assert(php->ufilepath); |
|---|
| 1281 | ZVAL_UNICODEL(&opline->op2.u.constant, php->ufilepath, php->ufilepath_len, copy); |
|---|
| 1282 | } |
|---|
| 1283 | #endif |
|---|
| 1284 | else { |
|---|
| 1285 | assert(0); |
|---|
| 1286 | } |
|---|
| 1287 | } |
|---|
| 1288 | else if ((oplineinfo & xcache_op2_is_dir)) { |
|---|
| 1289 | assert(opline->op2.op_type == IS_CONST); |
|---|
| 1290 | if (copy) { |
|---|
| 1291 | efree(Z_STRVAL(opline->op2.u.constant)); |
|---|
| 1292 | } |
|---|
| 1293 | if (Z_TYPE(opline->op2.u.constant) == IS_STRING) { |
|---|
| 1294 | assert(!php->dirpath); |
|---|
| 1295 | ZVAL_STRINGL(&opline->op2.u.constant, php->dirpath, php->dirpath_len, copy); |
|---|
| 1296 | } |
|---|
| 1297 | #ifdef IS_UNICODE |
|---|
| 1298 | else if (Z_TYPE(opline->op2.u.constant) == IS_UNICODE) { |
|---|
| 1299 | assert(!php->udirpath); |
|---|
| 1300 | ZVAL_UNICODEL(&opline->op2.u.constant, php->udirpath, php->udirpath_len, copy); |
|---|
| 1301 | } |
|---|
| 1302 | #endif |
|---|
| 1303 | else { |
|---|
| 1304 | assert(0); |
|---|
| 1305 | } |
|---|
| 1306 | } |
|---|
| 1307 | } |
|---|
| 1308 | } |
|---|
| 1309 | /* }}} */ |
|---|
| 1310 | static void xc_free_op_array_info(xc_op_array_info_t *op_array_info TSRMLS_DC) /* {{{ */ |
|---|
| 1311 | { |
|---|
| 1312 | if (op_array_info->oplineinfos) { |
|---|
| 1313 | efree(op_array_info->oplineinfos); |
|---|
| 1314 | } |
|---|
| 1315 | } |
|---|
| 1316 | /* }}} */ |
|---|
| 1317 | static void xc_free_php(xc_entry_data_php_t *php TSRMLS_DC) /* {{{ */ |
|---|
| 1318 | { |
|---|
| 1319 | int i; |
|---|
| 1320 | if (php->classinfos) { |
|---|
| 1321 | for (i = 0; i < php->classinfo_cnt; i ++) { |
|---|
| 1322 | xc_classinfo_t *classinfo = &php->classinfos[i]; |
|---|
| 1323 | int j; |
|---|
| 1324 | for (j = 0; j < classinfo->methodinfo_cnt; j ++) { |
|---|
| 1325 | xc_free_op_array_info(&classinfo->methodinfos[j] TSRMLS_CC); |
|---|
| 1326 | } |
|---|
| 1327 | |
|---|
| 1328 | if (classinfo->methodinfos) { |
|---|
| 1329 | efree(classinfo->methodinfos); |
|---|
| 1330 | } |
|---|
| 1331 | } |
|---|
| 1332 | } |
|---|
| 1333 | if (php->funcinfos) { |
|---|
| 1334 | for (i = 0; i < php->funcinfo_cnt; i ++) { |
|---|
| 1335 | xc_free_op_array_info(&php->funcinfos[i].op_array_info TSRMLS_CC); |
|---|
| 1336 | } |
|---|
| 1337 | } |
|---|
| 1338 | xc_free_op_array_info(&php->op_array_info TSRMLS_CC); |
|---|
| 1339 | |
|---|
| 1340 | #define X_FREE(var) do {\ |
|---|
| 1341 | if (php->var) { \ |
|---|
| 1342 | efree(php->var); \ |
|---|
| 1343 | } \ |
|---|
| 1344 | } while (0) |
|---|
| 1345 | |
|---|
| 1346 | X_FREE(dirpath); |
|---|
| 1347 | #ifdef IS_UNICODE |
|---|
| 1348 | X_FREE(ufilepath); |
|---|
| 1349 | X_FREE(udirpath); |
|---|
| 1350 | #endif |
|---|
| 1351 | |
|---|
| 1352 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 1353 | X_FREE(autoglobals); |
|---|
| 1354 | #endif |
|---|
| 1355 | X_FREE(classinfos); |
|---|
| 1356 | X_FREE(funcinfos); |
|---|
| 1357 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 1358 | X_FREE(constinfos); |
|---|
| 1359 | #endif |
|---|
| 1360 | #undef X_FREE |
|---|
| 1361 | } |
|---|
| 1362 | /* }}} */ |
|---|
| 1363 | static zend_op_array *xc_compile_php(xc_entry_data_php_t *php, zend_file_handle *h, int type TSRMLS_DC) /* {{{ */ |
|---|
| 1364 | { |
|---|
| 1365 | zend_op_array *op_array; |
|---|
| 1366 | int old_constinfo_cnt, old_funcinfo_cnt, old_classinfo_cnt; |
|---|
| 1367 | zend_bool catched = 0; |
|---|
| 1368 | xc_const_usage_t const_usage; |
|---|
| 1369 | |
|---|
| 1370 | /* {{{ compile */ |
|---|
| 1371 | TRACE("compiling %s", h->opened_path ? h->opened_path : h->filename); |
|---|
| 1372 | |
|---|
| 1373 | old_classinfo_cnt = zend_hash_num_elements(CG(class_table)); |
|---|
| 1374 | old_funcinfo_cnt = zend_hash_num_elements(CG(function_table)); |
|---|
| 1375 | old_constinfo_cnt = zend_hash_num_elements(EG(zend_constants)); |
|---|
| 1376 | |
|---|
| 1377 | php->op_array = NULL; |
|---|
| 1378 | XG(initial_compile_file_called) = 0; |
|---|
| 1379 | zend_try { |
|---|
| 1380 | op_array = old_compile_file(h, type TSRMLS_CC); |
|---|
| 1381 | } zend_catch { |
|---|
| 1382 | catched = 1; |
|---|
| 1383 | } zend_end_try(); |
|---|
| 1384 | |
|---|
| 1385 | if (catched) { |
|---|
| 1386 | goto err_bailout; |
|---|
| 1387 | } |
|---|
| 1388 | |
|---|
| 1389 | if (op_array == NULL) { |
|---|
| 1390 | goto err_op_array; |
|---|
| 1391 | } |
|---|
| 1392 | |
|---|
| 1393 | if (!XG(initial_compile_file_called)) { |
|---|
| 1394 | return op_array; |
|---|
| 1395 | } |
|---|
| 1396 | |
|---|
| 1397 | /* }}} */ |
|---|
| 1398 | /* {{{ prepare */ |
|---|
| 1399 | zend_restore_compiled_filename(h->opened_path ? h->opened_path : h->filename TSRMLS_CC); |
|---|
| 1400 | php->op_array = op_array; |
|---|
| 1401 | |
|---|
| 1402 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 1403 | php->constinfo_cnt = zend_hash_num_elements(EG(zend_constants)) - old_constinfo_cnt; |
|---|
| 1404 | #endif |
|---|
| 1405 | php->funcinfo_cnt = zend_hash_num_elements(CG(function_table)) - old_funcinfo_cnt; |
|---|
| 1406 | php->classinfo_cnt = zend_hash_num_elements(CG(class_table)) - old_classinfo_cnt; |
|---|
| 1407 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 1408 | /* {{{ count php->autoglobal_cnt */ { |
|---|
| 1409 | Bucket *b; |
|---|
| 1410 | |
|---|
| 1411 | php->autoglobal_cnt = 0; |
|---|
| 1412 | for (b = CG(auto_globals)->pListHead; b != NULL; b = b->pListNext) { |
|---|
| 1413 | zend_auto_global *auto_global = (zend_auto_global *) b->pData; |
|---|
| 1414 | /* check if actived */ |
|---|
| 1415 | if (auto_global->auto_global_callback && !auto_global->armed) { |
|---|
| 1416 | php->autoglobal_cnt ++; |
|---|
| 1417 | } |
|---|
| 1418 | } |
|---|
| 1419 | } |
|---|
| 1420 | /* }}} */ |
|---|
| 1421 | #endif |
|---|
| 1422 | |
|---|
| 1423 | #define X_ALLOC_N(var, cnt) do { \ |
|---|
| 1424 | if (php->cnt) { \ |
|---|
| 1425 | ECALLOC_N(php->var, php->cnt); \ |
|---|
| 1426 | if (!php->var) { \ |
|---|
| 1427 | goto err_alloc; \ |
|---|
| 1428 | } \ |
|---|
| 1429 | } \ |
|---|
| 1430 | else { \ |
|---|
| 1431 | php->var = NULL; \ |
|---|
| 1432 | } \ |
|---|
| 1433 | } while (0) |
|---|
| 1434 | |
|---|
| 1435 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 1436 | X_ALLOC_N(constinfos, constinfo_cnt); |
|---|
| 1437 | #endif |
|---|
| 1438 | X_ALLOC_N(funcinfos, funcinfo_cnt); |
|---|
| 1439 | X_ALLOC_N(classinfos, classinfo_cnt); |
|---|
| 1440 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 1441 | X_ALLOC_N(autoglobals, autoglobal_cnt); |
|---|
| 1442 | #endif |
|---|
| 1443 | #undef X_ALLOC |
|---|
| 1444 | /* }}} */ |
|---|
| 1445 | |
|---|
| 1446 | /* {{{ file/dir path init */ |
|---|
| 1447 | memset(&const_usage, 0, sizeof(const_usage)); |
|---|
| 1448 | php->filepath = zend_get_compiled_filename(TSRMLS_C); |
|---|
| 1449 | php->filepath_len = strlen(php->filepath); |
|---|
| 1450 | php->dirpath = estrndup(php->filepath, php->filepath_len); |
|---|
| 1451 | php->dirpath_len = zend_dirname(php->dirpath, php->filepath_len); |
|---|
| 1452 | #ifdef IS_UNICODE |
|---|
| 1453 | zend_string_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &php->ufilepath, &php->ufilepath_len, php->filepath, php->filepath_len TSRMLS_CC); |
|---|
| 1454 | zend_string_to_unicode(ZEND_U_CONVERTER(UG(runtime_encoding_conv)), &php->udirpath, &php->udirpath_len, php->dirpath, php->dirpath_len TSRMLS_CC); |
|---|
| 1455 | #endif |
|---|
| 1456 | /* }}} */ |
|---|
| 1457 | /* {{{ shallow copy, pointers only */ { |
|---|
| 1458 | Bucket *b; |
|---|
| 1459 | unsigned int i; |
|---|
| 1460 | unsigned int j; |
|---|
| 1461 | |
|---|
| 1462 | #define COPY_H(vartype, var, cnt, name, datatype) do { \ |
|---|
| 1463 | for (i = 0, j = 0; b; i ++, b = b->pListNext) { \ |
|---|
| 1464 | vartype *data = &php->var[j]; \ |
|---|
| 1465 | \ |
|---|
| 1466 | if (i < old_##cnt) { \ |
|---|
| 1467 | continue; \ |
|---|
| 1468 | } \ |
|---|
| 1469 | j ++; \ |
|---|
| 1470 | \ |
|---|
| 1471 | assert(i < old_##cnt + php->cnt); \ |
|---|
| 1472 | assert(b->pData); \ |
|---|
| 1473 | memcpy(&data->name, b->pData, sizeof(datatype)); \ |
|---|
| 1474 | UNISW(NOTHING, data->type = b->key.type;) \ |
|---|
| 1475 | if (UNISW(1, b->key.type == IS_STRING)) { \ |
|---|
| 1476 | ZSTR_S(data->key) = BUCKET_KEY_S(b); \ |
|---|
| 1477 | } \ |
|---|
| 1478 | else { \ |
|---|
| 1479 | ZSTR_U(data->key) = BUCKET_KEY_U(b); \ |
|---|
| 1480 | } \ |
|---|
| 1481 | data->key_size = b->nKeyLength; \ |
|---|
| 1482 | data->h = b->h; \ |
|---|
| 1483 | } \ |
|---|
| 1484 | } while(0) |
|---|
| 1485 | |
|---|
| 1486 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 1487 | b = EG(zend_constants)->pListHead; COPY_H(xc_constinfo_t, constinfos, constinfo_cnt, constant, zend_constant); |
|---|
| 1488 | #endif |
|---|
| 1489 | b = CG(function_table)->pListHead; COPY_H(xc_funcinfo_t, funcinfos, funcinfo_cnt, func, zend_function); |
|---|
| 1490 | b = CG(class_table)->pListHead; COPY_H(xc_classinfo_t, classinfos, classinfo_cnt, cest, xc_cest_t); |
|---|
| 1491 | |
|---|
| 1492 | for (i = 0; i < php->classinfo_cnt; i ++) { |
|---|
| 1493 | xc_classinfo_t *classinfo = &php->classinfos[i]; |
|---|
| 1494 | zend_class_entry *ce = CestToCePtr(classinfo->cest); |
|---|
| 1495 | classinfo->methodinfo_cnt = ce->function_table.nTableSize; |
|---|
| 1496 | if (classinfo->methodinfo_cnt) { |
|---|
| 1497 | int j; |
|---|
| 1498 | |
|---|
| 1499 | ECALLOC_N(classinfo->methodinfos, classinfo->methodinfo_cnt); |
|---|
| 1500 | if (!classinfo->methodinfos) { |
|---|
| 1501 | goto err_alloc; |
|---|
| 1502 | } |
|---|
| 1503 | |
|---|
| 1504 | for (j = 0, b = ce->function_table.pListHead; b; j ++, b = b->pListNext) { |
|---|
| 1505 | xc_collect_op_array_info(php, &const_usage, &classinfo->methodinfos[j], (zend_op_array *) b->pData TSRMLS_CC); |
|---|
| 1506 | } |
|---|
| 1507 | } |
|---|
| 1508 | else { |
|---|
| 1509 | classinfo->methodinfos = NULL; |
|---|
| 1510 | } |
|---|
| 1511 | } |
|---|
| 1512 | |
|---|
| 1513 | for (i = 0; i < php->funcinfo_cnt; i ++) { |
|---|
| 1514 | xc_collect_op_array_info(php, &const_usage, &php->funcinfos[i].op_array_info, (zend_op_array *) &php->funcinfos[i].func TSRMLS_CC); |
|---|
| 1515 | } |
|---|
| 1516 | |
|---|
| 1517 | xc_collect_op_array_info(php, &const_usage, &php->op_array_info, php->op_array TSRMLS_CC); |
|---|
| 1518 | |
|---|
| 1519 | #undef COPY_H |
|---|
| 1520 | |
|---|
| 1521 | /* for ZE1, cest need to be fixed inside store */ |
|---|
| 1522 | |
|---|
| 1523 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 1524 | /* scan for acatived auto globals */ |
|---|
| 1525 | i = 0; |
|---|
| 1526 | for (b = CG(auto_globals)->pListHead; b != NULL; b = b->pListNext) { |
|---|
| 1527 | zend_auto_global *auto_global = (zend_auto_global *) b->pData; |
|---|
| 1528 | /* check if actived */ |
|---|
| 1529 | if (auto_global->auto_global_callback && !auto_global->armed) { |
|---|
| 1530 | xc_autoglobal_t *data = &php->autoglobals[i]; |
|---|
| 1531 | |
|---|
| 1532 | assert(i < php->autoglobal_cnt); |
|---|
| 1533 | i ++; |
|---|
| 1534 | UNISW(NOTHING, data->type = b->key.type;) |
|---|
| 1535 | if (UNISW(1, b->key.type == IS_STRING)) { |
|---|
| 1536 | ZSTR_S(data->key) = BUCKET_KEY_S(b); |
|---|
| 1537 | } |
|---|
| 1538 | else { |
|---|
| 1539 | ZSTR_U(data->key) = BUCKET_KEY_U(b); |
|---|
| 1540 | } |
|---|
| 1541 | data->key_len = b->nKeyLength - 1; |
|---|
| 1542 | data->h = b->h; |
|---|
| 1543 | } |
|---|
| 1544 | } |
|---|
| 1545 | #endif |
|---|
| 1546 | } |
|---|
| 1547 | /* }}} */ |
|---|
| 1548 | /* {{{ file/dir path free unused */ |
|---|
| 1549 | #define X_FREE_UNUSED(var) \ |
|---|
| 1550 | if (!const_usage.var##path_used) { \ |
|---|
| 1551 | efree(php->var##path); \ |
|---|
| 1552 | php->var##path = NULL; \ |
|---|
| 1553 | php->var##path_len = 0; \ |
|---|
| 1554 | } |
|---|
| 1555 | if (!const_usage.filepath_used) { |
|---|
| 1556 | php->filepath = NULL; |
|---|
| 1557 | php->filepath_len = 0; |
|---|
| 1558 | } |
|---|
| 1559 | X_FREE_UNUSED(dir) |
|---|
| 1560 | #ifdef IS_UNICODE |
|---|
| 1561 | X_FREE_UNUSED(ufile) |
|---|
| 1562 | X_FREE_UNUSED(udir) |
|---|
| 1563 | #endif |
|---|
| 1564 | #undef X_FREE_UNUSED |
|---|
| 1565 | /* }}} */ |
|---|
| 1566 | #ifdef XCACHE_ERROR_CACHING |
|---|
| 1567 | php->compilererrors = ((xc_sandbox_t *) XG(sandbox))->compilererrors; |
|---|
| 1568 | php->compilererror_cnt = ((xc_sandbox_t *) XG(sandbox))->compilererror_cnt; |
|---|
| 1569 | #endif |
|---|
| 1570 | #ifndef ZEND_COMPILE_DELAYED_BINDING |
|---|
| 1571 | /* {{{ find inherited classes that should be early-binding */ |
|---|
| 1572 | php->have_early_binding = 0; |
|---|
| 1573 | { |
|---|
| 1574 | int i; |
|---|
| 1575 | for (i = 0; i < php->classinfo_cnt; i ++) { |
|---|
| 1576 | php->classinfos[i].oplineno = -1; |
|---|
| 1577 | } |
|---|
| 1578 | } |
|---|
| 1579 | |
|---|
| 1580 | xc_undo_pass_two(php->op_array TSRMLS_CC); |
|---|
| 1581 | xc_foreach_early_binding_class(php->op_array, xc_cache_early_binding_class_cb, (void *) php TSRMLS_CC); |
|---|
| 1582 | xc_redo_pass_two(php->op_array TSRMLS_CC); |
|---|
| 1583 | /* }}} */ |
|---|
| 1584 | #endif |
|---|
| 1585 | |
|---|
| 1586 | return op_array; |
|---|
| 1587 | |
|---|
| 1588 | err_alloc: |
|---|
| 1589 | xc_free_php(php TSRMLS_CC); |
|---|
| 1590 | |
|---|
| 1591 | err_bailout: |
|---|
| 1592 | err_op_array: |
|---|
| 1593 | |
|---|
| 1594 | if (catched) { |
|---|
| 1595 | zend_bailout(); |
|---|
| 1596 | } |
|---|
| 1597 | |
|---|
| 1598 | return op_array; |
|---|
| 1599 | } |
|---|
| 1600 | /* }}} */ |
|---|
| 1601 | static zend_op_array *xc_compile_restore(xc_entry_t *stored_xce, zend_file_handle *h TSRMLS_DC) /* {{{ */ |
|---|
| 1602 | { |
|---|
| 1603 | zend_op_array *op_array; |
|---|
| 1604 | xc_entry_t xce; |
|---|
| 1605 | xc_entry_data_php_t php; |
|---|
| 1606 | zend_bool catched; |
|---|
| 1607 | |
|---|
| 1608 | CG(in_compilation) = 1; |
|---|
| 1609 | CG(compiled_filename) = stored_xce->name.str.val; |
|---|
| 1610 | CG(zend_lineno) = 0; |
|---|
| 1611 | TRACE("restoring %s", stored_xce->name.str.val); |
|---|
| 1612 | xc_processor_restore_xc_entry_t(&xce, stored_xce TSRMLS_CC); |
|---|
| 1613 | xc_processor_restore_xc_entry_data_php_t(&php, xce.data.php, xc_readonly_protection TSRMLS_CC); |
|---|
| 1614 | xce.data.php = &php; |
|---|
| 1615 | #ifdef SHOW_DPRINT |
|---|
| 1616 | xc_dprint(&xce, 0 TSRMLS_CC); |
|---|
| 1617 | #endif |
|---|
| 1618 | |
|---|
| 1619 | catched = 0; |
|---|
| 1620 | zend_try { |
|---|
| 1621 | op_array = xc_entry_install(&xce, h TSRMLS_CC); |
|---|
| 1622 | } zend_catch { |
|---|
| 1623 | catched = 1; |
|---|
| 1624 | } zend_end_try(); |
|---|
| 1625 | |
|---|
| 1626 | if (php.constinfos) { |
|---|
| 1627 | efree(php.constinfos); |
|---|
| 1628 | } |
|---|
| 1629 | if (php.funcinfos) { |
|---|
| 1630 | efree(php.funcinfos); |
|---|
| 1631 | } |
|---|
| 1632 | if (php.classinfos) { |
|---|
| 1633 | efree(php.classinfos); |
|---|
| 1634 | } |
|---|
| 1635 | |
|---|
| 1636 | if (catched) { |
|---|
| 1637 | zend_bailout(); |
|---|
| 1638 | } |
|---|
| 1639 | CG(in_compilation) = 0; |
|---|
| 1640 | CG(compiled_filename) = NULL; |
|---|
| 1641 | TRACE("restored %s", stored_xce->name.str.val); |
|---|
| 1642 | return op_array; |
|---|
| 1643 | } |
|---|
| 1644 | /* }}} */ |
|---|
| 1645 | static zend_op_array *xc_check_initial_compile_file(zend_file_handle *h, int type TSRMLS_DC) /* {{{ */ |
|---|
| 1646 | { |
|---|
| 1647 | XG(initial_compile_file_called) = 1; |
|---|
| 1648 | return origin_compile_file(h, type TSRMLS_CC); |
|---|
| 1649 | } |
|---|
| 1650 | /* }}} */ |
|---|
| 1651 | static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) /* {{{ */ |
|---|
| 1652 | { |
|---|
| 1653 | zend_op_array *op_array; |
|---|
| 1654 | xc_entry_t xce, *stored_xce; |
|---|
| 1655 | xc_entry_data_php_t php, *stored_php; |
|---|
| 1656 | xc_cache_t *cache; |
|---|
| 1657 | zend_bool gaveup = 0; |
|---|
| 1658 | zend_bool catched = 0; |
|---|
| 1659 | zend_bool newlycompiled; |
|---|
| 1660 | char *filename; |
|---|
| 1661 | char opened_path_buffer[MAXPATHLEN]; |
|---|
| 1662 | xc_sandbox_t sandbox; |
|---|
| 1663 | |
|---|
| 1664 | assert(xc_initized); |
|---|
| 1665 | |
|---|
| 1666 | TRACE("type = %d\n", h->type); |
|---|
| 1667 | if (!XG(cacher)) { |
|---|
| 1668 | op_array = old_compile_file(h, type TSRMLS_CC); |
|---|
| 1669 | return op_array; |
|---|
| 1670 | } |
|---|
| 1671 | |
|---|
| 1672 | /* {{{ entry_init_key */ |
|---|
| 1673 | filename = h->opened_path ? h->opened_path : h->filename; |
|---|
| 1674 | xce.data.php = &php; |
|---|
| 1675 | if (xc_entry_init_key_php(&xce, filename, opened_path_buffer TSRMLS_CC) != SUCCESS) { |
|---|
| 1676 | TRACE("failed to init key for %s", filename); |
|---|
| 1677 | return old_compile_file(h, type TSRMLS_CC); |
|---|
| 1678 | } |
|---|
| 1679 | cache = xce.cache; |
|---|
| 1680 | /* }}} */ |
|---|
| 1681 | |
|---|
| 1682 | /* stale clogs precheck */ |
|---|
| 1683 | if (cache->compiling) { |
|---|
| 1684 | cache->clogs ++; |
|---|
| 1685 | return old_compile_file(h, type TSRMLS_CC); |
|---|
| 1686 | } |
|---|
| 1687 | /* {{{ entry_lookup/hit/md5_init/php_lookup */ |
|---|
| 1688 | stored_xce = NULL; |
|---|
| 1689 | stored_php = NULL; |
|---|
| 1690 | ENTER_LOCK_EX(cache) { |
|---|
| 1691 | stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC); |
|---|
| 1692 | if (stored_xce) { |
|---|
| 1693 | xc_cache_hit_dmz(cache TSRMLS_CC); |
|---|
| 1694 | |
|---|
| 1695 | TRACE("hit %s, holding", stored_xce->name.str.val); |
|---|
| 1696 | xc_entry_hold_php_dmz(stored_xce TSRMLS_CC); |
|---|
| 1697 | } |
|---|
| 1698 | else { |
|---|
| 1699 | cache->misses ++; |
|---|
| 1700 | TRACE("miss %s", xce.name.str.val); |
|---|
| 1701 | |
|---|
| 1702 | if (xc_entry_init_key_php_md5(&php, &xce TSRMLS_CC) != SUCCESS) { |
|---|
| 1703 | gaveup = 1; |
|---|
| 1704 | break; |
|---|
| 1705 | } |
|---|
| 1706 | |
|---|
| 1707 | stored_php = xc_php_find_dmz(&php TSRMLS_CC); |
|---|
| 1708 | |
|---|
| 1709 | /* miss but compiling */ |
|---|
| 1710 | if (!stored_php) { |
|---|
| 1711 | if (cache->compiling) { |
|---|
| 1712 | TRACE("%s", "miss but compiling"); |
|---|
| 1713 | cache->clogs ++; |
|---|
| 1714 | gaveup = 1; |
|---|
| 1715 | break; |
|---|
| 1716 | } |
|---|
| 1717 | TRACE("%s", "php_lookup miss"); |
|---|
| 1718 | } |
|---|
| 1719 | else { |
|---|
| 1720 | TRACE("%s", "php_lookup hit"); |
|---|
| 1721 | } |
|---|
| 1722 | |
|---|
| 1723 | cache->compiling = XG(request_time); |
|---|
| 1724 | } |
|---|
| 1725 | } LEAVE_LOCK_EX(cache); |
|---|
| 1726 | |
|---|
| 1727 | if (catched) { |
|---|
| 1728 | cache->compiling = 0; |
|---|
| 1729 | zend_bailout(); |
|---|
| 1730 | } |
|---|
| 1731 | |
|---|
| 1732 | /* hit */ |
|---|
| 1733 | if (stored_xce) { |
|---|
| 1734 | return xc_compile_restore(stored_xce, h TSRMLS_CC); |
|---|
| 1735 | } |
|---|
| 1736 | |
|---|
| 1737 | /* gaveup */ |
|---|
| 1738 | if (gaveup) { |
|---|
| 1739 | return old_compile_file(h, type TSRMLS_CC); |
|---|
| 1740 | } |
|---|
| 1741 | /* }}} */ |
|---|
| 1742 | op_array = NULL; |
|---|
| 1743 | /* {{{ compile */ |
|---|
| 1744 | if (stored_php) { |
|---|
| 1745 | newlycompiled = 0; |
|---|
| 1746 | xce.data.php = stored_php; |
|---|
| 1747 | } |
|---|
| 1748 | else { |
|---|
| 1749 | newlycompiled = 1; |
|---|
| 1750 | |
|---|
| 1751 | /* make compile inside sandbox */ |
|---|
| 1752 | xc_sandbox_init(&sandbox, filename TSRMLS_CC); |
|---|
| 1753 | |
|---|
| 1754 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 1755 | php.constinfos = NULL; |
|---|
| 1756 | #endif |
|---|
| 1757 | php.funcinfos = NULL; |
|---|
| 1758 | php.classinfos = NULL; |
|---|
| 1759 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 1760 | php.autoglobals = NULL; |
|---|
| 1761 | #endif |
|---|
| 1762 | memset(&php.op_array_info, 0, sizeof(php.op_array_info)); |
|---|
| 1763 | |
|---|
| 1764 | zend_try { |
|---|
| 1765 | op_array = xc_compile_php(&php, h, type TSRMLS_CC); |
|---|
| 1766 | } zend_catch { |
|---|
| 1767 | catched = 1; |
|---|
| 1768 | } zend_end_try(); |
|---|
| 1769 | |
|---|
| 1770 | if (catched || !op_array) { |
|---|
| 1771 | goto err_aftersandbox; |
|---|
| 1772 | } |
|---|
| 1773 | |
|---|
| 1774 | /* not cachable */ |
|---|
| 1775 | if (!php.op_array) { |
|---|
| 1776 | cache->compiling = 0; |
|---|
| 1777 | /* it's not cachable, but don't scare the users with high misses */ |
|---|
| 1778 | cache->misses --; |
|---|
| 1779 | xc_sandbox_free(&sandbox, XC_InstallNoBinding TSRMLS_CC); |
|---|
| 1780 | return op_array; |
|---|
| 1781 | } |
|---|
| 1782 | |
|---|
| 1783 | xce.data.php = &php; |
|---|
| 1784 | } |
|---|
| 1785 | /* }}} */ |
|---|
| 1786 | #ifdef HAVE_INODE |
|---|
| 1787 | /* {{{ path name fix |
|---|
| 1788 | * inode enabled entry hash/compare on name |
|---|
| 1789 | * do not update to its name to real pathname |
|---|
| 1790 | * WARNING: this code is required to be after compile |
|---|
| 1791 | */ |
|---|
| 1792 | if (xce.inode) { |
|---|
| 1793 | filename = h->opened_path ? h->opened_path : h->filename; |
|---|
| 1794 | if (xce.name.str.val != filename) { |
|---|
| 1795 | xce.name.str.val = filename; |
|---|
| 1796 | xce.name.str.len = strlen(filename); |
|---|
| 1797 | } |
|---|
| 1798 | } |
|---|
| 1799 | /* }}} */ |
|---|
| 1800 | #endif |
|---|
| 1801 | #ifdef SHOW_DPRINT |
|---|
| 1802 | xc_dprint(&xce, 0 TSRMLS_CC); |
|---|
| 1803 | #endif |
|---|
| 1804 | stored_xce = NULL; |
|---|
| 1805 | ENTER_LOCK_EX(cache) { /* {{{ php_store/entry_store */ |
|---|
| 1806 | /* php_store */ |
|---|
| 1807 | if (newlycompiled) { |
|---|
| 1808 | stored_php = xc_php_store_dmz(&php TSRMLS_CC); |
|---|
| 1809 | if (!stored_php) { |
|---|
| 1810 | /* error */ |
|---|
| 1811 | break; |
|---|
| 1812 | } |
|---|
| 1813 | } |
|---|
| 1814 | /* entry_store */ |
|---|
| 1815 | xc_php_addref_dmz(stored_php); |
|---|
| 1816 | stored_xce = xc_entry_store_dmz(&xce TSRMLS_CC); |
|---|
| 1817 | if (stored_xce) { |
|---|
| 1818 | stored_xce->data.php = stored_php; |
|---|
| 1819 | } |
|---|
| 1820 | else { |
|---|
| 1821 | /* error */ |
|---|
| 1822 | xc_php_release_dmz(stored_php); |
|---|
| 1823 | } |
|---|
| 1824 | } LEAVE_LOCK_EX(cache); |
|---|
| 1825 | /* }}} */ |
|---|
| 1826 | TRACE("%s", stored_xce ? "stored" : "store failed"); |
|---|
| 1827 | |
|---|
| 1828 | cache->compiling = 0; |
|---|
| 1829 | if (catched) { |
|---|
| 1830 | goto err_aftersandbox; |
|---|
| 1831 | } |
|---|
| 1832 | |
|---|
| 1833 | if (newlycompiled) { |
|---|
| 1834 | xc_free_php(&php TSRMLS_CC); |
|---|
| 1835 | } |
|---|
| 1836 | |
|---|
| 1837 | if (stored_xce) { |
|---|
| 1838 | if (op_array) { |
|---|
| 1839 | #ifdef ZEND_ENGINE_2 |
|---|
| 1840 | destroy_op_array(op_array TSRMLS_CC); |
|---|
| 1841 | #else |
|---|
| 1842 | destroy_op_array(op_array); |
|---|
| 1843 | #endif |
|---|
| 1844 | efree(op_array); |
|---|
| 1845 | h = NULL; |
|---|
| 1846 | } |
|---|
| 1847 | if (newlycompiled) { |
|---|
| 1848 | xc_sandbox_free(&sandbox, XC_NoInstall TSRMLS_CC); |
|---|
| 1849 | } |
|---|
| 1850 | return xc_compile_restore(stored_xce, h TSRMLS_CC); |
|---|
| 1851 | } |
|---|
| 1852 | else { |
|---|
| 1853 | if (newlycompiled) { |
|---|
| 1854 | zend_op_array *old_active_op_array = CG(active_op_array); |
|---|
| 1855 | /* install it */ |
|---|
| 1856 | CG(active_op_array) = op_array; |
|---|
| 1857 | xc_sandbox_free(&sandbox, XC_Install TSRMLS_CC); |
|---|
| 1858 | CG(active_op_array) = old_active_op_array; |
|---|
| 1859 | } |
|---|
| 1860 | } |
|---|
| 1861 | return op_array; |
|---|
| 1862 | |
|---|
| 1863 | err_aftersandbox: |
|---|
| 1864 | if (newlycompiled) { |
|---|
| 1865 | xc_free_php(&php TSRMLS_CC); |
|---|
| 1866 | xc_sandbox_free(&sandbox, XC_NoInstall TSRMLS_CC); |
|---|
| 1867 | } |
|---|
| 1868 | |
|---|
| 1869 | if (catched) { |
|---|
| 1870 | cache->compiling = 0; |
|---|
| 1871 | cache->errors ++; |
|---|
| 1872 | zend_bailout(); |
|---|
| 1873 | } |
|---|
| 1874 | return op_array; |
|---|
| 1875 | } |
|---|
| 1876 | /* }}} */ |
|---|
| 1877 | |
|---|
| 1878 | /* gdb helper functions, but N/A for coredump */ |
|---|
| 1879 | int xc_is_rw(const void *p) /* {{{ */ |
|---|
| 1880 | { |
|---|
| 1881 | xc_shm_t *shm; |
|---|
| 1882 | int i; |
|---|
| 1883 | |
|---|
| 1884 | if (xc_php_caches) { |
|---|
| 1885 | for (i = 0; i < xc_php_hcache.size; i ++) { |
|---|
| 1886 | shm = xc_php_caches[i]->shm; |
|---|
| 1887 | if (shm->handlers->is_readwrite(shm, p)) { |
|---|
| 1888 | return 1; |
|---|
| 1889 | } |
|---|
| 1890 | } |
|---|
| 1891 | } |
|---|
| 1892 | |
|---|
| 1893 | if (xc_var_caches) { |
|---|
| 1894 | for (i = 0; i < xc_var_hcache.size; i ++) { |
|---|
| 1895 | shm = xc_var_caches[i]->shm; |
|---|
| 1896 | if (shm->handlers->is_readwrite(shm, p)) { |
|---|
| 1897 | return 1; |
|---|
| 1898 | } |
|---|
| 1899 | } |
|---|
| 1900 | } |
|---|
| 1901 | return 0; |
|---|
| 1902 | } |
|---|
| 1903 | /* }}} */ |
|---|
| 1904 | int xc_is_ro(const void *p) /* {{{ */ |
|---|
| 1905 | { |
|---|
| 1906 | xc_shm_t *shm; |
|---|
| 1907 | int i; |
|---|
| 1908 | |
|---|
| 1909 | if (xc_php_caches) { |
|---|
| 1910 | for (i = 0; i < xc_php_hcache.size; i ++) { |
|---|
| 1911 | shm = xc_php_caches[i]->shm; |
|---|
| 1912 | if (shm->handlers->is_readonly(shm, p)) { |
|---|
| 1913 | return 1; |
|---|
| 1914 | } |
|---|
| 1915 | } |
|---|
| 1916 | } |
|---|
| 1917 | |
|---|
| 1918 | if (xc_var_caches) { |
|---|
| 1919 | for (i = 0; i < xc_var_hcache.size; i ++) { |
|---|
| 1920 | shm = xc_var_caches[i]->shm; |
|---|
| 1921 | if (shm->handlers->is_readonly(shm, p)) { |
|---|
| 1922 | return 1; |
|---|
| 1923 | } |
|---|
| 1924 | } |
|---|
| 1925 | } |
|---|
| 1926 | return 0; |
|---|
| 1927 | } |
|---|
| 1928 | /* }}} */ |
|---|
| 1929 | int xc_is_shm(const void *p) /* {{{ */ |
|---|
| 1930 | { |
|---|
| 1931 | return xc_is_ro(p) || xc_is_rw(p); |
|---|
| 1932 | } |
|---|
| 1933 | /* }}} */ |
|---|
| 1934 | |
|---|
| 1935 | void xc_gc_add_op_array(xc_gc_op_array_t *gc_op_array TSRMLS_DC) /* {{{ */ |
|---|
| 1936 | { |
|---|
| 1937 | zend_llist_add_element(&XG(gc_op_arrays), (void *) gc_op_array); |
|---|
| 1938 | } |
|---|
| 1939 | /* }}} */ |
|---|
| 1940 | static void xc_gc_op_array(void *pDest) /* {{{ */ |
|---|
| 1941 | { |
|---|
| 1942 | xc_gc_op_array_t *op_array = (xc_gc_op_array_t *) pDest; |
|---|
| 1943 | zend_uint i; |
|---|
| 1944 | #ifdef ZEND_ENGINE_2 |
|---|
| 1945 | if (op_array->arg_info) { |
|---|
| 1946 | for (i = 0; i < op_array->num_args; i++) { |
|---|
| 1947 | efree((char *) ZSTR_V(op_array->arg_info[i].name)); |
|---|
| 1948 | if (ZSTR_V(op_array->arg_info[i].class_name)) { |
|---|
| 1949 | efree((char *) ZSTR_V(op_array->arg_info[i].class_name)); |
|---|
| 1950 | } |
|---|
| 1951 | } |
|---|
| 1952 | efree(op_array->arg_info); |
|---|
| 1953 | } |
|---|
| 1954 | #endif |
|---|
| 1955 | if (op_array->opcodes) { |
|---|
| 1956 | efree(op_array->opcodes); |
|---|
| 1957 | } |
|---|
| 1958 | } |
|---|
| 1959 | /* }}} */ |
|---|
| 1960 | |
|---|
| 1961 | /* module helper function */ |
|---|
| 1962 | static int xc_init_constant(int module_number TSRMLS_DC) /* {{{ */ |
|---|
| 1963 | { |
|---|
| 1964 | typedef struct { |
|---|
| 1965 | const char *prefix; |
|---|
| 1966 | zend_uchar (*getsize)(); |
|---|
| 1967 | const char *(*get)(zend_uchar i); |
|---|
| 1968 | } xc_meminfo_t; |
|---|
| 1969 | xc_meminfo_t nameinfos[] = { |
|---|
| 1970 | { "", xc_get_op_type_count, xc_get_op_type }, |
|---|
| 1971 | { "", xc_get_data_type_count, xc_get_data_type }, |
|---|
| 1972 | { "", xc_get_opcode_count, xc_get_opcode }, |
|---|
| 1973 | { "OPSPEC_", xc_get_op_spec_count, xc_get_op_spec }, |
|---|
| 1974 | { NULL, NULL, NULL } |
|---|
| 1975 | }; |
|---|
| 1976 | xc_meminfo_t* p; |
|---|
| 1977 | zend_uchar i, count; |
|---|
| 1978 | char const_name[96]; |
|---|
| 1979 | int const_name_len; |
|---|
| 1980 | int undefdone = 0; |
|---|
| 1981 | |
|---|
| 1982 | for (p = nameinfos; p->getsize; p ++) { |
|---|
| 1983 | count = p->getsize(); |
|---|
| 1984 | for (i = 0; i < count; i ++) { |
|---|
| 1985 | const char *name = p->get(i); |
|---|
| 1986 | if (!name) continue; |
|---|
| 1987 | if (strcmp(name, "UNDEF") == 0) { |
|---|
| 1988 | if (undefdone) continue; |
|---|
| 1989 | undefdone = 1; |
|---|
| 1990 | } |
|---|
| 1991 | const_name_len = snprintf(const_name, sizeof(const_name), "XC_%s%s", p->prefix, name); |
|---|
| 1992 | zend_register_long_constant(const_name, const_name_len+1, i, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); |
|---|
| 1993 | } |
|---|
| 1994 | } |
|---|
| 1995 | |
|---|
| 1996 | zend_register_long_constant(ZEND_STRS("XC_SIZEOF_TEMP_VARIABLE"), sizeof(temp_variable), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); |
|---|
| 1997 | zend_register_long_constant(ZEND_STRS("XC_TYPE_PHP"), XC_TYPE_PHP, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); |
|---|
| 1998 | zend_register_long_constant(ZEND_STRS("XC_TYPE_VAR"), XC_TYPE_VAR, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); |
|---|
| 1999 | zend_register_stringl_constant(ZEND_STRS("XCACHE_VERSION"), ZEND_STRL(XCACHE_VERSION), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); |
|---|
| 2000 | zend_register_stringl_constant(ZEND_STRS("XCACHE_MODULES"), ZEND_STRL(XCACHE_MODULES), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); |
|---|
| 2001 | return 0; |
|---|
| 2002 | } |
|---|
| 2003 | /* }}} */ |
|---|
| 2004 | static xc_shm_t *xc_cache_destroy(xc_cache_t **caches, xc_hash_t *hcache) /* {{{ */ |
|---|
| 2005 | { |
|---|
| 2006 | int i; |
|---|
| 2007 | xc_cache_t *cache; |
|---|
| 2008 | xc_shm_t *shm; |
|---|
| 2009 | |
|---|
| 2010 | if (!caches) { |
|---|
| 2011 | return NULL; |
|---|
| 2012 | } |
|---|
| 2013 | shm = NULL; |
|---|
| 2014 | for (i = 0; i < hcache->size; i ++) { |
|---|
| 2015 | cache = caches[i]; |
|---|
| 2016 | if (cache) { |
|---|
| 2017 | if (cache->lck) { |
|---|
| 2018 | xc_lock_destroy(cache->lck); |
|---|
| 2019 | } |
|---|
| 2020 | /* do NOT free |
|---|
| 2021 | if (cache->entries) { |
|---|
| 2022 | cache->mem->handlers->free(cache->mem, cache->entries); |
|---|
| 2023 | } |
|---|
| 2024 | cache->mem->handlers->free(cache->mem, cache); |
|---|
| 2025 | */ |
|---|
| 2026 | shm = cache->shm; |
|---|
| 2027 | shm->handlers->memdestroy(cache->mem); |
|---|
| 2028 | } |
|---|
| 2029 | } |
|---|
| 2030 | free(caches); |
|---|
| 2031 | return shm; |
|---|
| 2032 | } |
|---|
| 2033 | /* }}} */ |
|---|
| 2034 | static xc_cache_t **xc_cache_init(xc_shm_t *shm, xc_hash_t *hcache, xc_hash_t *hentry, xc_hash_t *hphp, xc_shmsize_t shmsize) /* {{{ */ |
|---|
| 2035 | { |
|---|
| 2036 | xc_cache_t **caches = NULL, *cache; |
|---|
| 2037 | xc_mem_t *mem; |
|---|
| 2038 | time_t now = time(NULL); |
|---|
| 2039 | int i; |
|---|
| 2040 | xc_memsize_t memsize; |
|---|
| 2041 | |
|---|
| 2042 | memsize = shmsize / hcache->size; |
|---|
| 2043 | |
|---|
| 2044 | /* Don't let it break out of mem after ALIGNed |
|---|
| 2045 | * This is important for |
|---|
| 2046 | * Simply loop until it fit our need |
|---|
| 2047 | */ |
|---|
| 2048 | while (ALIGN(memsize) * hcache->size > shmsize && ALIGN(memsize) != memsize) { |
|---|
| 2049 | if (memsize < ALIGN(1)) { |
|---|
| 2050 | CHECK(NULL, "cache too small"); |
|---|
| 2051 | } |
|---|
| 2052 | memsize --; |
|---|
| 2053 | } |
|---|
| 2054 | |
|---|
| 2055 | CHECK(caches = calloc(hcache->size, sizeof(xc_cache_t *)), "caches OOM"); |
|---|
| 2056 | |
|---|
| 2057 | for (i = 0; i < hcache->size; i ++) { |
|---|
| 2058 | CHECK(mem = shm->handlers->meminit(shm, memsize), "Failed init memory allocator"); |
|---|
| 2059 | CHECK(cache = mem->handlers->calloc(mem, 1, sizeof(xc_cache_t)), "cache OOM"); |
|---|
| 2060 | CHECK(cache->entries = mem->handlers->calloc(mem, hentry->size, sizeof(xc_entry_t*)), "entries OOM"); |
|---|
| 2061 | if (hphp) { |
|---|
| 2062 | CHECK(cache->phps= mem->handlers->calloc(mem, hphp->size, sizeof(xc_entry_data_php_t*)), "phps OOM"); |
|---|
| 2063 | } |
|---|
| 2064 | CHECK(cache->lck = xc_lock_init(NULL), "can't create lock"); |
|---|
| 2065 | |
|---|
| 2066 | cache->hcache = hcache; |
|---|
| 2067 | cache->hentry = hentry; |
|---|
| 2068 | cache->hphp = hphp; |
|---|
| 2069 | cache->shm = shm; |
|---|
| 2070 | cache->mem = mem; |
|---|
| 2071 | cache->cacheid = i; |
|---|
| 2072 | cache->last_gc_deletes = now; |
|---|
| 2073 | cache->last_gc_expires = now; |
|---|
| 2074 | caches[i] = cache; |
|---|
| 2075 | } |
|---|
| 2076 | return caches; |
|---|
| 2077 | |
|---|
| 2078 | err: |
|---|
| 2079 | if (caches) { |
|---|
| 2080 | xc_cache_destroy(caches, hcache); |
|---|
| 2081 | } |
|---|
| 2082 | return NULL; |
|---|
| 2083 | } |
|---|
| 2084 | /* }}} */ |
|---|
| 2085 | static void xc_destroy() /* {{{ */ |
|---|
| 2086 | { |
|---|
| 2087 | xc_shm_t *shm = NULL; |
|---|
| 2088 | |
|---|
| 2089 | if (old_compile_file) { |
|---|
| 2090 | zend_compile_file = old_compile_file; |
|---|
| 2091 | old_compile_file = NULL; |
|---|
| 2092 | } |
|---|
| 2093 | |
|---|
| 2094 | if (origin_compile_file) { |
|---|
| 2095 | zend_compile_file = origin_compile_file; |
|---|
| 2096 | origin_compile_file = NULL; |
|---|
| 2097 | } |
|---|
| 2098 | |
|---|
| 2099 | if (xc_php_caches) { |
|---|
| 2100 | shm = xc_cache_destroy(xc_php_caches, &xc_php_hcache); |
|---|
| 2101 | xc_php_caches = NULL; |
|---|
| 2102 | } |
|---|
| 2103 | |
|---|
| 2104 | if (xc_var_caches) { |
|---|
| 2105 | shm = xc_cache_destroy(xc_var_caches, &xc_var_hcache); |
|---|
| 2106 | xc_var_caches = NULL; |
|---|
| 2107 | } |
|---|
| 2108 | |
|---|
| 2109 | if (shm) { |
|---|
| 2110 | xc_shm_destroy(shm); |
|---|
| 2111 | } |
|---|
| 2112 | |
|---|
| 2113 | xc_initized = 0; |
|---|
| 2114 | } |
|---|
| 2115 | /* }}} */ |
|---|
| 2116 | static int xc_init(int module_number TSRMLS_DC) /* {{{ */ |
|---|
| 2117 | { |
|---|
| 2118 | xc_shm_t *shm; |
|---|
| 2119 | xc_shmsize_t shmsize = ALIGN(xc_php_size) + ALIGN(xc_var_size); |
|---|
| 2120 | |
|---|
| 2121 | xc_php_caches = xc_var_caches = NULL; |
|---|
| 2122 | shm = NULL; |
|---|
| 2123 | |
|---|
| 2124 | if (shmsize < (size_t) xc_php_size || shmsize < (size_t) xc_var_size) { |
|---|
| 2125 | zend_error(E_ERROR, "XCache: neither xcache.size nor xcache.var_size can be negative"); |
|---|
| 2126 | goto err; |
|---|
| 2127 | } |
|---|
| 2128 | |
|---|
| 2129 | if (xc_php_size || xc_var_size) { |
|---|
| 2130 | CHECK(shm = xc_shm_init(xc_shm_scheme, shmsize, xc_readonly_protection, xc_mmap_path, NULL), "Cannot create shm"); |
|---|
| 2131 | if (!shm->handlers->can_readonly(shm)) { |
|---|
| 2132 | xc_readonly_protection = 0; |
|---|
| 2133 | } |
|---|
| 2134 | |
|---|
| 2135 | if (xc_php_size) { |
|---|
| 2136 | old_compile_file = zend_compile_file; |
|---|
| 2137 | zend_compile_file = xc_compile_file; |
|---|
| 2138 | |
|---|
| 2139 | CHECK(xc_php_caches = xc_cache_init(shm, &xc_php_hcache, &xc_php_hentry, &xc_php_hentry, xc_php_size), "failed init opcode cache"); |
|---|
| 2140 | } |
|---|
| 2141 | |
|---|
| 2142 | if (xc_var_size) { |
|---|
| 2143 | CHECK(xc_var_caches = xc_cache_init(shm, &xc_var_hcache, &xc_var_hentry, NULL, xc_var_size), "failed init variable cache"); |
|---|
| 2144 | } |
|---|
| 2145 | } |
|---|
| 2146 | return SUCCESS; |
|---|
| 2147 | |
|---|
| 2148 | err: |
|---|
| 2149 | if (xc_php_caches || xc_var_caches) { |
|---|
| 2150 | xc_destroy(); |
|---|
| 2151 | /* shm destroied in xc_destroy() */ |
|---|
| 2152 | } |
|---|
| 2153 | else if (shm) { |
|---|
| 2154 | xc_destroy(); |
|---|
| 2155 | xc_shm_destroy(shm); |
|---|
| 2156 | } |
|---|
| 2157 | return 0; |
|---|
| 2158 | } |
|---|
| 2159 | /* }}} */ |
|---|
| 2160 | static void xc_request_init(TSRMLS_D) /* {{{ */ |
|---|
| 2161 | { |
|---|
| 2162 | int i; |
|---|
| 2163 | |
|---|
| 2164 | if (!XG(internal_table_copied)) { |
|---|
| 2165 | zend_function tmp_func; |
|---|
| 2166 | xc_cest_t tmp_cest; |
|---|
| 2167 | |
|---|
| 2168 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 2169 | zend_hash_destroy(&XG(internal_constant_table)); |
|---|
| 2170 | #endif |
|---|
| 2171 | zend_hash_destroy(&XG(internal_function_table)); |
|---|
| 2172 | zend_hash_destroy(&XG(internal_class_table)); |
|---|
| 2173 | |
|---|
| 2174 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 2175 | zend_hash_init_ex(&XG(internal_constant_table), 20, NULL, (dtor_func_t) xc_zend_constant_dtor, 1, 0); |
|---|
| 2176 | #endif |
|---|
| 2177 | zend_hash_init_ex(&XG(internal_function_table), 100, NULL, NULL, 1, 0); |
|---|
| 2178 | zend_hash_init_ex(&XG(internal_class_table), 10, NULL, NULL, 1, 0); |
|---|
| 2179 | |
|---|
| 2180 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 2181 | xc_copy_internal_zend_constants(&XG(internal_constant_table), EG(zend_constants)); |
|---|
| 2182 | #endif |
|---|
| 2183 | zend_hash_copy(&XG(internal_function_table), CG(function_table), NULL, &tmp_func, sizeof(tmp_func)); |
|---|
| 2184 | zend_hash_copy(&XG(internal_class_table), CG(class_table), NULL, &tmp_cest, sizeof(tmp_cest)); |
|---|
| 2185 | |
|---|
| 2186 | XG(internal_table_copied) = 1; |
|---|
| 2187 | } |
|---|
| 2188 | if (xc_php_caches && !XG(php_holds)) { |
|---|
| 2189 | XG(php_holds) = calloc(xc_php_hcache.size, sizeof(xc_stack_t)); |
|---|
| 2190 | for (i = 0; i < xc_php_hcache.size; i ++) { |
|---|
| 2191 | xc_stack_init(&XG(php_holds[i])); |
|---|
| 2192 | } |
|---|
| 2193 | } |
|---|
| 2194 | |
|---|
| 2195 | if (xc_var_caches && !XG(var_holds)) { |
|---|
| 2196 | XG(var_holds) = calloc(xc_var_hcache.size, sizeof(xc_stack_t)); |
|---|
| 2197 | for (i = 0; i < xc_var_hcache.size; i ++) { |
|---|
| 2198 | xc_stack_init(&XG(var_holds[i])); |
|---|
| 2199 | } |
|---|
| 2200 | } |
|---|
| 2201 | |
|---|
| 2202 | #ifdef ZEND_ENGINE_2 |
|---|
| 2203 | zend_llist_init(&XG(gc_op_arrays), sizeof(xc_gc_op_array_t), xc_gc_op_array, 0); |
|---|
| 2204 | #endif |
|---|
| 2205 | |
|---|
| 2206 | #if PHP_API_VERSION <= 20041225 |
|---|
| 2207 | XG(request_time) = time(NULL); |
|---|
| 2208 | #else |
|---|
| 2209 | XG(request_time) = sapi_get_request_time(TSRMLS_C); |
|---|
| 2210 | #endif |
|---|
| 2211 | |
|---|
| 2212 | #ifdef HAVE_XCACHE_COVERAGER |
|---|
| 2213 | xc_coverager_request_init(TSRMLS_C); |
|---|
| 2214 | #endif |
|---|
| 2215 | } |
|---|
| 2216 | /* }}} */ |
|---|
| 2217 | static void xc_request_shutdown(TSRMLS_D) /* {{{ */ |
|---|
| 2218 | { |
|---|
| 2219 | xc_entry_unholds(TSRMLS_C); |
|---|
| 2220 | #ifdef ZEND_ENGINE_2 |
|---|
| 2221 | zend_llist_destroy(&XG(gc_op_arrays)); |
|---|
| 2222 | #endif |
|---|
| 2223 | xc_gc_expires_php(TSRMLS_C); |
|---|
| 2224 | xc_gc_expires_var(TSRMLS_C); |
|---|
| 2225 | xc_gc_deletes(TSRMLS_C); |
|---|
| 2226 | #ifdef HAVE_XCACHE_COVERAGER |
|---|
| 2227 | xc_coverager_request_shutdown(TSRMLS_C); |
|---|
| 2228 | #endif |
|---|
| 2229 | } |
|---|
| 2230 | /* }}} */ |
|---|
| 2231 | /* {{{ PHP_GINIT_FUNCTION(xcache) */ |
|---|
| 2232 | static |
|---|
| 2233 | #ifdef PHP_GINIT_FUNCTION |
|---|
| 2234 | PHP_GINIT_FUNCTION(xcache) |
|---|
| 2235 | #else |
|---|
| 2236 | void xc_init_globals(zend_xcache_globals* xcache_globals TSRMLS_DC) |
|---|
| 2237 | #endif |
|---|
| 2238 | { |
|---|
| 2239 | memset(xcache_globals, 0, sizeof(zend_xcache_globals)); |
|---|
| 2240 | |
|---|
| 2241 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 2242 | zend_hash_init_ex(&xcache_globals->internal_constant_table, 1, NULL, (dtor_func_t) xc_zend_constant_dtor, 1, 0); |
|---|
| 2243 | #endif |
|---|
| 2244 | zend_hash_init_ex(&xcache_globals->internal_function_table, 1, NULL, NULL, 1, 0); |
|---|
| 2245 | zend_hash_init_ex(&xcache_globals->internal_class_table, 1, NULL, NULL, 1, 0); |
|---|
| 2246 | } |
|---|
| 2247 | /* }}} */ |
|---|
| 2248 | /* {{{ PHP_GSHUTDOWN_FUNCTION(xcache) */ |
|---|
| 2249 | static |
|---|
| 2250 | #ifdef PHP_GSHUTDOWN_FUNCTION |
|---|
| 2251 | PHP_GSHUTDOWN_FUNCTION(xcache) |
|---|
| 2252 | #else |
|---|
| 2253 | void xc_shutdown_globals(zend_xcache_globals* xcache_globals TSRMLS_DC) |
|---|
| 2254 | #endif |
|---|
| 2255 | { |
|---|
| 2256 | int i; |
|---|
| 2257 | |
|---|
| 2258 | if (xcache_globals->php_holds != NULL) { |
|---|
| 2259 | for (i = 0; i < xc_php_hcache.size; i ++) { |
|---|
| 2260 | xc_stack_destroy(&xcache_globals->php_holds[i]); |
|---|
| 2261 | } |
|---|
| 2262 | free(xcache_globals->php_holds); |
|---|
| 2263 | xcache_globals->php_holds = NULL; |
|---|
| 2264 | } |
|---|
| 2265 | |
|---|
| 2266 | if (xcache_globals->var_holds != NULL) { |
|---|
| 2267 | for (i = 0; i < xc_var_hcache.size; i ++) { |
|---|
| 2268 | xc_stack_destroy(&xcache_globals->var_holds[i]); |
|---|
| 2269 | } |
|---|
| 2270 | free(xcache_globals->var_holds); |
|---|
| 2271 | xcache_globals->var_holds = NULL; |
|---|
| 2272 | } |
|---|
| 2273 | |
|---|
| 2274 | if (xcache_globals->internal_table_copied) { |
|---|
| 2275 | #ifdef HAVE_XCACHE_CONSTANT |
|---|
| 2276 | zend_hash_destroy(&xcache_globals->internal_constant_table); |
|---|
| 2277 | #endif |
|---|
| 2278 | zend_hash_destroy(&xcache_globals->internal_function_table); |
|---|
| 2279 | zend_hash_destroy(&xcache_globals->internal_class_table); |
|---|
| 2280 | } |
|---|
| 2281 | } |
|---|
| 2282 | /* }}} */ |
|---|
| 2283 | |
|---|
| 2284 | /* user functions */ |
|---|
| 2285 | static int xcache_admin_auth_check(TSRMLS_D) /* {{{ */ |
|---|
| 2286 | { |
|---|
| 2287 | zval **server = NULL; |
|---|
| 2288 | zval **user = NULL; |
|---|
| 2289 | zval **pass = NULL; |
|---|
| 2290 | char *admin_user = NULL; |
|---|
| 2291 | char *admin_pass = NULL; |
|---|
| 2292 | HashTable *ht; |
|---|
| 2293 | |
|---|
| 2294 | if (cfg_get_string("xcache.admin.user", &admin_user) == FAILURE || !admin_user[0]) { |
|---|
| 2295 | admin_user = NULL; |
|---|
| 2296 | } |
|---|
| 2297 | if (cfg_get_string("xcache.admin.pass", &admin_pass) == FAILURE || !admin_pass[0]) { |
|---|
| 2298 | admin_pass = NULL; |
|---|
| 2299 | } |
|---|
| 2300 | |
|---|
| 2301 | if (admin_user == NULL || admin_pass == NULL) { |
|---|
| 2302 | php_error_docref(XCACHE_WIKI_URL "/InstallAdministration" TSRMLS_CC, E_ERROR, |
|---|
| 2303 | "xcache.admin.user and/or xcache.admin.pass settings is not configured." |
|---|
| 2304 | " Make sure you've modified the correct php ini file for your php used in webserver."); |
|---|
| 2305 | zend_bailout(); |
|---|
| 2306 | } |
|---|
| 2307 | if (strlen(admin_pass) != 32) { |
|---|
| 2308 | php_error_docref(NULL TSRMLS_CC, E_ERROR, "xcache.admin.pass is %lu chars unexpectedly, it is supposed to be the password after md5() which should be 32 chars", (unsigned long) strlen(admin_pass)); |
|---|
| 2309 | zend_bailout(); |
|---|
| 2310 | } |
|---|
| 2311 | |
|---|
| 2312 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 2313 | zend_is_auto_global("_SERVER", sizeof("_SERVER") - 1 TSRMLS_CC); |
|---|
| 2314 | #endif |
|---|
| 2315 | if (zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void **) &server) != SUCCESS || Z_TYPE_PP(server) != IS_ARRAY) { |
|---|
| 2316 | php_error_docref(NULL TSRMLS_CC, E_ERROR, "_SERVER is corrupted"); |
|---|
| 2317 | zend_bailout(); |
|---|
| 2318 | } |
|---|
| 2319 | ht = HASH_OF((*server)); |
|---|
| 2320 | |
|---|
| 2321 | if (zend_hash_find(ht, "PHP_AUTH_USER", sizeof("PHP_AUTH_USER"), (void **) &user) == FAILURE) { |
|---|
| 2322 | user = NULL; |
|---|
| 2323 | } |
|---|
| 2324 | else if (Z_TYPE_PP(user) != IS_STRING) { |
|---|
| 2325 | user = NULL; |
|---|
| 2326 | } |
|---|
| 2327 | |
|---|
| 2328 | if (zend_hash_find(ht, "PHP_AUTH_PW", sizeof("PHP_AUTH_PW"), (void **) &pass) == FAILURE) { |
|---|
| 2329 | pass = NULL; |
|---|
| 2330 | } |
|---|
| 2331 | else if (Z_TYPE_PP(pass) != IS_STRING) { |
|---|
| 2332 | pass = NULL; |
|---|
| 2333 | } |
|---|
| 2334 | |
|---|
| 2335 | if (user != NULL && pass != NULL && strcmp(admin_user, Z_STRVAL_PP(user)) == 0) { |
|---|
| 2336 | PHP_MD5_CTX context; |
|---|
| 2337 | char md5str[33]; |
|---|
| 2338 | unsigned char digest[16]; |
|---|
| 2339 | |
|---|
| 2340 | PHP_MD5Init(&context); |
|---|
| 2341 | PHP_MD5Update(&context, (unsigned char *) Z_STRVAL_PP(pass), Z_STRLEN_PP(pass)); |
|---|
| 2342 | PHP_MD5Final(digest, &context); |
|---|
| 2343 | |
|---|
| 2344 | md5str[0] = '\0'; |
|---|
| 2345 | make_digest(md5str, digest); |
|---|
| 2346 | if (strcmp(admin_pass, md5str) == 0) { |
|---|
| 2347 | return 1; |
|---|
| 2348 | } |
|---|
| 2349 | } |
|---|
| 2350 | |
|---|
| 2351 | #define STR "HTTP/1.0 401 Unauthorized" |
|---|
| 2352 | sapi_add_header_ex(STR, sizeof(STR) - 1, 1, 1 TSRMLS_CC); |
|---|
| 2353 | #undef STR |
|---|
| 2354 | #define STR "WWW-authenticate: Basic Realm=\"XCache Administration\"" |
|---|
| 2355 | sapi_add_header_ex(STR, sizeof(STR) - 1, 1, 1 TSRMLS_CC); |
|---|
| 2356 | #undef STR |
|---|
| 2357 | #define STR "Content-type: text/html; charset=UTF-8" |
|---|
| 2358 | sapi_add_header_ex(STR, sizeof(STR) - 1, 1, 1 TSRMLS_CC); |
|---|
| 2359 | #undef STR |
|---|
| 2360 | ZEND_PUTS("<html>\n"); |
|---|
| 2361 | ZEND_PUTS("<head><title>XCache Authentication Failed</title></head>\n"); |
|---|
| 2362 | ZEND_PUTS("<body>\n"); |
|---|
| 2363 | ZEND_PUTS("<h1>XCache Authentication Failed</h1>\n"); |
|---|
| 2364 | ZEND_PUTS("<p>You're not authorized to access this page due to wrong username and/or password you typed.<br />The following check points is suggested:</p>\n"); |
|---|
| 2365 | ZEND_PUTS("<ul>\n"); |
|---|
| 2366 | ZEND_PUTS("<li>Be aware that `Username' and `Password' is case sense. Check capslock status led on your keyboard, and punch left/right Shift keys once for each</li>\n"); |
|---|
| 2367 | ZEND_PUTS("<li>Make sure the md5 password is generated correctly. You may use <a href=\"mkpassword.php\">mkpassword.php</a></li>\n"); |
|---|
| 2368 | ZEND_PUTS("<li>Reload browser cache by pressing F5 and/or Ctrl+F5, or simply clear browser cache after you've updated username/password in php ini.</li>\n"); |
|---|
| 2369 | ZEND_PUTS("</ul>\n"); |
|---|
| 2370 | ZEND_PUTS("Check <a href=\"" XCACHE_WIKI_URL "/InstallAdministration\">XCache wiki page</a> for more information.\n"); |
|---|
| 2371 | ZEND_PUTS("</body>\n"); |
|---|
| 2372 | ZEND_PUTS("</html>\n"); |
|---|
| 2373 | |
|---|
| 2374 | zend_bailout(); |
|---|
| 2375 | return 0; |
|---|
| 2376 | } |
|---|
| 2377 | /* }}} */ |
|---|
| 2378 | /* {{{ xcache_admin_operate */ |
|---|
| 2379 | typedef enum { XC_OP_COUNT, XC_OP_INFO, XC_OP_LIST, XC_OP_CLEAR } xcache_op_type; |
|---|
| 2380 | static void xcache_admin_operate(xcache_op_type optype, INTERNAL_FUNCTION_PARAMETERS) |
|---|
| 2381 | { |
|---|
| 2382 | long type; |
|---|
| 2383 | int size; |
|---|
| 2384 | xc_cache_t **caches, *cache; |
|---|
| 2385 | long id = 0; |
|---|
| 2386 | |
|---|
| 2387 | xcache_admin_auth_check(TSRMLS_C); |
|---|
| 2388 | |
|---|
| 2389 | if (!xc_initized) { |
|---|
| 2390 | RETURN_NULL(); |
|---|
| 2391 | } |
|---|
| 2392 | |
|---|
| 2393 | if (optype == XC_OP_COUNT) { |
|---|
| 2394 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &type) == FAILURE) { |
|---|
| 2395 | return; |
|---|
| 2396 | } |
|---|
| 2397 | } |
|---|
| 2398 | else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &type, &id) == FAILURE) { |
|---|
| 2399 | return; |
|---|
| 2400 | } |
|---|
| 2401 | |
|---|
| 2402 | switch (type) { |
|---|
| 2403 | case XC_TYPE_PHP: |
|---|
| 2404 | size = xc_php_hcache.size; |
|---|
| 2405 | caches = xc_php_caches; |
|---|
| 2406 | break; |
|---|
| 2407 | |
|---|
| 2408 | case XC_TYPE_VAR: |
|---|
| 2409 | size = xc_var_hcache.size; |
|---|
| 2410 | caches = xc_var_caches; |
|---|
| 2411 | break; |
|---|
| 2412 | |
|---|
| 2413 | default: |
|---|
| 2414 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown type %ld", type); |
|---|
| 2415 | RETURN_FALSE; |
|---|
| 2416 | } |
|---|
| 2417 | |
|---|
| 2418 | switch (optype) { |
|---|
| 2419 | case XC_OP_COUNT: |
|---|
| 2420 | RETURN_LONG(size) |
|---|
| 2421 | break; |
|---|
| 2422 | |
|---|
| 2423 | case XC_OP_INFO: |
|---|
| 2424 | case XC_OP_LIST: |
|---|
| 2425 | if (id < 0 || id >= size) { |
|---|
| 2426 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cache not exists"); |
|---|
| 2427 | RETURN_FALSE; |
|---|
| 2428 | } |
|---|
| 2429 | |
|---|
| 2430 | array_init(return_value); |
|---|
| 2431 | |
|---|
| 2432 | cache = caches[id]; |
|---|
| 2433 | ENTER_LOCK(cache) { |
|---|
| 2434 | if (optype == XC_OP_INFO) { |
|---|
| 2435 | xc_fillinfo_dmz(type, cache, return_value TSRMLS_CC); |
|---|
| 2436 | } |
|---|
| 2437 | else { |
|---|
| 2438 | xc_filllist_dmz(cache, return_value TSRMLS_CC); |
|---|
| 2439 | } |
|---|
| 2440 | } LEAVE_LOCK(cache); |
|---|
| 2441 | break; |
|---|
| 2442 | case XC_OP_CLEAR: |
|---|
| 2443 | { |
|---|
| 2444 | xc_entry_t *e, *next; |
|---|
| 2445 | int i, c; |
|---|
| 2446 | |
|---|
| 2447 | if (id < 0 || id >= size) { |
|---|
| 2448 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cache not exists"); |
|---|
| 2449 | RETURN_FALSE; |
|---|
| 2450 | } |
|---|
| 2451 | |
|---|
| 2452 | cache = caches[id]; |
|---|
| 2453 | ENTER_LOCK(cache) { |
|---|
| 2454 | for (i = 0, c = cache->hentry->size; i < c; i ++) { |
|---|
| 2455 | for (e = cache->entries[i]; e; e = next) { |
|---|
| 2456 | next = e->next; |
|---|
| 2457 | xc_entry_remove_dmz(e TSRMLS_CC); |
|---|
| 2458 | } |
|---|
| 2459 | cache->entries[i] = NULL; |
|---|
| 2460 | } |
|---|
| 2461 | } LEAVE_LOCK(cache); |
|---|
| 2462 | xc_gc_deletes(TSRMLS_C); |
|---|
| 2463 | } |
|---|
| 2464 | break; |
|---|
| 2465 | |
|---|
| 2466 | default: |
|---|
| 2467 | assert(0); |
|---|
| 2468 | } |
|---|
| 2469 | } |
|---|
| 2470 | /* }}} */ |
|---|
| 2471 | /* {{{ proto int xcache_count(int type) |
|---|
| 2472 | Return count of cache on specified cache type */ |
|---|
| 2473 | PHP_FUNCTION(xcache_count) |
|---|
| 2474 | { |
|---|
| 2475 | xcache_admin_operate(XC_OP_COUNT, INTERNAL_FUNCTION_PARAM_PASSTHRU); |
|---|
| 2476 | } |
|---|
| 2477 | /* }}} */ |
|---|
| 2478 | /* {{{ proto array xcache_info(int type, int id) |
|---|
| 2479 | Get cache info by id on specified cache type */ |
|---|
| 2480 | PHP_FUNCTION(xcache_info) |
|---|
| 2481 | { |
|---|
| 2482 | xcache_admin_operate(XC_OP_INFO, INTERNAL_FUNCTION_PARAM_PASSTHRU); |
|---|
| 2483 | } |
|---|
| 2484 | /* }}} */ |
|---|
| 2485 | /* {{{ proto array xcache_list(int type, int id) |
|---|
| 2486 | Get cache entries list by id on specified cache type */ |
|---|
| 2487 | PHP_FUNCTION(xcache_list) |
|---|
| 2488 | { |
|---|
| 2489 | xcache_admin_operate(XC_OP_LIST, INTERNAL_FUNCTION_PARAM_PASSTHRU); |
|---|
| 2490 | } |
|---|
| 2491 | /* }}} */ |
|---|
| 2492 | /* {{{ proto array xcache_clear_cache(int type, int id) |
|---|
| 2493 | Clear cache by id on specified cache type */ |
|---|
| 2494 | PHP_FUNCTION(xcache_clear_cache) |
|---|
| 2495 | { |
|---|
| 2496 | xcache_admin_operate(XC_OP_CLEAR, INTERNAL_FUNCTION_PARAM_PASSTHRU); |
|---|
| 2497 | } |
|---|
| 2498 | /* }}} */ |
|---|
| 2499 | |
|---|
| 2500 | #define VAR_DISABLED_WARNING() do { \ |
|---|
| 2501 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "xcache.var_size is either 0 or too small to enable var data caching"); \ |
|---|
| 2502 | } while (0) |
|---|
| 2503 | |
|---|
| 2504 | static int xc_entry_init_key_var(xc_entry_t *xce, zval *name TSRMLS_DC) /* {{{ */ |
|---|
| 2505 | { |
|---|
| 2506 | xc_hash_value_t hv; |
|---|
| 2507 | int cacheid; |
|---|
| 2508 | |
|---|
| 2509 | switch (Z_TYPE_P(name)) { |
|---|
| 2510 | #ifdef IS_UNICODE |
|---|
| 2511 | case IS_UNICODE: |
|---|
| 2512 | #endif |
|---|
| 2513 | case IS_STRING: |
|---|
| 2514 | break; |
|---|
| 2515 | default: |
|---|
| 2516 | #ifdef IS_UNICODE |
|---|
| 2517 | convert_to_unicode(name); |
|---|
| 2518 | #else |
|---|
| 2519 | convert_to_string(name); |
|---|
| 2520 | #endif |
|---|
| 2521 | } |
|---|
| 2522 | #ifdef IS_UNICODE |
|---|
| 2523 | xce->name_type = name->type; |
|---|
| 2524 | #endif |
|---|
| 2525 | xce->name = name->value; |
|---|
| 2526 | |
|---|
| 2527 | hv = xc_entry_hash_var(xce TSRMLS_CC); |
|---|
| 2528 | |
|---|
| 2529 | cacheid = (hv & xc_var_hcache.mask); |
|---|
| 2530 | xce->cache = xc_var_caches[cacheid]; |
|---|
| 2531 | hv >>= xc_var_hcache.bits; |
|---|
| 2532 | xce->hvalue = (hv & xc_var_hentry.mask); |
|---|
| 2533 | |
|---|
| 2534 | xce->type = XC_TYPE_VAR; |
|---|
| 2535 | return SUCCESS; |
|---|
| 2536 | } |
|---|
| 2537 | /* }}} */ |
|---|
| 2538 | /* {{{ proto mixed xcache_get(string name) |
|---|
| 2539 | Get cached data by specified name */ |
|---|
| 2540 | PHP_FUNCTION(xcache_get) |
|---|
| 2541 | { |
|---|
| 2542 | xc_entry_t xce, *stored_xce; |
|---|
| 2543 | xc_entry_data_var_t var; |
|---|
| 2544 | zval *name; |
|---|
| 2545 | int found = 0; |
|---|
| 2546 | |
|---|
| 2547 | if (!xc_var_caches) { |
|---|
| 2548 | VAR_DISABLED_WARNING(); |
|---|
| 2549 | RETURN_NULL(); |
|---|
| 2550 | } |
|---|
| 2551 | |
|---|
| 2552 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &name) == FAILURE) { |
|---|
| 2553 | return; |
|---|
| 2554 | } |
|---|
| 2555 | xce.data.var = &var; |
|---|
| 2556 | xc_entry_init_key_var(&xce, name TSRMLS_CC); |
|---|
| 2557 | |
|---|
| 2558 | ENTER_LOCK(xce.cache) { |
|---|
| 2559 | stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC); |
|---|
| 2560 | if (stored_xce) { |
|---|
| 2561 | if (!VAR_ENTRY_EXPIRED(stored_xce)) { |
|---|
| 2562 | found = 1; |
|---|
| 2563 | xc_processor_restore_zval(return_value, stored_xce->data.var->value, stored_xce->data.var->have_references TSRMLS_CC); |
|---|
| 2564 | /* return */ |
|---|
| 2565 | break; |
|---|
| 2566 | } |
|---|
| 2567 | else { |
|---|
| 2568 | xc_entry_remove_dmz(stored_xce TSRMLS_CC); |
|---|
| 2569 | } |
|---|
| 2570 | } |
|---|
| 2571 | |
|---|
| 2572 | RETVAL_NULL(); |
|---|
| 2573 | } LEAVE_LOCK(xce.cache); |
|---|
| 2574 | if (found) { |
|---|
| 2575 | xc_cache_hit_dmz(xce.cache TSRMLS_CC); |
|---|
| 2576 | } |
|---|
| 2577 | else { |
|---|
| 2578 | xce.cache->misses ++; |
|---|
| 2579 | } |
|---|
| 2580 | } |
|---|
| 2581 | /* }}} */ |
|---|
| 2582 | /* {{{ proto bool xcache_set(string name, mixed value [, int ttl]) |
|---|
| 2583 | Store data to cache by specified name */ |
|---|
| 2584 | PHP_FUNCTION(xcache_set) |
|---|
| 2585 | { |
|---|
| 2586 | xc_entry_t xce, *stored_xce; |
|---|
| 2587 | xc_entry_data_var_t var; |
|---|
| 2588 | zval *name; |
|---|
| 2589 | zval *value; |
|---|
| 2590 | |
|---|
| 2591 | if (!xc_var_caches) { |
|---|
| 2592 | VAR_DISABLED_WARNING(); |
|---|
| 2593 | RETURN_NULL(); |
|---|
| 2594 | } |
|---|
| 2595 | |
|---|
| 2596 | xce.ttl = XG(var_ttl); |
|---|
| 2597 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|l", &name, &value, &xce.ttl) == FAILURE) { |
|---|
| 2598 | return; |
|---|
| 2599 | } |
|---|
| 2600 | |
|---|
| 2601 | /* max ttl */ |
|---|
| 2602 | if (xc_var_maxttl && (!xce.ttl || xce.ttl > xc_var_maxttl)) { |
|---|
| 2603 | xce.ttl = xc_var_maxttl; |
|---|
| 2604 | } |
|---|
| 2605 | |
|---|
| 2606 | xce.data.var = &var; |
|---|
| 2607 | xc_entry_init_key_var(&xce, name TSRMLS_CC); |
|---|
| 2608 | |
|---|
| 2609 | ENTER_LOCK(xce.cache) { |
|---|
| 2610 | stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC); |
|---|
| 2611 | if (stored_xce) { |
|---|
| 2612 | xc_entry_remove_dmz(stored_xce TSRMLS_CC); |
|---|
| 2613 | } |
|---|
| 2614 | var.value = value; |
|---|
| 2615 | RETVAL_BOOL(xc_entry_store_dmz(&xce TSRMLS_CC) != NULL ? 1 : 0); |
|---|
| 2616 | } LEAVE_LOCK(xce.cache); |
|---|
| 2617 | } |
|---|
| 2618 | /* }}} */ |
|---|
| 2619 | /* {{{ proto bool xcache_isset(string name) |
|---|
| 2620 | Check if an entry exists in cache by specified name */ |
|---|
| 2621 | PHP_FUNCTION(xcache_isset) |
|---|
| 2622 | { |
|---|
| 2623 | xc_entry_t xce, *stored_xce; |
|---|
| 2624 | xc_entry_data_var_t var; |
|---|
| 2625 | zval *name; |
|---|
| 2626 | int found = 0; |
|---|
| 2627 | |
|---|
| 2628 | if (!xc_var_caches) { |
|---|
| 2629 | VAR_DISABLED_WARNING(); |
|---|
| 2630 | RETURN_FALSE; |
|---|
| 2631 | } |
|---|
| 2632 | |
|---|
| 2633 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &name) == FAILURE) { |
|---|
| 2634 | return; |
|---|
| 2635 | } |
|---|
| 2636 | xce.data.var = &var; |
|---|
| 2637 | xc_entry_init_key_var(&xce, name TSRMLS_CC); |
|---|
| 2638 | |
|---|
| 2639 | ENTER_LOCK(xce.cache) { |
|---|
| 2640 | stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC); |
|---|
| 2641 | if (stored_xce) { |
|---|
| 2642 | if (!VAR_ENTRY_EXPIRED(stored_xce)) { |
|---|
| 2643 | found = 1; |
|---|
| 2644 | RETVAL_TRUE; |
|---|
| 2645 | /* return */ |
|---|
| 2646 | break; |
|---|
| 2647 | } |
|---|
| 2648 | else { |
|---|
| 2649 | xc_entry_remove_dmz(stored_xce TSRMLS_CC); |
|---|
| 2650 | } |
|---|
| 2651 | } |
|---|
| 2652 | |
|---|
| 2653 | RETVAL_FALSE; |
|---|
| 2654 | } LEAVE_LOCK(xce.cache); |
|---|
| 2655 | if (found) { |
|---|
| 2656 | xc_cache_hit_dmz(xce.cache TSRMLS_CC); |
|---|
| 2657 | } |
|---|
| 2658 | else { |
|---|
| 2659 | xce.cache->misses ++; |
|---|
| 2660 | } |
|---|
| 2661 | } |
|---|
| 2662 | /* }}} */ |
|---|
| 2663 | /* {{{ proto bool xcache_unset(string name) |
|---|
| 2664 | Unset existing data in cache by specified name */ |
|---|
| 2665 | PHP_FUNCTION(xcache_unset) |
|---|
| 2666 | { |
|---|
| 2667 | xc_entry_t xce, *stored_xce; |
|---|
| 2668 | xc_entry_data_var_t var; |
|---|
| 2669 | zval *name; |
|---|
| 2670 | |
|---|
| 2671 | if (!xc_var_caches) { |
|---|
| 2672 | VAR_DISABLED_WARNING(); |
|---|
| 2673 | RETURN_FALSE; |
|---|
| 2674 | } |
|---|
| 2675 | |
|---|
| 2676 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &name) == FAILURE) { |
|---|
| 2677 | return; |
|---|
| 2678 | } |
|---|
| 2679 | xce.data.var = &var; |
|---|
| 2680 | xc_entry_init_key_var(&xce, name TSRMLS_CC); |
|---|
| 2681 | |
|---|
| 2682 | ENTER_LOCK(xce.cache) { |
|---|
| 2683 | stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC); |
|---|
| 2684 | if (stored_xce) { |
|---|
| 2685 | xc_entry_remove_dmz(stored_xce TSRMLS_CC); |
|---|
| 2686 | RETVAL_TRUE; |
|---|
| 2687 | } |
|---|
| 2688 | else { |
|---|
| 2689 | RETVAL_FALSE; |
|---|
| 2690 | } |
|---|
| 2691 | } LEAVE_LOCK(xce.cache); |
|---|
| 2692 | } |
|---|
| 2693 | /* }}} */ |
|---|
| 2694 | /* {{{ proto bool xcache_unset_by_prefix(string prefix) |
|---|
| 2695 | Unset existing data in cache by specified prefix */ |
|---|
| 2696 | PHP_FUNCTION(xcache_unset_by_prefix) |
|---|
| 2697 | { |
|---|
| 2698 | zval *prefix; |
|---|
| 2699 | int i, iend; |
|---|
| 2700 | |
|---|
| 2701 | if (!xc_var_caches) { |
|---|
| 2702 | VAR_DISABLED_WARNING(); |
|---|
| 2703 | RETURN_FALSE; |
|---|
| 2704 | } |
|---|
| 2705 | |
|---|
| 2706 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &prefix) == FAILURE) { |
|---|
| 2707 | return; |
|---|
| 2708 | } |
|---|
| 2709 | |
|---|
| 2710 | for (i = 0, iend = xc_var_hcache.size; i < iend; i ++) { |
|---|
| 2711 | xc_cache_t *cache = xc_var_caches[i]; |
|---|
| 2712 | ENTER_LOCK(cache) { |
|---|
| 2713 | int j, jend; |
|---|
| 2714 | for (j = 0, jend = cache->hentry->size; j < jend; j ++) { |
|---|
| 2715 | xc_entry_t *entry, *next; |
|---|
| 2716 | for (entry = cache->entries[j]; entry; entry = next) { |
|---|
| 2717 | next = entry->next; |
|---|
| 2718 | if (xc_entry_has_prefix_dmz(entry, prefix)) { |
|---|
| 2719 | xc_entry_remove_dmz(entry TSRMLS_CC); |
|---|
| 2720 | } |
|---|
| 2721 | } |
|---|
| 2722 | } |
|---|
| 2723 | } LEAVE_LOCK(cache); |
|---|
| 2724 | } |
|---|
| 2725 | } |
|---|
| 2726 | /* }}} */ |
|---|
| 2727 | static inline void xc_var_inc_dec(int inc, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */ |
|---|
| 2728 | { |
|---|
| 2729 | xc_entry_t xce, *stored_xce; |
|---|
| 2730 | xc_entry_data_var_t var, *stored_var; |
|---|
| 2731 | zval *name; |
|---|
| 2732 | long count = 1; |
|---|
| 2733 | long value = 0; |
|---|
| 2734 | zval oldzval; |
|---|
| 2735 | |
|---|
| 2736 | if (!xc_var_caches) { |
|---|
| 2737 | VAR_DISABLED_WARNING(); |
|---|
| 2738 | RETURN_NULL(); |
|---|
| 2739 | } |
|---|
| 2740 | |
|---|
| 2741 | xce.ttl = XG(var_ttl); |
|---|
| 2742 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ll", &name, &count, &xce.ttl) == FAILURE) { |
|---|
| 2743 | return; |
|---|
| 2744 | } |
|---|
| 2745 | |
|---|
| 2746 | /* max ttl */ |
|---|
| 2747 | if (xc_var_maxttl && (!xce.ttl || xce.ttl > xc_var_maxttl)) { |
|---|
| 2748 | xce.ttl = xc_var_maxttl; |
|---|
| 2749 | } |
|---|
| 2750 | |
|---|
| 2751 | xce.data.var = &var; |
|---|
| 2752 | xc_entry_init_key_var(&xce, name TSRMLS_CC); |
|---|
| 2753 | |
|---|
| 2754 | ENTER_LOCK(xce.cache) { |
|---|
| 2755 | stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC); |
|---|
| 2756 | if (stored_xce) { |
|---|
| 2757 | TRACE("incdec: gotxce %s", xce.name.str.val); |
|---|
| 2758 | /* timeout */ |
|---|
| 2759 | if (VAR_ENTRY_EXPIRED(stored_xce)) { |
|---|
| 2760 | TRACE("%s", "incdec: expired"); |
|---|
| 2761 | xc_entry_remove_dmz(stored_xce TSRMLS_CC); |
|---|
| 2762 | stored_xce = NULL; |
|---|
| 2763 | } |
|---|
| 2764 | else { |
|---|
| 2765 | /* do it in place */ |
|---|
| 2766 | stored_var = stored_xce->data.var; |
|---|
| 2767 | if (Z_TYPE_P(stored_var->value) == IS_LONG) { |
|---|
| 2768 | zval *zv; |
|---|
| 2769 | stored_xce->ctime = XG(request_time); |
|---|
| 2770 | stored_xce->ttl = xce.ttl; |
|---|
| 2771 | TRACE("%s", "incdec: islong"); |
|---|
| 2772 | value = Z_LVAL_P(stored_var->value); |
|---|
| 2773 | value += (inc == 1 ? count : - count); |
|---|
| 2774 | RETVAL_LONG(value); |
|---|
| 2775 | |
|---|
| 2776 | zv = (zval *) xce.cache->shm->handlers->to_readwrite(xce.cache->shm, (char *) stored_var->value); |
|---|
| 2777 | Z_LVAL_P(zv) = value; |
|---|
| 2778 | break; /* leave lock */ |
|---|
| 2779 | } |
|---|
| 2780 | else { |
|---|
| 2781 | TRACE("%s", "incdec: notlong"); |
|---|
| 2782 | xc_processor_restore_zval(&oldzval, stored_xce->data.var->value, stored_xce->data.var->have_references TSRMLS_CC); |
|---|
| 2783 | convert_to_long(&oldzval); |
|---|
| 2784 | value = Z_LVAL(oldzval); |
|---|
| 2785 | zval_dtor(&oldzval); |
|---|
| 2786 | } |
|---|
| 2787 | } |
|---|
| 2788 | } |
|---|
| 2789 | else { |
|---|
| 2790 | TRACE("incdec: %s not found", xce.name.str.val); |
|---|
| 2791 | } |
|---|
| 2792 | |
|---|
| 2793 | value += (inc == 1 ? count : - count); |
|---|
| 2794 | RETVAL_LONG(value); |
|---|
| 2795 | var.value = return_value; |
|---|
| 2796 | |
|---|
| 2797 | if (stored_xce) { |
|---|
| 2798 | xce.atime = stored_xce->atime; |
|---|
| 2799 | xce.ctime = stored_xce->ctime; |
|---|
| 2800 | xce.hits = stored_xce->hits; |
|---|
| 2801 | xc_entry_remove_dmz(stored_xce TSRMLS_CC); |
|---|
| 2802 | } |
|---|
| 2803 | xc_entry_store_dmz(&xce TSRMLS_CC); |
|---|
| 2804 | |
|---|
| 2805 | } LEAVE_LOCK(xce.cache); |
|---|
| 2806 | } |
|---|
| 2807 | /* }}} */ |
|---|
| 2808 | /* {{{ proto int xcache_inc(string name [, int value [, int ttl]]) |
|---|
| 2809 | Increase an int counter in cache by specified name, create it if not exists */ |
|---|
| 2810 | PHP_FUNCTION(xcache_inc) |
|---|
| 2811 | { |
|---|
| 2812 | xc_var_inc_dec(1, INTERNAL_FUNCTION_PARAM_PASSTHRU); |
|---|
| 2813 | } |
|---|
| 2814 | /* }}} */ |
|---|
| 2815 | /* {{{ proto int xcache_dec(string name [, int value [, int ttl]]) |
|---|
| 2816 | Decrease an int counter in cache by specified name, create it if not exists */ |
|---|
| 2817 | PHP_FUNCTION(xcache_dec) |
|---|
| 2818 | { |
|---|
| 2819 | xc_var_inc_dec(-1, INTERNAL_FUNCTION_PARAM_PASSTHRU); |
|---|
| 2820 | } |
|---|
| 2821 | /* }}} */ |
|---|
| 2822 | #ifdef HAVE_XCACHE_DPRINT |
|---|
| 2823 | /* {{{ proto bool xcache_dprint(mixed value) |
|---|
| 2824 | Prints variable (or value) internal struct (debug only) */ |
|---|
| 2825 | PHP_FUNCTION(xcache_dprint) |
|---|
| 2826 | { |
|---|
| 2827 | zval *value; |
|---|
| 2828 | |
|---|
| 2829 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) == FAILURE) { |
|---|
| 2830 | return; |
|---|
| 2831 | } |
|---|
| 2832 | xc_dprint_zval(value, 0 TSRMLS_CC); |
|---|
| 2833 | } |
|---|
| 2834 | /* }}} */ |
|---|
| 2835 | #endif |
|---|
| 2836 | /* {{{ proto string xcache_asm(string filename) |
|---|
| 2837 | */ |
|---|
| 2838 | #ifdef HAVE_XCACHE_ASSEMBLER |
|---|
| 2839 | PHP_FUNCTION(xcache_asm) |
|---|
| 2840 | { |
|---|
| 2841 | } |
|---|
| 2842 | #endif |
|---|
| 2843 | /* }}} */ |
|---|
| 2844 | #ifdef HAVE_XCACHE_DISASSEMBLER |
|---|
| 2845 | /* {{{ proto array xcache_dasm_file(string filename) |
|---|
| 2846 | Disassemble file into opcode array by filename */ |
|---|
| 2847 | PHP_FUNCTION(xcache_dasm_file) |
|---|
| 2848 | { |
|---|
| 2849 | char *filename; |
|---|
| 2850 | int filename_len; |
|---|
| 2851 | |
|---|
| 2852 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) { |
|---|
| 2853 | return; |
|---|
| 2854 | } |
|---|
| 2855 | if (!filename_len) RETURN_FALSE; |
|---|
| 2856 | |
|---|
| 2857 | xc_dasm_file(return_value, filename TSRMLS_CC); |
|---|
| 2858 | } |
|---|
| 2859 | /* }}} */ |
|---|
| 2860 | /* {{{ proto array xcache_dasm_string(string code) |
|---|
| 2861 | Disassemble php code into opcode array */ |
|---|
| 2862 | PHP_FUNCTION(xcache_dasm_string) |
|---|
| 2863 | { |
|---|
| 2864 | zval *code; |
|---|
| 2865 | |
|---|
| 2866 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &code) == FAILURE) { |
|---|
| 2867 | return; |
|---|
| 2868 | } |
|---|
| 2869 | xc_dasm_string(return_value, code TSRMLS_CC); |
|---|
| 2870 | } |
|---|
| 2871 | /* }}} */ |
|---|
| 2872 | #endif |
|---|
| 2873 | /* {{{ proto string xcache_encode(string filename) |
|---|
| 2874 | Encode php file into XCache opcode encoded format */ |
|---|
| 2875 | #ifdef HAVE_XCACHE_ENCODER |
|---|
| 2876 | PHP_FUNCTION(xcache_encode) |
|---|
| 2877 | { |
|---|
| 2878 | } |
|---|
| 2879 | #endif |
|---|
| 2880 | /* }}} */ |
|---|
| 2881 | /* {{{ proto bool xcache_decode_file(string filename) |
|---|
| 2882 | Decode(load) opcode from XCache encoded format file */ |
|---|
| 2883 | #ifdef HAVE_XCACHE_DECODER |
|---|
| 2884 | PHP_FUNCTION(xcache_decode_file) |
|---|
| 2885 | { |
|---|
| 2886 | } |
|---|
| 2887 | #endif |
|---|
| 2888 | /* }}} */ |
|---|
| 2889 | /* {{{ proto bool xcache_decode_string(string data) |
|---|
| 2890 | Decode(load) opcode from XCache encoded format data */ |
|---|
| 2891 | #ifdef HAVE_XCACHE_DECODER |
|---|
| 2892 | PHP_FUNCTION(xcache_decode_string) |
|---|
| 2893 | { |
|---|
| 2894 | } |
|---|
| 2895 | #endif |
|---|
| 2896 | /* }}} */ |
|---|
| 2897 | /* {{{ xc_call_getter */ |
|---|
| 2898 | typedef const char *(xc_name_getter_t)(zend_uchar type); |
|---|
| 2899 | static void xc_call_getter(xc_name_getter_t getter, int count, INTERNAL_FUNCTION_PARAMETERS) |
|---|
| 2900 | { |
|---|
| 2901 | long spec; |
|---|
| 2902 | const char *name; |
|---|
| 2903 | |
|---|
| 2904 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &spec) == FAILURE) { |
|---|
| 2905 | return; |
|---|
| 2906 | } |
|---|
| 2907 | if (spec >= 0 && spec < count) { |
|---|
| 2908 | name = getter((zend_uchar) spec); |
|---|
| 2909 | if (name) { |
|---|
| 2910 | /* RETURN_STRING */ |
|---|
| 2911 | int len = strlen(name); |
|---|
| 2912 | return_value->value.str.len = len; |
|---|
| 2913 | return_value->value.str.val = estrndup(name, len); |
|---|
| 2914 | return_value->type = IS_STRING; |
|---|
| 2915 | return; |
|---|
| 2916 | } |
|---|
| 2917 | } |
|---|
| 2918 | RETURN_NULL(); |
|---|
| 2919 | } |
|---|
| 2920 | /* }}} */ |
|---|
| 2921 | /* {{{ proto string xcache_get_op_type(int op_type) */ |
|---|
| 2922 | PHP_FUNCTION(xcache_get_op_type) |
|---|
| 2923 | { |
|---|
| 2924 | xc_call_getter(xc_get_op_type, xc_get_op_type_count(), INTERNAL_FUNCTION_PARAM_PASSTHRU); |
|---|
| 2925 | } |
|---|
| 2926 | /* }}} */ |
|---|
| 2927 | /* {{{ proto string xcache_get_data_type(int type) */ |
|---|
| 2928 | PHP_FUNCTION(xcache_get_data_type) |
|---|
| 2929 | { |
|---|
| 2930 | xc_call_getter(xc_get_data_type, xc_get_data_type_count(), INTERNAL_FUNCTION_PARAM_PASSTHRU); |
|---|
| 2931 | } |
|---|
| 2932 | /* }}} */ |
|---|
| 2933 | /* {{{ proto string xcache_get_opcode(int opcode) */ |
|---|
| 2934 | PHP_FUNCTION(xcache_get_opcode) |
|---|
| 2935 | { |
|---|
| 2936 | xc_call_getter(xc_get_opcode, xc_get_opcode_count(), INTERNAL_FUNCTION_PARAM_PASSTHRU); |
|---|
| 2937 | } |
|---|
| 2938 | /* }}} */ |
|---|
| 2939 | /* {{{ proto string xcache_get_op_spec(int op_type) */ |
|---|
| 2940 | PHP_FUNCTION(xcache_get_op_spec) |
|---|
| 2941 | { |
|---|
| 2942 | xc_call_getter(xc_get_op_spec, xc_get_op_spec_count(), INTERNAL_FUNCTION_PARAM_PASSTHRU); |
|---|
| 2943 | } |
|---|
| 2944 | /* }}} */ |
|---|
| 2945 | #ifdef HAVE_XCACHE_OPCODE_SPEC_DEF |
|---|
| 2946 | /* {{{ proto string xcache_get_opcode_spec(int opcode) */ |
|---|
| 2947 | PHP_FUNCTION(xcache_get_opcode_spec) |
|---|
| 2948 | { |
|---|
| 2949 | long spec; |
|---|
| 2950 | const xc_opcode_spec_t *opspec; |
|---|
| 2951 | |
|---|
| 2952 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &spec) == FAILURE) { |
|---|
| 2953 | return; |
|---|
| 2954 | } |
|---|
| 2955 | if ((zend_uchar) spec <= xc_get_opcode_spec_count()) { |
|---|
| 2956 | opspec = xc_get_opcode_spec((zend_uchar) spec); |
|---|
| 2957 | if (opspec) { |
|---|
| 2958 | array_init(return_value); |
|---|
| 2959 | add_assoc_long_ex(return_value, ZEND_STRS("ext"), opspec->ext); |
|---|
| 2960 | add_assoc_long_ex(return_value, ZEND_STRS("op1"), opspec->op1); |
|---|
| 2961 | add_assoc_long_ex(return_value, ZEND_STRS("op2"), opspec->op2); |
|---|
| 2962 | add_assoc_long_ex(return_value, ZEND_STRS("res"), opspec->res); |
|---|
| 2963 | return; |
|---|
| 2964 | } |
|---|
| 2965 | } |
|---|
| 2966 | RETURN_NULL(); |
|---|
| 2967 | } |
|---|
| 2968 | /* }}} */ |
|---|
| 2969 | #endif |
|---|
| 2970 | /* {{{ proto mixed xcache_get_special_value(zval value) */ |
|---|
| 2971 | PHP_FUNCTION(xcache_get_special_value) |
|---|
| 2972 | { |
|---|
| 2973 | zval *value; |
|---|
| 2974 | |
|---|
| 2975 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) == FAILURE) { |
|---|
| 2976 | return; |
|---|
| 2977 | } |
|---|
| 2978 | |
|---|
| 2979 | if (value->type == IS_CONSTANT) { |
|---|
| 2980 | *return_value = *value; |
|---|
| 2981 | zval_copy_ctor(return_value); |
|---|
| 2982 | return_value->type = UNISW(IS_STRING, UG(unicode) ? IS_UNICODE : IS_STRING); |
|---|
| 2983 | return; |
|---|
| 2984 | } |
|---|
| 2985 | |
|---|
| 2986 | if (value->type == IS_CONSTANT_ARRAY) { |
|---|
| 2987 | *return_value = *value; |
|---|
| 2988 | zval_copy_ctor(return_value); |
|---|
| 2989 | return_value->type = IS_ARRAY; |
|---|
| 2990 | return; |
|---|
| 2991 | } |
|---|
| 2992 | |
|---|
| 2993 | RETURN_NULL(); |
|---|
| 2994 | } |
|---|
| 2995 | /* }}} */ |
|---|
| 2996 | /* {{{ proto string xcache_coredump(int op_type) */ |
|---|
| 2997 | PHP_FUNCTION(xcache_coredump) |
|---|
| 2998 | { |
|---|
| 2999 | if (xc_test) { |
|---|
| 3000 | raise(SIGSEGV); |
|---|
| 3001 | } |
|---|
| 3002 | else { |
|---|
| 3003 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "xcache.test must be enabled to test xcache_coredump()"); |
|---|
| 3004 | } |
|---|
| 3005 | } |
|---|
| 3006 | /* }}} */ |
|---|
| 3007 | /* {{{ proto string xcache_is_autoglobal(string name) */ |
|---|
| 3008 | PHP_FUNCTION(xcache_is_autoglobal) |
|---|
| 3009 | { |
|---|
| 3010 | char *name; |
|---|
| 3011 | int name_len; |
|---|
| 3012 | |
|---|
| 3013 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { |
|---|
| 3014 | return; |
|---|
| 3015 | } |
|---|
| 3016 | |
|---|
| 3017 | RETURN_BOOL(zend_hash_exists(CG(auto_globals), name, name_len + 1)); |
|---|
| 3018 | } |
|---|
| 3019 | /* }}} */ |
|---|
| 3020 | static function_entry xcache_functions[] = /* {{{ */ |
|---|
| 3021 | { |
|---|
| 3022 | PHP_FE(xcache_count, NULL) |
|---|
| 3023 | PHP_FE(xcache_info, NULL) |
|---|
| 3024 | PHP_FE(xcache_list, NULL) |
|---|
| 3025 | PHP_FE(xcache_clear_cache, NULL) |
|---|
| 3026 | PHP_FE(xcache_coredump, NULL) |
|---|
| 3027 | #ifdef HAVE_XCACHE_ASSEMBLER |
|---|
| 3028 | PHP_FE(xcache_asm, NULL) |
|---|
| 3029 | #endif |
|---|
| 3030 | #ifdef HAVE_XCACHE_DISASSEMBLER |
|---|
| 3031 | PHP_FE(xcache_dasm_file, NULL) |
|---|
| 3032 | PHP_FE(xcache_dasm_string, NULL) |
|---|
| 3033 | #endif |
|---|
| 3034 | #ifdef HAVE_XCACHE_ENCODER |
|---|
| 3035 | PHP_FE(xcache_encode, NULL) |
|---|
| 3036 | #endif |
|---|
| 3037 | #ifdef HAVE_XCACHE_DECODER |
|---|
| 3038 | PHP_FE(xcache_decode_file, NULL) |
|---|
| 3039 | PHP_FE(xcache_decode_string, NULL) |
|---|
| 3040 | #endif |
|---|
| 3041 | #ifdef HAVE_XCACHE_COVERAGER |
|---|
| 3042 | PHP_FE(xcache_coverager_decode, NULL) |
|---|
| 3043 | PHP_FE(xcache_coverager_start, NULL) |
|---|
| 3044 | PHP_FE(xcache_coverager_stop, NULL) |
|---|
| 3045 | PHP_FE(xcache_coverager_get, NULL) |
|---|
| 3046 | #endif |
|---|
| 3047 | PHP_FE(xcache_get_special_value, NULL) |
|---|
| 3048 | PHP_FE(xcache_get_op_type, NULL) |
|---|
| 3049 | PHP_FE(xcache_get_data_type, NULL) |
|---|
| 3050 | PHP_FE(xcache_get_opcode, NULL) |
|---|
| 3051 | #ifdef HAVE_XCACHE_OPCODE_SPEC_DEF |
|---|
| 3052 | PHP_FE(xcache_get_opcode_spec, NULL) |
|---|
| 3053 | #endif |
|---|
| 3054 | PHP_FE(xcache_is_autoglobal, NULL) |
|---|
| 3055 | PHP_FE(xcache_inc, NULL) |
|---|
| 3056 | PHP_FE(xcache_dec, NULL) |
|---|
| 3057 | PHP_FE(xcache_get, NULL) |
|---|
| 3058 | PHP_FE(xcache_set, NULL) |
|---|
| 3059 | PHP_FE(xcache_isset, NULL) |
|---|
| 3060 | PHP_FE(xcache_unset, NULL) |
|---|
| 3061 | PHP_FE(xcache_unset_by_prefix, NULL) |
|---|
| 3062 | #ifdef HAVE_XCACHE_DPRINT |
|---|
| 3063 | PHP_FE(xcache_dprint, NULL) |
|---|
| 3064 | #endif |
|---|
| 3065 | {NULL, NULL, NULL} |
|---|
| 3066 | }; |
|---|
| 3067 | /* }}} */ |
|---|
| 3068 | |
|---|
| 3069 | /* old signal handlers {{{ */ |
|---|
| 3070 | typedef void (*xc_sighandler_t)(int); |
|---|
| 3071 | #define FOREACH_SIG(sig) static xc_sighandler_t old_##sig##_handler = NULL |
|---|
| 3072 | #include "foreachcoresig.h" |
|---|
| 3073 | #undef FOREACH_SIG |
|---|
| 3074 | /* }}} */ |
|---|
| 3075 | static void xcache_signal_handler(int sig); |
|---|
| 3076 | static void xcache_restore_signal_handler() /* {{{ */ |
|---|
| 3077 | { |
|---|
| 3078 | #define FOREACH_SIG(sig) do { \ |
|---|
| 3079 | if (old_##sig##_handler != xcache_signal_handler) { \ |
|---|
| 3080 | signal(sig, old_##sig##_handler); \ |
|---|
| 3081 | } \ |
|---|
| 3082 | else { \ |
|---|
| 3083 | signal(sig, SIG_DFL); \ |
|---|
| 3084 | } \ |
|---|
| 3085 | } while (0) |
|---|
| 3086 | #include "foreachcoresig.h" |
|---|
| 3087 | #undef FOREACH_SIG |
|---|
| 3088 | } |
|---|
| 3089 | /* }}} */ |
|---|
| 3090 | static void xcache_init_signal_handler() /* {{{ */ |
|---|
| 3091 | { |
|---|
| 3092 | #define FOREACH_SIG(sig) \ |
|---|
| 3093 | old_##sig##_handler = signal(sig, xcache_signal_handler) |
|---|
| 3094 | #include "foreachcoresig.h" |
|---|
| 3095 | #undef FOREACH_SIG |
|---|
| 3096 | } |
|---|
| 3097 | /* }}} */ |
|---|
| 3098 | static void xcache_signal_handler(int sig) /* {{{ */ |
|---|
| 3099 | { |
|---|
| 3100 | xcache_restore_signal_handler(); |
|---|
| 3101 | if (xc_coredump_dir && xc_coredump_dir[0]) { |
|---|
| 3102 | chdir(xc_coredump_dir); |
|---|
| 3103 | } |
|---|
| 3104 | raise(sig); |
|---|
| 3105 | } |
|---|
| 3106 | /* }}} */ |
|---|
| 3107 | |
|---|
| 3108 | /* {{{ PHP_INI */ |
|---|
| 3109 | |
|---|
| 3110 | static PHP_INI_MH(xc_OnUpdateDummy) |
|---|
| 3111 | { |
|---|
| 3112 | return SUCCESS; |
|---|
| 3113 | } |
|---|
| 3114 | |
|---|
| 3115 | static PHP_INI_MH(xc_OnUpdateULong) |
|---|
| 3116 | { |
|---|
| 3117 | zend_ulong *p = (zend_ulong *) mh_arg1; |
|---|
| 3118 | |
|---|
| 3119 | *p = (zend_ulong) atoi(new_value); |
|---|
| 3120 | return SUCCESS; |
|---|
| 3121 | } |
|---|
| 3122 | |
|---|
| 3123 | static PHP_INI_MH(xc_OnUpdateBool) |
|---|
| 3124 | { |
|---|
| 3125 | zend_bool *p = (zend_bool *)mh_arg1; |
|---|
| 3126 | |
|---|
| 3127 | if (strncasecmp("on", new_value, sizeof("on"))) { |
|---|
| 3128 | *p = (zend_bool) atoi(new_value); |
|---|
| 3129 | } |
|---|
| 3130 | else { |
|---|
| 3131 | *p = (zend_bool) 1; |
|---|
| 3132 | } |
|---|
| 3133 | return SUCCESS; |
|---|
| 3134 | } |
|---|
| 3135 | |
|---|
| 3136 | static PHP_INI_MH(xc_OnUpdateString) |
|---|
| 3137 | { |
|---|
| 3138 | char **p = (char**)mh_arg1; |
|---|
| 3139 | if (*p) { |
|---|
| 3140 | pefree(*p, 1); |
|---|
| 3141 | } |
|---|
| 3142 | *p = pemalloc(strlen(new_value) + 1, 1); |
|---|
| 3143 | strcpy(*p, new_value); |
|---|
| 3144 | return SUCCESS; |
|---|
| 3145 | } |
|---|
| 3146 | |
|---|
| 3147 | #ifndef ZEND_ENGINE_2 |
|---|
| 3148 | #define OnUpdateLong OnUpdateInt |
|---|
| 3149 | #endif |
|---|
| 3150 | |
|---|
| 3151 | #ifdef ZEND_WIN32 |
|---|
| 3152 | # define DEFAULT_PATH "xcache" |
|---|
| 3153 | #else |
|---|
| 3154 | # define DEFAULT_PATH "/dev/zero" |
|---|
| 3155 | #endif |
|---|
| 3156 | PHP_INI_BEGIN() |
|---|
| 3157 | PHP_INI_ENTRY1 ("xcache.mmap_path", DEFAULT_PATH, PHP_INI_SYSTEM, xc_OnUpdateString, &xc_mmap_path) |
|---|
| 3158 | PHP_INI_ENTRY1 ("xcache.coredump_directory", "", PHP_INI_SYSTEM, xc_OnUpdateString, &xc_coredump_dir) |
|---|
| 3159 | PHP_INI_ENTRY1 ("xcache.test", "0", PHP_INI_SYSTEM, xc_OnUpdateBool, &xc_test) |
|---|
| 3160 | PHP_INI_ENTRY1 ("xcache.readonly_protection", "0", PHP_INI_SYSTEM, xc_OnUpdateBool, &xc_readonly_protection) |
|---|
| 3161 | /* opcode cache */ |
|---|
| 3162 | PHP_INI_ENTRY1 ("xcache.size", "0", PHP_INI_SYSTEM, xc_OnUpdateDummy, NULL) |
|---|
| 3163 | PHP_INI_ENTRY1 ("xcache.count", "1", PHP_INI_SYSTEM, xc_OnUpdateDummy, NULL) |
|---|
| 3164 | PHP_INI_ENTRY1 ("xcache.slots", "8K", PHP_INI_SYSTEM, xc_OnUpdateDummy, NULL) |
|---|
| 3165 | PHP_INI_ENTRY1 ("xcache.shm_scheme", "mmap", PHP_INI_SYSTEM, xc_OnUpdateString, &xc_shm_scheme) |
|---|
| 3166 | PHP_INI_ENTRY1 ("xcache.ttl", "0", PHP_INI_SYSTEM, xc_OnUpdateULong, &xc_php_ttl) |
|---|
| 3167 | PHP_INI_ENTRY1 ("xcache.gc_interval", "0", PHP_INI_SYSTEM, xc_OnUpdateULong, &xc_php_gc_interval) |
|---|
| 3168 | /* var cache */ |
|---|
| 3169 | PHP_INI_ENTRY1 ("xcache.var_size", "0", PHP_INI_SYSTEM, xc_OnUpdateDummy, NULL) |
|---|
| 3170 | PHP_INI_ENTRY1 ("xcache.var_count", "1", PHP_INI_SYSTEM, xc_OnUpdateDummy, NULL) |
|---|
| 3171 | PHP_INI_ENTRY1 ("xcache.var_slots", "8K", PHP_INI_SYSTEM, xc_OnUpdateDummy, NULL) |
|---|
| 3172 | PHP_INI_ENTRY1 ("xcache.var_maxttl", "0", PHP_INI_SYSTEM, xc_OnUpdateULong, &xc_var_maxttl) |
|---|
| 3173 | PHP_INI_ENTRY1 ("xcache.var_gc_interval", "120", PHP_INI_SYSTEM, xc_OnUpdateULong, &xc_var_gc_interval) |
|---|
| 3174 | |
|---|
| 3175 | STD_PHP_INI_BOOLEAN("xcache.cacher", "1", PHP_INI_ALL, OnUpdateBool, cacher, zend_xcache_globals, xcache_globals) |
|---|
| 3176 | STD_PHP_INI_BOOLEAN("xcache.stat", "1", PHP_INI_ALL, OnUpdateBool, stat, zend_xcache_globals, xcache_globals) |
|---|
| 3177 | STD_PHP_INI_BOOLEAN("xcache.experimental", "0", PHP_INI_ALL, OnUpdateBool, experimental, zend_xcache_globals, xcache_globals) |
|---|
| 3178 | #ifdef HAVE_XCACHE_OPTIMIZER |
|---|
| 3179 | STD_PHP_INI_BOOLEAN("xcache.optimizer", "0", PHP_INI_ALL, OnUpdateBool, optimizer, zend_xcache_globals, xcache_globals) |
|---|
| 3180 | #endif |
|---|
| 3181 | STD_PHP_INI_ENTRY ("xcache.var_ttl", "0", PHP_INI_ALL, OnUpdateLong, var_ttl, zend_xcache_globals, xcache_globals) |
|---|
| 3182 | #ifdef HAVE_XCACHE_COVERAGER |
|---|
| 3183 | STD_PHP_INI_BOOLEAN("xcache.coverager" , "0", PHP_INI_ALL, OnUpdateBool, coverager, zend_xcache_globals, xcache_globals) |
|---|
| 3184 | PHP_INI_ENTRY1 ("xcache.coveragedump_directory", "", PHP_INI_SYSTEM, xc_OnUpdateDummy, NULL) |
|---|
| 3185 | #endif |
|---|
| 3186 | PHP_INI_END() |
|---|
| 3187 | /* }}} */ |
|---|
| 3188 | /* {{{ PHP_MINFO_FUNCTION(xcache) */ |
|---|
| 3189 | static PHP_MINFO_FUNCTION(xcache) |
|---|
| 3190 | { |
|---|
| 3191 | char buf[100]; |
|---|
| 3192 | char *ptr; |
|---|
| 3193 | int left, len; |
|---|
| 3194 | xc_shm_scheme_t *scheme; |
|---|
| 3195 | #ifdef HAVE_XCACHE_COVERAGER |
|---|
| 3196 | char *covdumpdir; |
|---|
| 3197 | #endif |
|---|
| 3198 | |
|---|
| 3199 | php_info_print_table_start(); |
|---|
| 3200 | php_info_print_table_header(2, "XCache Support", "enabled"); |
|---|
| 3201 | php_info_print_table_row(2, "Version", XCACHE_VERSION); |
|---|
| 3202 | php_info_print_table_row(2, "Modules Built", XCACHE_MODULES); |
|---|
| 3203 | php_info_print_table_row(2, "Readonly Protection", xc_readonly_protection ? "enabled" : "N/A"); |
|---|
| 3204 | #ifdef ZEND_ENGINE_2_1 |
|---|
| 3205 | ptr = php_format_date("Y-m-d H:i:s", sizeof("Y-m-d H:i:s") - 1, xc_init_time, 1 TSRMLS_CC); |
|---|
| 3206 | php_info_print_table_row(2, "Cache Init Time", ptr); |
|---|
| 3207 | efree(ptr); |
|---|
| 3208 | #else |
|---|
| 3209 | snprintf(buf, sizeof(buf), "%lu", (long unsigned) xc_init_time); |
|---|
| 3210 | php_info_print_table_row(2, "Cache Init Time", buf); |
|---|
| 3211 | #endif |
|---|
| 3212 | |
|---|
| 3213 | #ifdef ZTS |
|---|
| 3214 | snprintf(buf, sizeof(buf), "%lu.%lu", xc_init_instance_id, xc_init_instance_subid); |
|---|
| 3215 | #else |
|---|
| 3216 | snprintf(buf, sizeof(buf), "%lu", xc_init_instance_id); |
|---|
| 3217 | #endif |
|---|
| 3218 | php_info_print_table_row(2, "Cache Instance Id", buf); |
|---|
| 3219 | |
|---|
| 3220 | if (xc_php_size) { |
|---|
| 3221 | ptr = _php_math_number_format(xc_php_size, 0, '.', ','); |
|---|
| 3222 | snprintf(buf, sizeof(buf), "enabled, %s bytes, %d split(s), with %d slots each", ptr, xc_php_hcache.size, xc_php_hentry.size); |
|---|
| 3223 | php_info_print_table_row(2, "Opcode Cache", buf); |
|---|
| 3224 | efree(ptr); |
|---|
| 3225 | } |
|---|
| 3226 | else { |
|---|
| 3227 | php_info_print_table_row(2, "Opcode Cache", "disabled"); |
|---|
| 3228 | } |
|---|
| 3229 | if (xc_var_size) { |
|---|
| 3230 | ptr = _php_math_number_format(xc_var_size, 0, '.', ','); |
|---|
| 3231 | snprintf(buf, sizeof(buf), "enabled, %s bytes, %d split(s), with %d slots each", ptr, xc_var_hcache.size, xc_var_hentry.size); |
|---|
| 3232 | php_info_print_table_row(2, "Variable Cache", buf); |
|---|
| 3233 | efree(ptr); |
|---|
| 3234 | } |
|---|
| 3235 | else { |
|---|
| 3236 | php_info_print_table_row(2, "Variable Cache", "disabled"); |
|---|
| 3237 | } |
|---|
| 3238 | |
|---|
| 3239 | left = sizeof(buf); |
|---|
| 3240 | ptr = buf; |
|---|
| 3241 | buf[0] = '\0'; |
|---|
| 3242 | for (scheme = xc_shm_scheme_first(); scheme; scheme = xc_shm_scheme_next(scheme)) { |
|---|
| 3243 | len = snprintf(ptr, left, ptr == buf ? "%s" : ", %s", xc_shm_scheme_name(scheme)); |
|---|
| 3244 | left -= len; |
|---|
| 3245 | ptr += len; |
|---|
| 3246 | } |
|---|
| 3247 | php_info_print_table_row(2, "Shared Memory Schemes", buf); |
|---|
| 3248 | |
|---|
| 3249 | #ifdef HAVE_XCACHE_COVERAGER |
|---|
| 3250 | if (cfg_get_string("xcache.coveragedump_directory", &covdumpdir) != SUCCESS || !covdumpdir[0]) { |
|---|
| 3251 | covdumpdir = NULL; |
|---|
| 3252 | } |
|---|
| 3253 | php_info_print_table_row(2, "Coverage Auto Dumper", XG(coverager) && covdumpdir ? "enabled" : "disabled"); |
|---|
| 3254 | #endif |
|---|
| 3255 | php_info_print_table_end(); |
|---|
| 3256 | |
|---|
| 3257 | DISPLAY_INI_ENTRIES(); |
|---|
| 3258 | } |
|---|
| 3259 | /* }}} */ |
|---|
| 3260 | /* {{{ extension startup */ |
|---|
| 3261 | static void xc_zend_extension_register(zend_extension *new_extension, DL_HANDLE handle) |
|---|
| 3262 | { |
|---|
| 3263 | zend_extension extension; |
|---|
| 3264 | |
|---|
| 3265 | extension = *new_extension; |
|---|
| 3266 | extension.handle = handle; |
|---|
| 3267 | |
|---|
| 3268 | zend_extension_dispatch_message(ZEND_EXTMSG_NEW_EXTENSION, &extension); |
|---|
| 3269 | |
|---|
| 3270 | zend_llist_prepend_element(&zend_extensions, &extension); |
|---|
| 3271 | TRACE("%s", "registered"); |
|---|
| 3272 | } |
|---|
| 3273 | |
|---|
| 3274 | static zend_llist_element *xc_llist_get_element_by_zend_extension(zend_llist *l, const char *extension_name) |
|---|
| 3275 | { |
|---|
| 3276 | zend_llist_element *element; |
|---|
| 3277 | |
|---|
| 3278 | for (element = zend_extensions.head; element; element = element->next) { |
|---|
| 3279 | zend_extension *extension = (zend_extension *) element->data; |
|---|
| 3280 | |
|---|
| 3281 | if (!strcmp(extension->name, extension_name)) { |
|---|
| 3282 | return element; |
|---|
| 3283 | } |
|---|
| 3284 | } |
|---|
| 3285 | return NULL; |
|---|
| 3286 | } |
|---|
| 3287 | |
|---|
| 3288 | static void xc_llist_prepend(zend_llist *l, zend_llist_element *element) |
|---|
| 3289 | { |
|---|
| 3290 | element->next = l->head; |
|---|
| 3291 | element->prev = NULL; |
|---|
| 3292 | if (l->head) { |
|---|
| 3293 | l->head->prev = element; |
|---|
| 3294 | } |
|---|
| 3295 | else { |
|---|
| 3296 | l->tail = element; |
|---|
| 3297 | } |
|---|
| 3298 | l->head = element; |
|---|
| 3299 | ++l->count; |
|---|
| 3300 | } |
|---|
| 3301 | |
|---|
| 3302 | static void xc_llist_unlink(zend_llist *l, zend_llist_element *element) |
|---|
| 3303 | { |
|---|
| 3304 | if ((element)->prev) { |
|---|
| 3305 | (element)->prev->next = (element)->next; |
|---|
| 3306 | } |
|---|
| 3307 | else { |
|---|
| 3308 | (l)->head = (element)->next; |
|---|
| 3309 | } |
|---|
| 3310 | |
|---|
| 3311 | if ((element)->next) { |
|---|
| 3312 | (element)->next->prev = (element)->prev; |
|---|
| 3313 | } |
|---|
| 3314 | else { |
|---|
| 3315 | (l)->tail = (element)->prev; |
|---|
| 3316 | } |
|---|
| 3317 | |
|---|
| 3318 | --l->count; |
|---|
| 3319 | } |
|---|
| 3320 | |
|---|
| 3321 | static int xc_zend_extension_startup(zend_extension *extension) |
|---|
| 3322 | { |
|---|
| 3323 | if (extension->startup) { |
|---|
| 3324 | if (extension->startup(extension) != SUCCESS) { |
|---|
| 3325 | return FAILURE; |
|---|
| 3326 | } |
|---|
| 3327 | } |
|---|
| 3328 | return SUCCESS; |
|---|
| 3329 | } |
|---|
| 3330 | /* }}} */ |
|---|
| 3331 | static int xc_ptr_compare_func(void *p1, void *p2) /* {{{ */ |
|---|
| 3332 | { |
|---|
| 3333 | return p1 == p2; |
|---|
| 3334 | } |
|---|
| 3335 | /* }}} */ |
|---|
| 3336 | static int xc_zend_remove_extension(zend_extension *extension) /* {{{ */ |
|---|
| 3337 | { |
|---|
| 3338 | llist_dtor_func_t dtor; |
|---|
| 3339 | |
|---|
| 3340 | assert(extension); |
|---|
| 3341 | dtor = zend_extensions.dtor; /* avoid dtor */ |
|---|
| 3342 | zend_extensions.dtor = NULL; |
|---|
| 3343 | zend_llist_del_element(&zend_extensions, extension, xc_ptr_compare_func); |
|---|
| 3344 | zend_extensions.dtor = dtor; |
|---|
| 3345 | return SUCCESS; |
|---|
| 3346 | } |
|---|
| 3347 | /* }}} */ |
|---|
| 3348 | static int xc_config_hash(xc_hash_t *p, char *name, char *default_value) /* {{{ */ |
|---|
| 3349 | { |
|---|
| 3350 | int bits, size; |
|---|
| 3351 | char *value; |
|---|
| 3352 | |
|---|
| 3353 | if (cfg_get_string(name, &value) != SUCCESS) { |
|---|
| 3354 | value = default_value; |
|---|
| 3355 | } |
|---|
| 3356 | |
|---|
| 3357 | p->size = zend_atoi(value, strlen(value)); |
|---|
| 3358 | for (size = 1, bits = 1; size < p->size; bits ++, size <<= 1) { |
|---|
| 3359 | /* empty body */ |
|---|
| 3360 | } |
|---|
| 3361 | p->size = size; |
|---|
| 3362 | p->bits = bits; |
|---|
| 3363 | p->mask = size - 1; |
|---|
| 3364 | |
|---|
| 3365 | return SUCCESS; |
|---|
| 3366 | } |
|---|
| 3367 | /* }}} */ |
|---|
| 3368 | static int xc_config_long(zend_ulong *p, char *name, char *default_value) /* {{{ */ |
|---|
| 3369 | { |
|---|
| 3370 | char *value; |
|---|
| 3371 | |
|---|
| 3372 | if (cfg_get_string(name, &value) != SUCCESS) { |
|---|
| 3373 | value = default_value; |
|---|
| 3374 | } |
|---|
| 3375 | |
|---|
| 3376 | *p = zend_atol(value, strlen(value)); |
|---|
| 3377 | return SUCCESS; |
|---|
| 3378 | } |
|---|
| 3379 | /* }}} */ |
|---|
| 3380 | /* {{{ PHP_MINIT_FUNCTION(xcache) */ |
|---|
| 3381 | static PHP_MINIT_FUNCTION(xcache) |
|---|
| 3382 | { |
|---|
| 3383 | char *env; |
|---|
| 3384 | zend_extension *ext; |
|---|
| 3385 | zend_llist_position lpos; |
|---|
| 3386 | |
|---|
| 3387 | xc_module_gotup = 1; |
|---|
| 3388 | if (!xc_zend_extension_gotup) { |
|---|
| 3389 | xc_zend_extension_register(&zend_extension_entry, 0); |
|---|
| 3390 | xc_zend_extension_startup(&zend_extension_entry); |
|---|
| 3391 | xc_zend_extension_faked = 1; |
|---|
| 3392 | } |
|---|
| 3393 | |
|---|
| 3394 | ext = zend_get_extension("Zend Optimizer"); |
|---|
| 3395 | if (ext) { |
|---|
| 3396 | /* zend_optimizer.optimization_level>0 is not compatible with other cacher, disabling */ |
|---|
| 3397 | ext->op_array_handler = NULL; |
|---|
| 3398 | } |
|---|
| 3399 | /* cache if there's an op_array_ctor */ |
|---|
| 3400 | for (ext = zend_llist_get_first_ex(&zend_extensions, &lpos); |
|---|
| 3401 | ext; |
|---|
| 3402 | ext = zend_llist_get_next_ex(&zend_extensions, &lpos)) { |
|---|
| 3403 | if (ext->op_array_ctor) { |
|---|
| 3404 | xc_have_op_array_ctor = 1; |
|---|
| 3405 | break; |
|---|
| 3406 | } |
|---|
| 3407 | } |
|---|
| 3408 | |
|---|
| 3409 | |
|---|
| 3410 | #ifndef PHP_GINIT |
|---|
| 3411 | ZEND_INIT_MODULE_GLOBALS(xcache, xc_init_globals, xc_shutdown_globals); |
|---|
| 3412 | #endif |
|---|
| 3413 | REGISTER_INI_ENTRIES(); |
|---|
| 3414 | |
|---|
| 3415 | xc_config_long(&xc_php_size, "xcache.size", "0"); |
|---|
| 3416 | xc_config_hash(&xc_php_hcache, "xcache.count", "1"); |
|---|
| 3417 | xc_config_hash(&xc_php_hentry, "xcache.slots", "8K"); |
|---|
| 3418 | |
|---|
| 3419 | xc_config_long(&xc_var_size, "xcache.var_size", "0"); |
|---|
| 3420 | xc_config_hash(&xc_var_hcache, "xcache.var_count", "1"); |
|---|
| 3421 | xc_config_hash(&xc_var_hentry, "xcache.var_slots", "8K"); |
|---|
| 3422 | |
|---|
| 3423 | if (strcmp(sapi_module.name, "cli") == 0) { |
|---|
| 3424 | if ((env = getenv("XCACHE_TEST")) != NULL) { |
|---|
| 3425 | zend_alter_ini_entry("xcache.test", sizeof("xcache.test"), env, strlen(env) + 1, PHP_INI_SYSTEM, PHP_INI_STAGE_STARTUP); |
|---|
| 3426 | } |
|---|
| 3427 | if (!xc_test) { |
|---|
| 3428 | /* disable cache for cli except for testing */ |
|---|
| 3429 | xc_php_size = xc_var_size = 0; |
|---|
| 3430 | } |
|---|
| 3431 | } |
|---|
| 3432 | |
|---|
| 3433 | if (xc_php_size <= 0) { |
|---|
| 3434 | xc_php_size = xc_php_hcache.size = 0; |
|---|
| 3435 | } |
|---|
| 3436 | if (xc_var_size <= 0) { |
|---|
| 3437 | xc_var_size = xc_var_hcache.size = 0; |
|---|
| 3438 | } |
|---|
| 3439 | |
|---|
| 3440 | if (xc_coredump_dir && xc_coredump_dir[0]) { |
|---|
| 3441 | xcache_init_signal_handler(); |
|---|
| 3442 | } |
|---|
| 3443 | |
|---|
| 3444 | xc_init_constant(module_number TSRMLS_CC); |
|---|
| 3445 | xc_shm_init_modules(); |
|---|
| 3446 | |
|---|
| 3447 | if ((xc_php_size || xc_var_size) && xc_mmap_path && xc_mmap_path[0]) { |
|---|
| 3448 | if (xc_init(module_number TSRMLS_CC) != SUCCESS) { |
|---|
| 3449 | zend_error(E_ERROR, "XCache: Cannot init"); |
|---|
| 3450 | goto err_init; |
|---|
| 3451 | } |
|---|
| 3452 | xc_initized = 1; |
|---|
| 3453 | xc_init_time = time(NULL); |
|---|
| 3454 | #ifdef PHP_WIN32 |
|---|
| 3455 | xc_init_instance_id = GetCurrentProcessId(); |
|---|
| 3456 | #else |
|---|
| 3457 | xc_init_instance_id = getpid(); |
|---|
| 3458 | #endif |
|---|
| 3459 | #ifdef ZTS |
|---|
| 3460 | xc_init_instance_subid = tsrm_thread_id(); |
|---|
| 3461 | #endif |
|---|
| 3462 | } |
|---|
| 3463 | |
|---|
| 3464 | #ifdef HAVE_XCACHE_COVERAGER |
|---|
| 3465 | xc_coverager_init(module_number TSRMLS_CC); |
|---|
| 3466 | #endif |
|---|
| 3467 | |
|---|
| 3468 | return SUCCESS; |
|---|
| 3469 | |
|---|
| 3470 | err_init: |
|---|
| 3471 | return FAILURE; |
|---|
| 3472 | } |
|---|
| 3473 | /* }}} */ |
|---|
| 3474 | /* {{{ PHP_MSHUTDOWN_FUNCTION(xcache) */ |
|---|
| 3475 | static PHP_MSHUTDOWN_FUNCTION(xcache) |
|---|
| 3476 | { |
|---|
| 3477 | if (xc_initized) { |
|---|
| 3478 | xc_destroy(); |
|---|
| 3479 | } |
|---|
| 3480 | if (xc_mmap_path) { |
|---|
| 3481 | pefree(xc_mmap_path, 1); |
|---|
| 3482 | xc_mmap_path = NULL; |
|---|
| 3483 | } |
|---|
| 3484 | if (xc_shm_scheme) { |
|---|
| 3485 | pefree(xc_shm_scheme, 1); |
|---|
| 3486 | xc_shm_scheme = NULL; |
|---|
| 3487 | } |
|---|
| 3488 | |
|---|
| 3489 | #ifdef HAVE_XCACHE_COVERAGER |
|---|
| 3490 | xc_coverager_destroy(); |
|---|
| 3491 | #endif |
|---|
| 3492 | |
|---|
| 3493 | if (xc_coredump_dir && xc_coredump_dir[0]) { |
|---|
| 3494 | xcache_restore_signal_handler(); |
|---|
| 3495 | } |
|---|
| 3496 | if (xc_coredump_dir) { |
|---|
| 3497 | pefree(xc_coredump_dir, 1); |
|---|
| 3498 | xc_coredump_dir = NULL; |
|---|
| 3499 | } |
|---|
| 3500 | #ifndef PHP_GINIT |
|---|
| 3501 | # ifdef ZTS |
|---|
| 3502 | ts_free_id(xcache_globals_id); |
|---|
| 3503 | # else |
|---|
| 3504 | xc_shutdown_globals(&xcache_globals TSRMLS_CC); |
|---|
| 3505 | # endif |
|---|
| 3506 | #endif |
|---|
| 3507 | |
|---|
| 3508 | if (xc_zend_extension_faked) { |
|---|
| 3509 | zend_extension *ext = zend_get_extension(XCACHE_NAME); |
|---|
| 3510 | if (ext->shutdown) { |
|---|
| 3511 | ext->shutdown(ext); |
|---|
| 3512 | } |
|---|
| 3513 | xc_zend_remove_extension(ext); |
|---|
| 3514 | } |
|---|
| 3515 | UNREGISTER_INI_ENTRIES(); |
|---|
| 3516 | |
|---|
| 3517 | xc_module_gotup = 0; |
|---|
| 3518 | xc_zend_extension_gotup = 0; |
|---|
| 3519 | xc_zend_extension_faked = 0; |
|---|
| 3520 | |
|---|
| 3521 | return SUCCESS; |
|---|
| 3522 | } |
|---|
| 3523 | /* }}} */ |
|---|
| 3524 | /* {{{ PHP_RINIT_FUNCTION(xcache) */ |
|---|
| 3525 | static PHP_RINIT_FUNCTION(xcache) |
|---|
| 3526 | { |
|---|
| 3527 | xc_request_init(TSRMLS_C); |
|---|
| 3528 | return SUCCESS; |
|---|
| 3529 | } |
|---|
| 3530 | /* }}} */ |
|---|
| 3531 | /* {{{ PHP_RSHUTDOWN_FUNCTION(xcache) */ |
|---|
| 3532 | #ifndef ZEND_ENGINE_2 |
|---|
| 3533 | static PHP_RSHUTDOWN_FUNCTION(xcache) |
|---|
| 3534 | #else |
|---|
| 3535 | static ZEND_MODULE_POST_ZEND_DEACTIVATE_D(xcache) |
|---|
| 3536 | #endif |
|---|
| 3537 | { |
|---|
| 3538 | #ifdef ZEND_ENGINE_2 |
|---|
| 3539 | TSRMLS_FETCH(); |
|---|
| 3540 | #endif |
|---|
| 3541 | |
|---|
| 3542 | xc_request_shutdown(TSRMLS_C); |
|---|
| 3543 | return SUCCESS; |
|---|
| 3544 | } |
|---|
| 3545 | /* }}} */ |
|---|
| 3546 | /* {{{ module dependencies */ |
|---|
| 3547 | #if ZEND_MODULE_API_NO >= 20050922 |
|---|
| 3548 | static const zend_module_dep xcache_module_deps[] = { |
|---|
| 3549 | ZEND_MOD_REQUIRED("standard") |
|---|
| 3550 | ZEND_MOD_CONFLICTS("apc") |
|---|
| 3551 | ZEND_MOD_CONFLICTS("eAccelerator") |
|---|
| 3552 | ZEND_MOD_CONFLICTS("Turck MMCache") |
|---|
| 3553 | {NULL, NULL, NULL} |
|---|
| 3554 | }; |
|---|
| 3555 | #endif |
|---|
| 3556 | /* }}} */ |
|---|
| 3557 | /* {{{ module definition structure */ |
|---|
| 3558 | |
|---|
| 3559 | zend_module_entry xcache_module_entry = { |
|---|
| 3560 | #if ZEND_MODULE_API_NO >= 20050922 |
|---|
| 3561 | STANDARD_MODULE_HEADER_EX, |
|---|
| 3562 | NULL, |
|---|
| 3563 | xcache_module_deps, |
|---|
| 3564 | #else |
|---|
| 3565 | STANDARD_MODULE_HEADER, |
|---|
| 3566 | #endif |
|---|
| 3567 | XCACHE_NAME, |
|---|
| 3568 | xcache_functions, |
|---|
| 3569 | PHP_MINIT(xcache), |
|---|
| 3570 | PHP_MSHUTDOWN(xcache), |
|---|
| 3571 | PHP_RINIT(xcache), |
|---|
| 3572 | #ifndef ZEND_ENGINE_2 |
|---|
| 3573 | PHP_RSHUTDOWN(xcache), |
|---|
| 3574 | #else |
|---|
| 3575 | NULL, |
|---|
| 3576 | #endif |
|---|
| 3577 | PHP_MINFO(xcache), |
|---|
| 3578 | XCACHE_VERSION, |
|---|
| 3579 | #ifdef PHP_GINIT |
|---|
| 3580 | PHP_MODULE_GLOBALS(xcache), |
|---|
| 3581 | PHP_GINIT(xcache), |
|---|
| 3582 | PHP_GSHUTDOWN(xcache), |
|---|
| 3583 | #endif |
|---|
| 3584 | #ifdef ZEND_ENGINE_2 |
|---|
| 3585 | ZEND_MODULE_POST_ZEND_DEACTIVATE_N(xcache), |
|---|
| 3586 | #else |
|---|
| 3587 | NULL, |
|---|
| 3588 | NULL, |
|---|
| 3589 | #endif |
|---|
| 3590 | STANDARD_MODULE_PROPERTIES_EX |
|---|
| 3591 | }; |
|---|
| 3592 | |
|---|
| 3593 | #ifdef COMPILE_DL_XCACHE |
|---|
| 3594 | ZEND_GET_MODULE(xcache) |
|---|
| 3595 | #endif |
|---|
| 3596 | /* }}} */ |
|---|
| 3597 | static startup_func_t xc_last_ext_startup; |
|---|
| 3598 | static int xc_zend_startup_last(zend_extension *extension) /* {{{ */ |
|---|
| 3599 | { |
|---|
| 3600 | /* restore */ |
|---|
| 3601 | extension->startup = xc_last_ext_startup; |
|---|
| 3602 | if (extension->startup) { |
|---|
| 3603 | if (extension->startup(extension) != SUCCESS) { |
|---|
| 3604 | return FAILURE; |
|---|
| 3605 | } |
|---|
| 3606 | } |
|---|
| 3607 | assert(xc_llist_zend_extension); |
|---|
| 3608 | xc_llist_prepend(&zend_extensions, xc_llist_zend_extension); |
|---|
| 3609 | if (!xc_module_gotup) { |
|---|
| 3610 | return zend_startup_module(&xcache_module_entry); |
|---|
| 3611 | } |
|---|
| 3612 | return SUCCESS; |
|---|
| 3613 | } |
|---|
| 3614 | /* }}} */ |
|---|
| 3615 | ZEND_DLEXPORT int xcache_zend_startup(zend_extension *extension) /* {{{ */ |
|---|
| 3616 | { |
|---|
| 3617 | xc_zend_extension_gotup = 1; |
|---|
| 3618 | |
|---|
| 3619 | if (!origin_compile_file) { |
|---|
| 3620 | origin_compile_file = zend_compile_file; |
|---|
| 3621 | zend_compile_file = xc_check_initial_compile_file; |
|---|
| 3622 | } |
|---|
| 3623 | |
|---|
| 3624 | if (zend_llist_count(&zend_extensions) > 1) { |
|---|
| 3625 | zend_llist_position lpos; |
|---|
| 3626 | zend_extension *ext; |
|---|
| 3627 | |
|---|
| 3628 | xc_llist_zend_extension = xc_llist_get_element_by_zend_extension(&zend_extensions, XCACHE_NAME); |
|---|
| 3629 | xc_llist_unlink(&zend_extensions, xc_llist_zend_extension); |
|---|
| 3630 | |
|---|
| 3631 | ext = (zend_extension *) zend_llist_get_last_ex(&zend_extensions, &lpos); |
|---|
| 3632 | assert(ext && ext != (zend_extension *) xc_llist_zend_extension->data); |
|---|
| 3633 | xc_last_ext_startup = ext->startup; |
|---|
| 3634 | ext->startup = xc_zend_startup_last; |
|---|
| 3635 | } |
|---|
| 3636 | else if (!xc_module_gotup) { |
|---|
| 3637 | return zend_startup_module(&xcache_module_entry); |
|---|
| 3638 | } |
|---|
| 3639 | return SUCCESS; |
|---|
| 3640 | } |
|---|
| 3641 | /* }}} */ |
|---|
| 3642 | ZEND_DLEXPORT void xcache_zend_shutdown(zend_extension *extension) /* {{{ */ |
|---|
| 3643 | { |
|---|
| 3644 | /* empty */ |
|---|
| 3645 | } |
|---|
| 3646 | /* }}} */ |
|---|
| 3647 | ZEND_DLEXPORT void xcache_statement_handler(zend_op_array *op_array) /* {{{ */ |
|---|
| 3648 | { |
|---|
| 3649 | #ifdef HAVE_XCACHE_COVERAGER |
|---|
| 3650 | xc_coverager_handle_ext_stmt(op_array, ZEND_EXT_STMT); |
|---|
| 3651 | #endif |
|---|
| 3652 | } |
|---|
| 3653 | /* }}} */ |
|---|
| 3654 | ZEND_DLEXPORT void xcache_fcall_begin_handler(zend_op_array *op_array) /* {{{ */ |
|---|
| 3655 | { |
|---|
| 3656 | #if 0 |
|---|
| 3657 | xc_coverager_handle_ext_stmt(op_array, ZEND_EXT_FCALL_BEGIN); |
|---|
| 3658 | #endif |
|---|
| 3659 | } |
|---|
| 3660 | /* }}} */ |
|---|
| 3661 | ZEND_DLEXPORT void xcache_fcall_end_handler(zend_op_array *op_array) /* {{{ */ |
|---|
| 3662 | { |
|---|
| 3663 | #if 0 |
|---|
| 3664 | xc_coverager_handle_ext_stmt(op_array, ZEND_EXT_FCALL_END); |
|---|
| 3665 | #endif |
|---|
| 3666 | } |
|---|
| 3667 | /* }}} */ |
|---|
| 3668 | /* {{{ zend extension definition structure */ |
|---|
| 3669 | ZEND_DLEXPORT zend_extension zend_extension_entry = { |
|---|
| 3670 | XCACHE_NAME, |
|---|
| 3671 | XCACHE_VERSION, |
|---|
| 3672 | XCACHE_AUTHOR, |
|---|
| 3673 | XCACHE_URL, |
|---|
| 3674 | XCACHE_COPYRIGHT, |
|---|
| 3675 | xcache_zend_startup, |
|---|
| 3676 | xcache_zend_shutdown, |
|---|
| 3677 | NULL, /* activate_func_t */ |
|---|
| 3678 | NULL, /* deactivate_func_t */ |
|---|
| 3679 | NULL, /* message_handler_func_t */ |
|---|
| 3680 | #ifdef HAVE_XCACHE_OPTIMIZER |
|---|
| 3681 | xc_optimizer_op_array_handler, |
|---|
| 3682 | #else |
|---|
| 3683 | NULL, /* op_array_handler_func_t */ |
|---|
| 3684 | #endif |
|---|
| 3685 | xcache_statement_handler, |
|---|
| 3686 | xcache_fcall_begin_handler, |
|---|
| 3687 | xcache_fcall_end_handler, |
|---|
| 3688 | NULL, /* op_array_ctor_func_t */ |
|---|
| 3689 | NULL, /* op_array_dtor_func_t */ |
|---|
| 3690 | STANDARD_ZEND_EXTENSION_PROPERTIES |
|---|
| 3691 | }; |
|---|
| 3692 | |
|---|
| 3693 | #ifndef ZEND_EXT_API |
|---|
| 3694 | # define ZEND_EXT_API ZEND_DLEXPORT |
|---|
| 3695 | #endif |
|---|
| 3696 | #if COMPILE_DL_XCACHE |
|---|
| 3697 | ZEND_EXTENSION(); |
|---|
| 3698 | #endif |
|---|
| 3699 | /* }}} */ |
|---|