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