[1] | 1 | |
---|
| 2 | #undef DEBUG |
---|
| 3 | |
---|
| 4 | /* {{{ macros */ |
---|
| 5 | #include <stdlib.h> |
---|
| 6 | #include <stdio.h> |
---|
| 7 | #include <string.h> |
---|
| 8 | |
---|
| 9 | #include <signal.h> |
---|
| 10 | |
---|
| 11 | #include "php.h" |
---|
| 12 | #include "ext/standard/info.h" |
---|
[34] | 13 | #include "ext/standard/md5.h" |
---|
[82] | 14 | #include "ext/standard/php_math.h" |
---|
[1] | 15 | #include "zend_extensions.h" |
---|
| 16 | #include "SAPI.h" |
---|
| 17 | |
---|
| 18 | #include "xcache.h" |
---|
| 19 | #include "optimizer.h" |
---|
[27] | 20 | #include "coverager.h" |
---|
[1] | 21 | #include "disassembler.h" |
---|
| 22 | #include "align.h" |
---|
| 23 | #include "stack.h" |
---|
| 24 | #include "xcache_globals.h" |
---|
| 25 | #include "processor.h" |
---|
| 26 | #include "utils.h" |
---|
| 27 | #include "const_string.h" |
---|
| 28 | #include "opcode_spec.h" |
---|
| 29 | |
---|
| 30 | #ifdef DEBUG |
---|
[18] | 31 | # undef NDEBUG |
---|
[1] | 32 | # undef inline |
---|
| 33 | # define inline |
---|
| 34 | #else |
---|
[18] | 35 | # ifndef NDEBUG |
---|
| 36 | # define NDEBUG |
---|
| 37 | # endif |
---|
[1] | 38 | #endif |
---|
| 39 | #include <assert.h> |
---|
| 40 | |
---|
| 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 | #define ENTER_LOCK(x) do { \ |
---|
| 45 | int catched = 0; \ |
---|
| 46 | xc_lock(x->lck); \ |
---|
| 47 | zend_try { \ |
---|
| 48 | do |
---|
| 49 | #define LEAVE_LOCK(x) \ |
---|
| 50 | while (0); \ |
---|
| 51 | } zend_catch { \ |
---|
| 52 | catched = 1; \ |
---|
| 53 | } zend_end_try(); \ |
---|
| 54 | xc_unlock(x->lck); \ |
---|
| 55 | } while(0) |
---|
| 56 | /* }}} */ |
---|
| 57 | |
---|
| 58 | /* {{{ globals */ |
---|
| 59 | static char *xc_mmap_path = NULL; |
---|
| 60 | static char *xc_coredump_dir = NULL; |
---|
| 61 | |
---|
| 62 | static xc_hash_t xc_php_hcache = {0}; |
---|
| 63 | static xc_hash_t xc_php_hentry = {0}; |
---|
| 64 | static xc_hash_t xc_var_hcache = {0}; |
---|
| 65 | static xc_hash_t xc_var_hentry = {0}; |
---|
| 66 | |
---|
| 67 | /* total size */ |
---|
| 68 | static zend_ulong xc_php_size = 0; |
---|
| 69 | static zend_ulong xc_var_size = 0; |
---|
| 70 | |
---|
| 71 | static xc_cache_t **xc_php_caches = NULL; |
---|
| 72 | static xc_cache_t **xc_var_caches = NULL; |
---|
| 73 | |
---|
| 74 | static zend_bool xc_initized = 0; |
---|
| 75 | static zend_compile_file_t *origin_compile_file; |
---|
| 76 | |
---|
| 77 | static zend_bool xc_test = 0; |
---|
| 78 | static zend_bool xc_readonly_protection = 0; |
---|
| 79 | |
---|
| 80 | static zend_bool xc_module_gotup = 0; |
---|
| 81 | static zend_bool xc_zend_extension_gotup = 0; |
---|
| 82 | #if !COMPILE_DL_XCACHE |
---|
| 83 | # define zend_extension_entry xcache_zend_extension_entry |
---|
| 84 | #endif |
---|
| 85 | ZEND_DLEXPORT zend_extension zend_extension_entry; |
---|
| 86 | ZEND_DECLARE_MODULE_GLOBALS(xcache); |
---|
| 87 | /* }}} */ |
---|
| 88 | |
---|
| 89 | /* any function in *_dmz is only safe be called within locked(single thread) area */ |
---|
| 90 | |
---|
| 91 | static inline int xc_entry_equal_dmz(xc_entry_t *a, xc_entry_t *b) /* {{{ */ |
---|
| 92 | { |
---|
| 93 | /* this function isn't required but can be in dmz */ |
---|
| 94 | |
---|
| 95 | if (a->type != b->type) { |
---|
| 96 | return 0; |
---|
| 97 | } |
---|
| 98 | switch (a->type) { |
---|
| 99 | case XC_TYPE_PHP: |
---|
| 100 | #ifdef HAVE_INODE |
---|
| 101 | do { |
---|
| 102 | xc_entry_data_php_t *ap = a->data.php; |
---|
| 103 | xc_entry_data_php_t *bp = b->data.php; |
---|
| 104 | return ap->inode == bp->inode |
---|
| 105 | && ap->device == bp->device; |
---|
| 106 | } while(0); |
---|
| 107 | #endif |
---|
| 108 | /* fall */ |
---|
| 109 | |
---|
| 110 | case XC_TYPE_VAR: |
---|
| 111 | do { |
---|
| 112 | #ifdef IS_UNICODE |
---|
| 113 | if (a->name_type == IS_UNICODE) { |
---|
| 114 | if (a->name.ustr.len != b->name.ustr.len) { |
---|
| 115 | return 0; |
---|
| 116 | } |
---|
| 117 | return memcmp(a->name.ustr.val, b->name.ustr.val, (a->name.ustr.len + 1) * sizeof(UChar)) == 0; |
---|
| 118 | } |
---|
| 119 | else { |
---|
| 120 | return memcmp(a->name.str.val, b->name.str.val, a->name.str.len + 1) == 0; |
---|
| 121 | } |
---|
| 122 | #else |
---|
| 123 | return memcmp(a->name.str.val, b->name.str.val, a->name.str.len + 1) == 0; |
---|
| 124 | #endif |
---|
| 125 | |
---|
| 126 | } while(0); |
---|
| 127 | default: |
---|
| 128 | assert(0); |
---|
| 129 | } |
---|
| 130 | return 0; |
---|
| 131 | } |
---|
| 132 | /* }}} */ |
---|
| 133 | static void xc_entry_free_dmz(volatile xc_entry_t *xce) /* {{{ */ |
---|
| 134 | { |
---|
| 135 | xc_mem_free(xce->cache->mem, (xc_entry_t *)xce); |
---|
| 136 | } |
---|
| 137 | /* }}} */ |
---|
| 138 | static void xc_entry_add_dmz(xc_entry_t *xce) /* {{{ */ |
---|
| 139 | { |
---|
| 140 | xc_entry_t **head = &(xce->cache->entries[xce->hvalue]); |
---|
| 141 | xce->next = *head; |
---|
| 142 | *head = xce; |
---|
[32] | 143 | xce->cache->entries_count ++; |
---|
[1] | 144 | } |
---|
| 145 | /* }}} */ |
---|
| 146 | static xc_entry_t *xc_entry_store_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */ |
---|
| 147 | { |
---|
| 148 | xc_entry_t *stored_xce; |
---|
| 149 | |
---|
| 150 | xce->hits = 0; |
---|
| 151 | xce->ctime = XG(request_time); |
---|
| 152 | xce->atime = XG(request_time); |
---|
| 153 | stored_xce = xc_processor_store_xc_entry_t(xce TSRMLS_CC); |
---|
| 154 | if (stored_xce) { |
---|
| 155 | xc_entry_add_dmz(stored_xce); |
---|
| 156 | return stored_xce; |
---|
| 157 | } |
---|
| 158 | else { |
---|
| 159 | xce->cache->ooms ++; |
---|
| 160 | return NULL; |
---|
| 161 | } |
---|
| 162 | } |
---|
| 163 | /* }}} */ |
---|
| 164 | static void xc_entry_remove_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */ |
---|
| 165 | { |
---|
| 166 | xc_entry_t **last = &(xce->cache->entries[xce->hvalue]); |
---|
| 167 | xc_entry_t *p; |
---|
| 168 | for (p = *last; p; last = &(p->next), p = p->next) { |
---|
| 169 | if (xc_entry_equal_dmz(xce, p)) { |
---|
| 170 | *last = p->next; |
---|
[32] | 171 | xce->cache->entries_count ++; |
---|
[1] | 172 | if (p->refcount == 0) { |
---|
| 173 | xc_entry_free_dmz(p); |
---|
| 174 | } |
---|
| 175 | else { |
---|
| 176 | p->next = p->cache->deletes; |
---|
| 177 | p->cache->deletes = p; |
---|
| 178 | p->dtime = XG(request_time); |
---|
[32] | 179 | xce->cache->deletes_count ++; |
---|
[1] | 180 | } |
---|
| 181 | return; |
---|
| 182 | } |
---|
| 183 | } |
---|
| 184 | assert(0); |
---|
| 185 | } |
---|
| 186 | /* }}} */ |
---|
| 187 | static xc_entry_t *xc_entry_find_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */ |
---|
| 188 | { |
---|
| 189 | xc_entry_t *p; |
---|
| 190 | for (p = xce->cache->entries[xce->hvalue]; p; p = p->next) { |
---|
| 191 | if (xc_entry_equal_dmz(xce, p)) { |
---|
| 192 | if (p->type == XC_TYPE_VAR || /* PHP */ p->data.php->mtime == xce->data.php->mtime) { |
---|
| 193 | p->hits ++; |
---|
| 194 | p->atime = XG(request_time); |
---|
| 195 | return p; |
---|
| 196 | } |
---|
| 197 | else { |
---|
| 198 | xc_entry_remove_dmz(p TSRMLS_CC); |
---|
| 199 | return NULL; |
---|
| 200 | } |
---|
| 201 | } |
---|
| 202 | } |
---|
| 203 | return NULL; |
---|
| 204 | } |
---|
| 205 | /* }}} */ |
---|
| 206 | static void xc_entry_hold_php_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */ |
---|
| 207 | { |
---|
| 208 | xce->refcount ++; |
---|
| 209 | xc_stack_push(&XG(php_holds)[xce->cache->cacheid], (void *)xce); |
---|
| 210 | } |
---|
| 211 | /* }}} */ |
---|
| 212 | #if 0 |
---|
| 213 | static void xc_entry_hold_var_dmz(xc_entry_t *xce TSRMLS_DC) /* {{{ */ |
---|
| 214 | { |
---|
| 215 | xce->refcount ++; |
---|
| 216 | xc_stack_push(&XG(var_holds)[xce->cache->cacheid], (void *)xce); |
---|
| 217 | } |
---|
| 218 | /* }}} */ |
---|
| 219 | #endif |
---|
| 220 | |
---|
| 221 | /* helper functions for user functions */ |
---|
| 222 | static void xc_fillinfo_dmz(xc_cache_t *cache, zval *return_value TSRMLS_DC) /* {{{ */ |
---|
| 223 | { |
---|
| 224 | zval *blocks; |
---|
| 225 | const xc_block_t *b; |
---|
| 226 | #ifndef NDEBUG |
---|
| 227 | xc_memsize_t avail = 0; |
---|
| 228 | #endif |
---|
| 229 | xc_mem_t *mem = cache->mem; |
---|
| 230 | |
---|
| 231 | add_assoc_long_ex(return_value, ZEND_STRS("slots"), cache->hentry->size); |
---|
| 232 | add_assoc_long_ex(return_value, ZEND_STRS("compiling"), cache->compiling); |
---|
| 233 | add_assoc_long_ex(return_value, ZEND_STRS("misses"), cache->misses); |
---|
| 234 | add_assoc_long_ex(return_value, ZEND_STRS("hits"), cache->hits); |
---|
| 235 | add_assoc_long_ex(return_value, ZEND_STRS("clogs"), cache->clogs); |
---|
| 236 | add_assoc_long_ex(return_value, ZEND_STRS("ooms"), cache->ooms); |
---|
| 237 | |
---|
[32] | 238 | add_assoc_long_ex(return_value, ZEND_STRS("cached"), cache->entries_count); |
---|
| 239 | add_assoc_long_ex(return_value, ZEND_STRS("deleted"), cache->deletes_count); |
---|
[1] | 240 | |
---|
| 241 | MAKE_STD_ZVAL(blocks); |
---|
| 242 | array_init(blocks); |
---|
| 243 | |
---|
| 244 | add_assoc_long_ex(return_value, ZEND_STRS("size"), xc_mem_size(mem)); |
---|
| 245 | add_assoc_long_ex(return_value, ZEND_STRS("avail"), xc_mem_avail(mem)); |
---|
| 246 | add_assoc_bool_ex(return_value, ZEND_STRS("can_readonly"), xc_readonly_protection); |
---|
| 247 | |
---|
| 248 | for (b = xc_mem_freeblock_first(mem); b; b = xc_mem_freeblock_next(b)) { |
---|
| 249 | zval *bi; |
---|
| 250 | |
---|
| 251 | MAKE_STD_ZVAL(bi); |
---|
| 252 | array_init(bi); |
---|
| 253 | |
---|
| 254 | add_assoc_long_ex(bi, ZEND_STRS("size"), xc_mem_block_size(b)); |
---|
| 255 | add_assoc_long_ex(bi, ZEND_STRS("offset"), xc_mem_block_offset(mem, b)); |
---|
| 256 | add_next_index_zval(blocks, bi); |
---|
| 257 | #ifndef NDEBUG |
---|
| 258 | avail += b->size; |
---|
| 259 | #endif |
---|
| 260 | } |
---|
| 261 | add_assoc_zval_ex(return_value, ZEND_STRS("free_blocks"), blocks); |
---|
| 262 | assert(avail == xc_mem_avail(mem)); |
---|
| 263 | } |
---|
| 264 | /* }}} */ |
---|
| 265 | static void xc_fillentry_dmz(xc_entry_t *entry, int del, zval *list TSRMLS_DC) /* {{{ */ |
---|
| 266 | { |
---|
| 267 | zval* ei; |
---|
| 268 | xc_entry_data_php_t *php; |
---|
| 269 | xc_entry_data_var_t *var; |
---|
| 270 | |
---|
| 271 | ALLOC_INIT_ZVAL(ei); |
---|
| 272 | array_init(ei); |
---|
| 273 | |
---|
| 274 | add_assoc_long_ex(ei, ZEND_STRS("size"), entry->size); |
---|
| 275 | add_assoc_long_ex(ei, ZEND_STRS("refcount"), entry->refcount); |
---|
| 276 | add_assoc_long_ex(ei, ZEND_STRS("hits"), entry->hits); |
---|
| 277 | add_assoc_long_ex(ei, ZEND_STRS("ctime"), entry->ctime); |
---|
| 278 | add_assoc_long_ex(ei, ZEND_STRS("atime"), entry->atime); |
---|
| 279 | add_assoc_long_ex(ei, ZEND_STRS("dtime"), entry->dtime); |
---|
| 280 | #ifdef IS_UNICODE |
---|
| 281 | do { |
---|
| 282 | zval *zv; |
---|
| 283 | ALLOC_INIT_ZVAL(zv); |
---|
| 284 | switch (entry->name_type) { |
---|
| 285 | case IS_UNICODE: |
---|
| 286 | ZVAL_UNICODEL(zv, entry->name.ustr.val, entry->name.ustr.len, 1); |
---|
| 287 | break; |
---|
| 288 | case IS_STRING: |
---|
| 289 | ZVAL_STRINGL(zv, entry->name.str.val, entry->name.str.len, 1); |
---|
| 290 | break; |
---|
| 291 | default: |
---|
| 292 | assert(0); |
---|
| 293 | } |
---|
| 294 | zv->type = entry->name_type; |
---|
| 295 | add_assoc_zval_ex(ei, ZEND_STRS("name"), zv); |
---|
| 296 | } while (0); |
---|
| 297 | #else |
---|
| 298 | add_assoc_stringl_ex(ei, ZEND_STRS("name"), entry->name.str.val, entry->name.str.len + 1, 1); |
---|
| 299 | #endif |
---|
| 300 | switch (entry->type) { |
---|
| 301 | case XC_TYPE_PHP: |
---|
| 302 | php = entry->data.php; |
---|
| 303 | add_assoc_long_ex(ei, ZEND_STRS("sourcesize"), php->sourcesize); |
---|
| 304 | #ifdef HAVE_INODE |
---|
| 305 | add_assoc_long_ex(ei, ZEND_STRS("device"), php->device); |
---|
| 306 | add_assoc_long_ex(ei, ZEND_STRS("inode"), php->inode); |
---|
| 307 | #endif |
---|
| 308 | add_assoc_long_ex(ei, ZEND_STRS("mtime"), php->mtime); |
---|
| 309 | |
---|
| 310 | add_assoc_long_ex(ei, ZEND_STRS("function_cnt"), php->funcinfo_cnt); |
---|
| 311 | add_assoc_long_ex(ei, ZEND_STRS("class_cnt"), php->classinfo_cnt); |
---|
| 312 | break; |
---|
| 313 | case XC_TYPE_VAR: |
---|
| 314 | var = entry->data.var; |
---|
| 315 | break; |
---|
| 316 | |
---|
| 317 | default: |
---|
| 318 | assert(0); |
---|
| 319 | } |
---|
| 320 | |
---|
| 321 | add_next_index_zval(list, ei); |
---|
| 322 | } |
---|
| 323 | /* }}} */ |
---|
| 324 | static void xc_filllist_dmz(xc_cache_t *cache, zval *return_value TSRMLS_DC) /* {{{ */ |
---|
| 325 | { |
---|
| 326 | zval* list; |
---|
| 327 | int i, c; |
---|
| 328 | xc_entry_t *e; |
---|
| 329 | |
---|
| 330 | ALLOC_INIT_ZVAL(list); |
---|
| 331 | array_init(list); |
---|
| 332 | |
---|
| 333 | for (i = 0, c = cache->hentry->size; i < c; i ++) { |
---|
| 334 | for (e = cache->entries[i]; e; e = e->next) { |
---|
[11] | 335 | xc_fillentry_dmz(e, 0, list TSRMLS_CC); |
---|
[1] | 336 | } |
---|
| 337 | } |
---|
| 338 | add_assoc_zval(return_value, "cache_list", list); |
---|
| 339 | |
---|
| 340 | ALLOC_INIT_ZVAL(list); |
---|
| 341 | array_init(list); |
---|
| 342 | for (e = cache->deletes; e; e = e->next) { |
---|
[11] | 343 | xc_fillentry_dmz(e, 1, list TSRMLS_CC); |
---|
[1] | 344 | } |
---|
| 345 | add_assoc_zval(return_value, "deleted_list", list); |
---|
| 346 | } |
---|
| 347 | /* }}} */ |
---|
| 348 | |
---|
| 349 | static zend_op_array *xc_entry_install(xc_entry_t *xce, zend_file_handle *h TSRMLS_DC) /* {{{ */ |
---|
| 350 | { |
---|
| 351 | zend_uint i; |
---|
| 352 | xc_entry_data_php_t *p = xce->data.php; |
---|
| 353 | #ifndef ZEND_ENGINE_2 |
---|
| 354 | /* new ptr which is stored inside CG(class_table) */ |
---|
| 355 | xc_cest_t **new_cest_ptrs = (xc_cest_t **)do_alloca(sizeof(xc_cest_t*) * p->classinfo_cnt); |
---|
| 356 | #endif |
---|
| 357 | |
---|
| 358 | /* install function */ |
---|
| 359 | for (i = 0; i < p->funcinfo_cnt; i ++) { |
---|
| 360 | xc_funcinfo_t *fi = &p->funcinfos[i]; |
---|
| 361 | xc_install_function(xce->name.str.val, &fi->func, |
---|
| 362 | UNISW(0, fi->type), fi->key, fi->key_size TSRMLS_CC); |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | /* install class */ |
---|
| 366 | for (i = 0; i < p->classinfo_cnt; i ++) { |
---|
| 367 | xc_classinfo_t *ci = &p->classinfos[i]; |
---|
| 368 | #ifndef ZEND_ENGINE_2 |
---|
| 369 | zend_class_entry *ce = CestToCePtr(ci->cest); |
---|
| 370 | /* fix pointer to the be which inside class_table */ |
---|
| 371 | if (ce->parent) { |
---|
| 372 | zend_uint class_idx = (/* class_num */ (int) ce->parent) - 1; |
---|
| 373 | assert(class_idx < i); |
---|
| 374 | ci->cest.parent = new_cest_ptrs[class_idx]; |
---|
| 375 | } |
---|
| 376 | new_cest_ptrs[i] = |
---|
| 377 | #endif |
---|
| 378 | xc_install_class(xce->name.str.val, &ci->cest, |
---|
| 379 | UNISW(0, ci->type), ci->key, ci->key_size TSRMLS_CC); |
---|
| 380 | } |
---|
| 381 | |
---|
| 382 | i = 1; |
---|
| 383 | zend_hash_add(&EG(included_files), xce->name.str.val, xce->name.str.len+1, (void *)&i, sizeof(int), NULL); |
---|
| 384 | zend_llist_add_element(&CG(open_files), h); |
---|
| 385 | |
---|
| 386 | #ifndef ZEND_ENGINE_2 |
---|
| 387 | free_alloca(new_cest_ptrs); |
---|
| 388 | #endif |
---|
| 389 | return p->op_array; |
---|
| 390 | } |
---|
| 391 | /* }}} */ |
---|
| 392 | static void xc_entry_gc_real(xc_cache_t **caches, int size TSRMLS_DC) /* {{{ */ |
---|
| 393 | { |
---|
| 394 | time_t t = XG(request_time); |
---|
| 395 | int i; |
---|
| 396 | xc_cache_t *cache; |
---|
[11] | 397 | typedef xc_entry_t *xc_delete_t; |
---|
| 398 | xc_delete_t p, *last; |
---|
[1] | 399 | |
---|
| 400 | for (i = 0; i < size; i ++) { |
---|
| 401 | cache = caches[i]; |
---|
| 402 | ENTER_LOCK(cache) { |
---|
| 403 | if (cache->deletes) { |
---|
[11] | 404 | last = (xc_delete_t *) &cache->deletes; |
---|
[1] | 405 | for (p = *last; p; p = p->next) { |
---|
| 406 | if (t - p->dtime > 3600) { |
---|
| 407 | p->refcount = 0; |
---|
| 408 | /* issue warning here */ |
---|
| 409 | } |
---|
| 410 | if (p->refcount == 0) { |
---|
| 411 | *last = p->next; |
---|
[32] | 412 | cache->deletes_count --; |
---|
[1] | 413 | xc_entry_free_dmz(p); |
---|
| 414 | } |
---|
| 415 | else { |
---|
| 416 | last = &(p->next); |
---|
| 417 | } |
---|
| 418 | } |
---|
| 419 | } |
---|
| 420 | } LEAVE_LOCK(cache); |
---|
| 421 | } |
---|
| 422 | } |
---|
| 423 | /* }}} */ |
---|
| 424 | static void xc_entry_gc(TSRMLS_D) /* {{{ */ |
---|
| 425 | { |
---|
| 426 | xc_entry_gc_real(xc_php_caches, xc_php_hcache.size TSRMLS_CC); |
---|
| 427 | xc_entry_gc_real(xc_var_caches, xc_var_hcache.size TSRMLS_CC); |
---|
| 428 | } |
---|
| 429 | /* }}} */ |
---|
[11] | 430 | static inline void xc_entry_unholds_real(xc_stack_t *holds, xc_cache_t **caches, int cachecount TSRMLS_DC) /* {{{ */ |
---|
[1] | 431 | { |
---|
| 432 | int i; |
---|
| 433 | xc_stack_t *s; |
---|
| 434 | xc_cache_t *cache; |
---|
| 435 | xc_entry_t *xce; |
---|
| 436 | |
---|
| 437 | for (i = 0; i < cachecount; i ++) { |
---|
| 438 | s = &holds[i]; |
---|
| 439 | if (xc_stack_size(s)) { |
---|
| 440 | cache = ((xc_entry_t *)xc_stack_top(s))->cache; |
---|
| 441 | ENTER_LOCK(cache) { |
---|
| 442 | while (xc_stack_size(holds)) { |
---|
| 443 | xce = (xc_entry_t*) xc_stack_pop(holds); |
---|
| 444 | xce->refcount --; |
---|
| 445 | assert(xce->refcount >= 0); |
---|
| 446 | } |
---|
| 447 | } LEAVE_LOCK(cache); |
---|
| 448 | } |
---|
| 449 | } |
---|
| 450 | } |
---|
| 451 | /* }}} */ |
---|
| 452 | static void xc_entry_unholds(TSRMLS_D) /* {{{ */ |
---|
| 453 | { |
---|
[11] | 454 | xc_entry_unholds_real(XG(php_holds), xc_php_caches, xc_php_hcache.size TSRMLS_CC); |
---|
| 455 | xc_entry_unholds_real(XG(var_holds), xc_var_caches, xc_var_hcache.size TSRMLS_CC); |
---|
[1] | 456 | } |
---|
| 457 | /* }}} */ |
---|
[11] | 458 | static int xc_stat(const char *filename, const char *include_path, struct stat *pbuf TSRMLS_DC) /* {{{ */ |
---|
[1] | 459 | { |
---|
| 460 | char filepath[1024]; |
---|
| 461 | char *paths, *path; |
---|
| 462 | char *tokbuf; |
---|
| 463 | int size = strlen(include_path) + 1; |
---|
| 464 | char tokens[] = { DEFAULT_DIR_SEPARATOR, '\0' }; |
---|
| 465 | |
---|
| 466 | paths = (char *)do_alloca(size); |
---|
| 467 | memcpy(paths, include_path, size); |
---|
| 468 | |
---|
[11] | 469 | for (path = php_strtok_r(paths, tokens, &tokbuf); path; path = php_strtok_r(NULL, tokens, &tokbuf)) { |
---|
[1] | 470 | if (strlen(path) + strlen(filename) + 1 > 1024) { |
---|
| 471 | continue; |
---|
| 472 | } |
---|
| 473 | snprintf(filepath, sizeof(filepath), "%s/%s", path, filename); |
---|
| 474 | if (VCWD_STAT(filepath, pbuf) == 0) { |
---|
| 475 | free_alloca(paths); |
---|
| 476 | return 0; |
---|
| 477 | } |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | free_alloca(paths); |
---|
| 481 | |
---|
| 482 | return 1; |
---|
| 483 | } |
---|
| 484 | /* }}} */ |
---|
| 485 | |
---|
| 486 | #define HASH(i) (i) |
---|
| 487 | #define HASH_USTR_L(t, s, l) HASH(zend_u_inline_hash_func(t, s, (l + 1) * sizeof(UChar))) |
---|
| 488 | #define HASH_STR_L(s, l) HASH(zend_inline_hash_func(s, l + 1)) |
---|
| 489 | #define HASH_STR(s) HASH_STR_L(s, strlen(s) + 1) |
---|
| 490 | #define HASH_NUM(n) HASH(n) |
---|
| 491 | static inline xc_hash_value_t xc_entry_hash_var(xc_entry_t *xce) /* {{{ */ |
---|
| 492 | { |
---|
[19] | 493 | return UNISW(NOTHING, UG(unicode) ? HASH_USTR_L(xce->name_type, (char *)xce->name.ustr.val, xce->name.ustr.len) :) |
---|
[1] | 494 | HASH_STR_L(xce->name.str.val, xce->name.str.len); |
---|
| 495 | } |
---|
| 496 | /* }}} */ |
---|
| 497 | static inline xc_hash_value_t xc_entry_hash_php(xc_entry_t *xce) /* {{{ */ |
---|
| 498 | { |
---|
| 499 | #ifdef HAVE_INODE |
---|
| 500 | return HASH(xce->data.php->device + xce->data.php->inode); |
---|
| 501 | #else |
---|
| 502 | return xc_entry_hash_var(xce); |
---|
| 503 | #endif |
---|
| 504 | } |
---|
| 505 | /* }}} */ |
---|
| 506 | static int xc_entry_init_key_php(xc_entry_t *xce, char *filename TSRMLS_DC) /* {{{ */ |
---|
| 507 | { |
---|
| 508 | struct stat buf, *pbuf; |
---|
| 509 | xc_hash_value_t hv; |
---|
| 510 | int cacheid; |
---|
| 511 | xc_entry_data_php_t *php; |
---|
[75] | 512 | char *ptr; |
---|
[1] | 513 | |
---|
| 514 | if (!filename || !SG(request_info).path_translated) { |
---|
| 515 | return 0; |
---|
| 516 | } |
---|
| 517 | |
---|
| 518 | do { |
---|
| 519 | if (strcmp(SG(request_info).path_translated, filename) == 0) { |
---|
| 520 | /* sapi has already done this stat() for us */ |
---|
| 521 | pbuf = sapi_get_stat(TSRMLS_C); |
---|
| 522 | if (pbuf) { |
---|
| 523 | break; |
---|
| 524 | } |
---|
| 525 | } |
---|
| 526 | |
---|
[75] | 527 | /* absolute path */ |
---|
[1] | 528 | pbuf = &buf; |
---|
| 529 | if (IS_ABSOLUTE_PATH(filename, strlen(filename))) { |
---|
| 530 | if (VCWD_STAT(filename, pbuf) != 0) { |
---|
| 531 | return 0; |
---|
| 532 | } |
---|
[75] | 533 | break; |
---|
[1] | 534 | } |
---|
[75] | 535 | |
---|
| 536 | /* relative path */ |
---|
| 537 | if (*filename == '.' && (IS_SLASH(filename[1]) || filename[1] == '.')) { |
---|
| 538 | ptr = filename + 1; |
---|
| 539 | if (*ptr == '.') { |
---|
| 540 | while (*(++ptr) == '.'); |
---|
| 541 | if (!IS_SLASH(*ptr)) { |
---|
| 542 | goto not_relative_path; |
---|
| 543 | } |
---|
| 544 | } |
---|
| 545 | |
---|
| 546 | if (VCWD_STAT(filename, pbuf) != 0) { |
---|
[1] | 547 | return 0; |
---|
| 548 | } |
---|
[75] | 549 | break; |
---|
[1] | 550 | } |
---|
[75] | 551 | not_relative_path: |
---|
| 552 | |
---|
| 553 | /* use include_path */ |
---|
| 554 | if (xc_stat(filename, PG(include_path), pbuf TSRMLS_CC) != 0) { |
---|
| 555 | return 0; |
---|
| 556 | } |
---|
[1] | 557 | } while (0); |
---|
| 558 | |
---|
| 559 | if (XG(request_time) - pbuf->st_mtime < 2) { |
---|
| 560 | return 0; |
---|
| 561 | } |
---|
| 562 | |
---|
[19] | 563 | UNISW(NOTHING, xce->name_type = IS_STRING;) |
---|
[1] | 564 | xce->name.str.val = filename; |
---|
| 565 | xce->name.str.len = strlen(filename); |
---|
| 566 | |
---|
| 567 | php = xce->data.php; |
---|
| 568 | php->mtime = pbuf->st_mtime; |
---|
| 569 | #ifdef HAVE_INODE |
---|
| 570 | php->device = pbuf->st_dev; |
---|
| 571 | php->inode = pbuf->st_ino; |
---|
| 572 | #endif |
---|
| 573 | php->sourcesize = pbuf->st_size; |
---|
| 574 | |
---|
| 575 | |
---|
| 576 | hv = xc_entry_hash_php(xce); |
---|
| 577 | cacheid = (hv & xc_php_hcache.mask); |
---|
| 578 | xce->cache = xc_php_caches[cacheid]; |
---|
| 579 | hv >>= xc_php_hcache.bits; |
---|
| 580 | xce->hvalue = (hv & xc_php_hentry.mask); |
---|
| 581 | |
---|
| 582 | xce->type = XC_TYPE_PHP; |
---|
| 583 | return 1; |
---|
| 584 | } |
---|
| 585 | /* }}} */ |
---|
| 586 | static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) /* {{{ */ |
---|
| 587 | { |
---|
| 588 | xc_sandbox_t sandbox; |
---|
| 589 | zend_op_array *op_array; |
---|
| 590 | xc_entry_t xce, *stored_xce; |
---|
| 591 | xc_entry_data_php_t php; |
---|
| 592 | xc_cache_t *cache; |
---|
| 593 | zend_bool clogged = 0; |
---|
| 594 | zend_bool catched = 0; |
---|
| 595 | char *filename; |
---|
| 596 | |
---|
| 597 | if (!xc_initized) { |
---|
| 598 | assert(0); |
---|
| 599 | } |
---|
| 600 | |
---|
| 601 | if (!XG(cacher)) { |
---|
| 602 | op_array = origin_compile_file(h, type TSRMLS_CC); |
---|
| 603 | #ifdef HAVE_XCACHE_OPTIMIZER |
---|
| 604 | if (XG(optimizer)) { |
---|
| 605 | xc_optimize(op_array TSRMLS_CC); |
---|
| 606 | } |
---|
| 607 | #endif |
---|
| 608 | return op_array; |
---|
| 609 | } |
---|
| 610 | |
---|
| 611 | /* {{{ prepare key |
---|
| 612 | * include_once() and require_once() gives us opened_path |
---|
| 613 | * however, include() and require() non-absolute path which break |
---|
| 614 | * included_files, and may confuse with (include|require)_once |
---|
| 615 | * -- Xuefer |
---|
| 616 | */ |
---|
| 617 | |
---|
| 618 | filename = h->opened_path ? h->opened_path : h->filename; |
---|
| 619 | xce.data.php = &php; |
---|
| 620 | if (!xc_entry_init_key_php(&xce, filename TSRMLS_CC)) { |
---|
| 621 | return origin_compile_file(h, type TSRMLS_CC); |
---|
| 622 | } |
---|
| 623 | cache = xce.cache; |
---|
| 624 | /* }}} */ |
---|
| 625 | /* {{{ restore */ |
---|
| 626 | /* stale precheck */ |
---|
| 627 | if (cache->compiling) { |
---|
| 628 | cache->clogs ++; /* is it safe here? */ |
---|
| 629 | return origin_compile_file(h, type TSRMLS_CC); |
---|
| 630 | } |
---|
| 631 | |
---|
| 632 | stored_xce = NULL; |
---|
| 633 | op_array = NULL; |
---|
| 634 | ENTER_LOCK(cache) { |
---|
| 635 | /* clogged */ |
---|
| 636 | if (cache->compiling) { |
---|
| 637 | cache->clogs ++; |
---|
| 638 | op_array = NULL; |
---|
| 639 | clogged = 1; |
---|
| 640 | break; |
---|
| 641 | } |
---|
| 642 | |
---|
| 643 | stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC); |
---|
| 644 | /* found */ |
---|
| 645 | if (stored_xce) { |
---|
| 646 | #ifdef DEBUG |
---|
| 647 | fprintf(stderr, "found %s, catch it\n", stored_xce->name.str.val); |
---|
| 648 | #endif |
---|
| 649 | xc_entry_hold_php_dmz(stored_xce TSRMLS_CC); |
---|
| 650 | cache->hits ++; |
---|
| 651 | break; |
---|
| 652 | } |
---|
| 653 | |
---|
| 654 | cache->compiling = XG(request_time); |
---|
| 655 | cache->misses ++; |
---|
| 656 | } LEAVE_LOCK(cache); |
---|
| 657 | |
---|
| 658 | /* found */ |
---|
| 659 | if (stored_xce) { |
---|
| 660 | goto restore; |
---|
| 661 | } |
---|
| 662 | |
---|
| 663 | /* clogged */ |
---|
| 664 | if (clogged) { |
---|
| 665 | return origin_compile_file(h, type TSRMLS_CC); |
---|
| 666 | } |
---|
| 667 | /* }}} */ |
---|
| 668 | |
---|
| 669 | /* {{{ compile */ |
---|
| 670 | #ifdef DEBUG |
---|
| 671 | fprintf(stderr, "compiling %s\n", filename); |
---|
| 672 | #endif |
---|
| 673 | |
---|
| 674 | /* make compile inside sandbox */ |
---|
| 675 | xc_sandbox_init(&sandbox, filename TSRMLS_CC); |
---|
| 676 | |
---|
| 677 | zend_try { |
---|
| 678 | op_array = origin_compile_file(h, type TSRMLS_CC); |
---|
| 679 | } zend_catch { |
---|
| 680 | catched = 1; |
---|
| 681 | } zend_end_try(); |
---|
| 682 | |
---|
| 683 | if (catched) { |
---|
| 684 | goto err_bailout; |
---|
| 685 | } |
---|
| 686 | |
---|
| 687 | if (op_array == NULL) { |
---|
| 688 | goto err_oparray; |
---|
| 689 | } |
---|
| 690 | |
---|
[86] | 691 | filename = h->opened_path ? h->opened_path : h->filename; |
---|
| 692 | if (xce.name.str.val != filename) { |
---|
| 693 | xce.name.str.val = filename; |
---|
| 694 | xce.name.str.len = strlen(filename); |
---|
| 695 | } |
---|
| 696 | |
---|
[1] | 697 | #ifdef HAVE_XCACHE_OPTIMIZER |
---|
| 698 | if (XG(optimizer)) { |
---|
| 699 | xc_optimize(op_array TSRMLS_CC); |
---|
| 700 | } |
---|
| 701 | #endif |
---|
| 702 | |
---|
| 703 | php.op_array = op_array; |
---|
| 704 | |
---|
| 705 | php.funcinfo_cnt = zend_hash_num_elements(CG(function_table)); |
---|
| 706 | php.classinfo_cnt = zend_hash_num_elements(CG(class_table)); |
---|
| 707 | |
---|
| 708 | php.funcinfos = ECALLOC_N(php.funcinfos, php.funcinfo_cnt); |
---|
| 709 | if (!php.funcinfos) { |
---|
| 710 | goto err_func; |
---|
| 711 | } |
---|
| 712 | php.classinfos = ECALLOC_N(php.classinfos, php.classinfo_cnt); |
---|
| 713 | if (!php.classinfos) { |
---|
| 714 | goto err_class; |
---|
| 715 | } |
---|
| 716 | /* }}} */ |
---|
| 717 | /* {{{ shallow copy, pointers only */ { |
---|
| 718 | Bucket *b; |
---|
| 719 | unsigned int i; |
---|
| 720 | |
---|
| 721 | b = CG(function_table)->pListHead; |
---|
| 722 | for (i = 0; b; i ++, b = b->pListNext) { |
---|
| 723 | xc_funcinfo_t *fi = &php.funcinfos[i]; |
---|
| 724 | |
---|
| 725 | assert(i < php.funcinfo_cnt); |
---|
| 726 | assert(b->pData); |
---|
| 727 | memcpy(&fi->func, b->pData, sizeof(zend_function)); |
---|
[19] | 728 | UNISW(NOTHING, fi->type = b->key.type;) |
---|
[1] | 729 | fi->key = BUCKET_KEY(b); |
---|
| 730 | fi->key_size = b->nKeyLength; |
---|
| 731 | } |
---|
| 732 | |
---|
| 733 | b = CG(class_table)->pListHead; |
---|
| 734 | for (i = 0; b; i ++, b = b->pListNext) { |
---|
| 735 | xc_classinfo_t *ci = &php.classinfos[i]; |
---|
| 736 | |
---|
| 737 | assert(i < php.classinfo_cnt); |
---|
| 738 | assert(b->pData); |
---|
| 739 | memcpy(&ci->cest, b->pData, sizeof(xc_cest_t)); |
---|
[19] | 740 | UNISW(NOTHING, ci->type = b->key.type;) |
---|
[1] | 741 | ci->key = BUCKET_KEY(b); |
---|
| 742 | ci->key_size = b->nKeyLength; |
---|
| 743 | /* need to fix inside store */ |
---|
| 744 | } |
---|
| 745 | } |
---|
| 746 | /* }}} */ |
---|
| 747 | xc_entry_gc(TSRMLS_C); |
---|
| 748 | ENTER_LOCK(cache) { /* {{{ store/add entry */ |
---|
| 749 | stored_xce = xc_entry_store_dmz(&xce TSRMLS_CC); |
---|
| 750 | } LEAVE_LOCK(cache); |
---|
| 751 | /* }}} */ |
---|
| 752 | #ifdef DEBUG |
---|
| 753 | fprintf(stderr, "stored\n"); |
---|
| 754 | #endif |
---|
| 755 | |
---|
| 756 | efree(xce.data.php->classinfos); |
---|
| 757 | err_class: |
---|
| 758 | efree(xce.data.php->funcinfos); |
---|
| 759 | err_func: |
---|
| 760 | err_oparray: |
---|
| 761 | err_bailout: |
---|
| 762 | |
---|
| 763 | if (xc_test && stored_xce) { |
---|
| 764 | /* no install, keep open_files too for h */ |
---|
| 765 | xc_sandbox_free(&sandbox, 0 TSRMLS_CC); |
---|
| 766 | sandbox.tmp_open_files->dtor = NULL; |
---|
| 767 | } |
---|
| 768 | else { |
---|
| 769 | xc_sandbox_free(&sandbox, 1 TSRMLS_CC); |
---|
| 770 | } |
---|
| 771 | |
---|
| 772 | ENTER_LOCK(cache) { |
---|
| 773 | cache->compiling = 0; |
---|
| 774 | } LEAVE_LOCK(cache); |
---|
| 775 | if (catched) { |
---|
| 776 | zend_bailout(); |
---|
| 777 | } |
---|
| 778 | if (xc_test && stored_xce) { |
---|
| 779 | goto restore; |
---|
| 780 | } |
---|
| 781 | return op_array; |
---|
| 782 | |
---|
| 783 | restore: |
---|
[86] | 784 | if (php_check_open_basedir(stored_xce->name.str.val TSRMLS_CC) != 0) { |
---|
| 785 | return NULL; |
---|
| 786 | } |
---|
| 787 | |
---|
[1] | 788 | #ifdef DEBUG |
---|
| 789 | fprintf(stderr, "restoring\n"); |
---|
| 790 | #endif |
---|
| 791 | xc_processor_restore_xc_entry_t(&xce, stored_xce, xc_readonly_protection TSRMLS_CC); |
---|
| 792 | op_array = xc_entry_install(&xce, h TSRMLS_CC); |
---|
| 793 | |
---|
| 794 | efree(xce.data.php->funcinfos); |
---|
| 795 | efree(xce.data.php->classinfos); |
---|
| 796 | efree(xce.data.php); |
---|
| 797 | #ifdef DEBUG |
---|
| 798 | fprintf(stderr, "restored\n"); |
---|
| 799 | #endif |
---|
| 800 | return op_array; |
---|
| 801 | } |
---|
| 802 | /* }}} */ |
---|
| 803 | |
---|
| 804 | /* gdb helper functions, but N/A for coredump */ |
---|
| 805 | int xc_is_rw(const void *p) /* {{{ */ |
---|
| 806 | { |
---|
| 807 | int i; |
---|
| 808 | if (!xc_initized) { |
---|
| 809 | return 0; |
---|
| 810 | } |
---|
| 811 | for (i = 0; i < xc_php_hcache.size; i ++) { |
---|
| 812 | if (xc_shm_is_readwrite(xc_php_caches[i]->shm, p)) { |
---|
| 813 | return 1; |
---|
| 814 | } |
---|
| 815 | } |
---|
| 816 | for (i = 0; i < xc_var_hcache.size; i ++) { |
---|
| 817 | if (xc_shm_is_readwrite(xc_var_caches[i]->shm, p)) { |
---|
| 818 | return 1; |
---|
| 819 | } |
---|
| 820 | } |
---|
| 821 | return 0; |
---|
| 822 | } |
---|
| 823 | /* }}} */ |
---|
| 824 | int xc_is_ro(const void *p) /* {{{ */ |
---|
| 825 | { |
---|
| 826 | int i; |
---|
| 827 | if (!xc_initized) { |
---|
| 828 | return 0; |
---|
| 829 | } |
---|
| 830 | for (i = 0; i < xc_php_hcache.size; i ++) { |
---|
| 831 | if (xc_shm_is_readonly(xc_php_caches[i]->shm, p)) { |
---|
| 832 | return 1; |
---|
| 833 | } |
---|
| 834 | } |
---|
| 835 | for (i = 0; i < xc_var_hcache.size; i ++) { |
---|
| 836 | if (xc_shm_is_readonly(xc_var_caches[i]->shm, p)) { |
---|
| 837 | return 1; |
---|
| 838 | } |
---|
| 839 | } |
---|
| 840 | return 0; |
---|
| 841 | } |
---|
| 842 | /* }}} */ |
---|
| 843 | int xc_is_shm(const void *p) /* {{{ */ |
---|
| 844 | { |
---|
| 845 | return xc_is_ro(p) || xc_is_rw(p); |
---|
| 846 | } |
---|
| 847 | /* }}} */ |
---|
| 848 | |
---|
| 849 | /* module helper function */ |
---|
| 850 | static int xc_init_constant(int module_number TSRMLS_DC) /* {{{ */ |
---|
| 851 | { |
---|
[11] | 852 | typedef struct { |
---|
[1] | 853 | const char *prefix; |
---|
[20] | 854 | zend_uchar (*getsize)(); |
---|
[1] | 855 | const char *(*get)(zend_uchar i); |
---|
[11] | 856 | } xc_meminfo_t; |
---|
| 857 | xc_meminfo_t nameinfos[] = { |
---|
[1] | 858 | { "", xc_get_op_type_count, xc_get_op_type }, |
---|
| 859 | { "", xc_get_data_type_count, xc_get_data_type }, |
---|
| 860 | { "", xc_get_opcode_count, xc_get_opcode }, |
---|
| 861 | { "OPSPEC_", xc_get_op_spec_count, xc_get_op_spec }, |
---|
| 862 | { NULL, NULL, NULL } |
---|
| 863 | }; |
---|
[11] | 864 | xc_meminfo_t* p; |
---|
[20] | 865 | zend_uchar i, count; |
---|
[1] | 866 | char const_name[96]; |
---|
| 867 | int const_name_len; |
---|
| 868 | int undefdone = 0; |
---|
| 869 | |
---|
| 870 | for (p = nameinfos; p->getsize; p ++) { |
---|
[20] | 871 | count = p->getsize(); |
---|
| 872 | for (i = 0; i < count; i ++) { |
---|
[1] | 873 | const char *name = p->get(i); |
---|
| 874 | if (!name) continue; |
---|
| 875 | if (strcmp(name, "UNDEF") == 0) { |
---|
| 876 | if (undefdone) continue; |
---|
| 877 | undefdone = 1; |
---|
| 878 | } |
---|
| 879 | const_name_len = snprintf(const_name, sizeof(const_name), "XC_%s%s", p->prefix, name); |
---|
| 880 | zend_register_long_constant(const_name, const_name_len+1, i, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); |
---|
| 881 | } |
---|
| 882 | } |
---|
| 883 | |
---|
| 884 | zend_register_long_constant(ZEND_STRS("XC_SIZEOF_TEMP_VARIABLE"), sizeof(temp_variable), CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); |
---|
| 885 | zend_register_long_constant(ZEND_STRS("XC_TYPE_PHP"), XC_TYPE_PHP, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); |
---|
| 886 | zend_register_long_constant(ZEND_STRS("XC_TYPE_VAR"), XC_TYPE_VAR, CONST_CS | CONST_PERSISTENT, module_number TSRMLS_CC); |
---|
| 887 | return 0; |
---|
| 888 | } |
---|
| 889 | /* }}} */ |
---|
[11] | 890 | static xc_shm_t *xc_cache_destroy(xc_cache_t **caches, xc_hash_t *hcache) /* {{{ */ |
---|
[1] | 891 | { |
---|
| 892 | int i; |
---|
| 893 | xc_cache_t *cache; |
---|
| 894 | xc_shm_t *shm; |
---|
| 895 | |
---|
| 896 | if (!caches) { |
---|
| 897 | return NULL; |
---|
| 898 | } |
---|
| 899 | shm = NULL; |
---|
| 900 | for (i = 0; i < hcache->size; i ++) { |
---|
| 901 | cache = caches[i]; |
---|
| 902 | if (cache) { |
---|
| 903 | if (cache->lck) { |
---|
| 904 | xc_lock_destroy(cache->lck); |
---|
| 905 | } |
---|
| 906 | /* do NOT free |
---|
| 907 | if (cache->entries) { |
---|
| 908 | xc_mem_free(cache->mem, cache->entries); |
---|
| 909 | } |
---|
| 910 | xc_mem_free(cache->mem, cache); |
---|
| 911 | */ |
---|
| 912 | xc_mem_destroy(cache->mem); |
---|
| 913 | shm = cache->shm; |
---|
| 914 | } |
---|
| 915 | } |
---|
| 916 | free(caches); |
---|
| 917 | return shm; |
---|
| 918 | } |
---|
| 919 | /* }}} */ |
---|
[11] | 920 | static xc_cache_t **xc_cache_init(xc_shm_t *shm, char *ptr, xc_hash_t *hcache, xc_hash_t *hentry, xc_shmsize_t shmsize) /* {{{ */ |
---|
[1] | 921 | { |
---|
| 922 | xc_cache_t **caches = NULL, *cache; |
---|
| 923 | xc_mem_t *mem; |
---|
| 924 | int i; |
---|
[49] | 925 | xc_memsize_t memsize; |
---|
[11] | 926 | |
---|
[49] | 927 | memsize = shmsize / hcache->size; |
---|
[1] | 928 | |
---|
[49] | 929 | /* Don't let it break out of mem after ALIGNed |
---|
| 930 | * This is important for |
---|
| 931 | * Simply loop until it fit our need |
---|
| 932 | */ |
---|
| 933 | while (ALIGN(memsize) * hcache->size > shmsize && ALIGN(memsize) != memsize) { |
---|
| 934 | if (memsize < ALIGN(1)) { |
---|
| 935 | CHECK(NULL, "cache too small"); |
---|
| 936 | } |
---|
| 937 | memsize --; |
---|
| 938 | } |
---|
| 939 | |
---|
[1] | 940 | CHECK(caches = calloc(hcache->size, sizeof(xc_cache_t *)), "caches OOM"); |
---|
| 941 | |
---|
| 942 | for (i = 0; i < hcache->size; i ++) { |
---|
[49] | 943 | CHECK(mem = xc_mem_init(ptr, memsize), "Failed init memory allocator"); |
---|
| 944 | ptr += memsize; |
---|
[1] | 945 | CHECK(cache = xc_mem_calloc(mem, 1, sizeof(xc_cache_t)), "cache OOM"); |
---|
| 946 | CHECK(cache->entries = xc_mem_calloc(mem, hentry->size, sizeof(xc_entry_t*)), "entries OOM"); |
---|
| 947 | CHECK(cache->lck = xc_lock_init(NULL), "can't create lock"); |
---|
| 948 | |
---|
| 949 | cache->hcache = hcache; |
---|
| 950 | cache->hentry = hentry; |
---|
| 951 | cache->shm = shm; |
---|
| 952 | cache->mem = mem; |
---|
| 953 | cache->cacheid = i; |
---|
| 954 | caches[i] = cache; |
---|
| 955 | } |
---|
| 956 | assert(ptr <= (char*)xc_shm_ptr(shm) + shmsize); |
---|
| 957 | return caches; |
---|
| 958 | |
---|
| 959 | err: |
---|
| 960 | if (caches) { |
---|
| 961 | xc_cache_destroy(caches, hcache); |
---|
| 962 | } |
---|
| 963 | return NULL; |
---|
| 964 | } |
---|
| 965 | /* }}} */ |
---|
| 966 | static void xc_destroy() /* {{{ */ |
---|
| 967 | { |
---|
| 968 | xc_shm_t *shm = NULL; |
---|
| 969 | |
---|
| 970 | if (origin_compile_file) { |
---|
| 971 | zend_compile_file = origin_compile_file; |
---|
| 972 | origin_compile_file = NULL; |
---|
| 973 | } |
---|
| 974 | |
---|
| 975 | if (xc_php_caches) { |
---|
| 976 | shm = xc_cache_destroy(xc_php_caches, &xc_php_hcache); |
---|
| 977 | xc_php_caches = NULL; |
---|
| 978 | } |
---|
| 979 | if (xc_var_caches) { |
---|
| 980 | shm = xc_cache_destroy(xc_var_caches, &xc_var_hcache); |
---|
| 981 | xc_var_caches = NULL; |
---|
| 982 | } |
---|
| 983 | if (shm) { |
---|
| 984 | xc_shm_destroy(shm); |
---|
| 985 | } |
---|
| 986 | } |
---|
| 987 | /* }}} */ |
---|
| 988 | static int xc_init(int module_number TSRMLS_DC) /* {{{ */ |
---|
| 989 | { |
---|
| 990 | xc_shm_t *shm; |
---|
| 991 | char *ptr; |
---|
| 992 | |
---|
[11] | 993 | xc_php_caches = xc_var_caches = NULL; |
---|
| 994 | |
---|
[1] | 995 | if (xc_php_size || xc_var_size) { |
---|
| 996 | CHECK(shm = xc_shm_init(xc_mmap_path, ALIGN(xc_php_size) + ALIGN(xc_var_size), xc_readonly_protection), "Cannot create shm"); |
---|
| 997 | if (!xc_shm_can_readonly(shm)) { |
---|
| 998 | xc_readonly_protection = 0; |
---|
| 999 | } |
---|
| 1000 | |
---|
| 1001 | ptr = (char *)xc_shm_ptr(shm); |
---|
| 1002 | if (xc_php_size) { |
---|
| 1003 | origin_compile_file = zend_compile_file; |
---|
| 1004 | zend_compile_file = xc_compile_file; |
---|
| 1005 | |
---|
| 1006 | CHECK(xc_php_caches = xc_cache_init(shm, ptr, &xc_php_hcache, &xc_php_hentry, xc_php_size), "failed init opcode cache"); |
---|
| 1007 | ptr += ALIGN(xc_php_size); |
---|
| 1008 | } |
---|
| 1009 | |
---|
| 1010 | if (xc_var_size) { |
---|
| 1011 | CHECK(xc_var_caches = xc_cache_init(shm, ptr, &xc_var_hcache, &xc_var_hentry, xc_var_size), "failed init variable cache"); |
---|
| 1012 | } |
---|
| 1013 | } |
---|
| 1014 | return 1; |
---|
| 1015 | |
---|
| 1016 | err: |
---|
| 1017 | if (xc_php_caches || xc_var_caches) { |
---|
| 1018 | xc_destroy(); |
---|
| 1019 | /* shm destroied */ |
---|
| 1020 | } |
---|
| 1021 | else if (shm) { |
---|
| 1022 | xc_shm_destroy(shm); |
---|
| 1023 | } |
---|
| 1024 | return 0; |
---|
| 1025 | } |
---|
| 1026 | /* }}} */ |
---|
| 1027 | static void xc_request_init(TSRMLS_D) /* {{{ */ |
---|
| 1028 | { |
---|
[17] | 1029 | int i; |
---|
| 1030 | |
---|
| 1031 | if (xc_php_hcache.size && !XG(php_holds)) { |
---|
| 1032 | XG(php_holds) = calloc(xc_php_hcache.size, sizeof(xc_stack_t)); |
---|
| 1033 | for (i = 0; i < xc_php_hcache.size; i ++) { |
---|
| 1034 | xc_stack_init(&XG(php_holds[i])); |
---|
| 1035 | } |
---|
| 1036 | } |
---|
| 1037 | |
---|
| 1038 | if (xc_var_hcache.size && !XG(var_holds)) { |
---|
| 1039 | XG(var_holds) = calloc(xc_var_hcache.size, sizeof(xc_stack_t)); |
---|
| 1040 | for (i = 0; i < xc_var_hcache.size; i ++) { |
---|
| 1041 | xc_stack_init(&XG(var_holds[i])); |
---|
| 1042 | } |
---|
| 1043 | } |
---|
| 1044 | |
---|
[1] | 1045 | if (XG(cacher)) { |
---|
| 1046 | #if PHP_API_VERSION <= 20041225 |
---|
| 1047 | XG(request_time) = time(NULL); |
---|
| 1048 | #else |
---|
| 1049 | XG(request_time) = sapi_get_request_time(TSRMLS_C); |
---|
| 1050 | #endif |
---|
| 1051 | } |
---|
[27] | 1052 | #ifdef HAVE_XCACHE_COVERAGER |
---|
| 1053 | xc_coverager_request_init(TSRMLS_C); |
---|
[1] | 1054 | #endif |
---|
| 1055 | } |
---|
| 1056 | /* }}} */ |
---|
| 1057 | static void xc_request_shutdown(TSRMLS_D) /* {{{ */ |
---|
| 1058 | { |
---|
| 1059 | xc_entry_unholds(TSRMLS_C); |
---|
[27] | 1060 | #ifdef HAVE_XCACHE_COVERAGER |
---|
| 1061 | xc_coverager_request_shutdown(TSRMLS_C); |
---|
[1] | 1062 | #endif |
---|
| 1063 | } |
---|
| 1064 | /* }}} */ |
---|
| 1065 | static void xc_init_globals(zend_xcache_globals* xc_globals TSRMLS_DC) /* {{{ */ |
---|
| 1066 | { |
---|
[17] | 1067 | memset(xc_globals, 0, sizeof(zend_xcache_globals)); |
---|
[1] | 1068 | } |
---|
| 1069 | /* }}} */ |
---|
| 1070 | static void xc_shutdown_globals(zend_xcache_globals* xc_globals TSRMLS_DC) /* {{{ */ |
---|
| 1071 | { |
---|
| 1072 | int i; |
---|
| 1073 | |
---|
| 1074 | if (xc_globals->php_holds != NULL) { |
---|
| 1075 | for (i = 0; i < xc_php_hcache.size; i ++) { |
---|
| 1076 | xc_stack_destroy(&xc_globals->php_holds[i]); |
---|
| 1077 | } |
---|
| 1078 | free(xc_globals->php_holds); |
---|
| 1079 | xc_globals->php_holds = NULL; |
---|
| 1080 | } |
---|
| 1081 | |
---|
| 1082 | if (xc_globals->var_holds != NULL) { |
---|
| 1083 | for (i = 0; i < xc_var_hcache.size; i ++) { |
---|
| 1084 | xc_stack_destroy(&xc_globals->var_holds[i]); |
---|
| 1085 | } |
---|
| 1086 | free(xc_globals->var_holds); |
---|
| 1087 | xc_globals->var_holds = NULL; |
---|
| 1088 | } |
---|
| 1089 | } |
---|
| 1090 | /* }}} */ |
---|
| 1091 | |
---|
| 1092 | /* user functions */ |
---|
[55] | 1093 | static int xcache_admin_auth_check(TSRMLS_D) /* {{{ */ |
---|
[34] | 1094 | { |
---|
| 1095 | zval **server = NULL; |
---|
| 1096 | zval **user = NULL; |
---|
| 1097 | zval **pass = NULL; |
---|
| 1098 | char *admin_user = NULL; |
---|
| 1099 | char *admin_pass = NULL; |
---|
| 1100 | HashTable *ht; |
---|
| 1101 | |
---|
| 1102 | if (cfg_get_string("xcache.admin.user", &admin_user) == FAILURE || !admin_user[0]) { |
---|
| 1103 | admin_user = NULL; |
---|
| 1104 | } |
---|
| 1105 | if (cfg_get_string("xcache.admin.pass", &admin_pass) == FAILURE || !admin_pass[0]) { |
---|
| 1106 | admin_pass = NULL; |
---|
| 1107 | } |
---|
| 1108 | |
---|
| 1109 | if (admin_user == NULL || admin_pass == NULL) { |
---|
| 1110 | php_error_docref(NULL TSRMLS_CC, E_ERROR, "xcache.admin.user and xcache.admin.pass is required"); |
---|
| 1111 | zend_bailout(); |
---|
| 1112 | } |
---|
| 1113 | if (strlen(admin_pass) != 32) { |
---|
| 1114 | php_error_docref(NULL TSRMLS_CC, E_ERROR, "unexpect %d bytes of xcache.admin.pass, expected 32 bytes, the password after md5()", strlen(admin_pass)); |
---|
| 1115 | zend_bailout(); |
---|
| 1116 | } |
---|
| 1117 | |
---|
| 1118 | if (zend_hash_find(&EG(symbol_table), "_SERVER", sizeof("_SERVER"), (void **) &server) != SUCCESS || Z_TYPE_PP(server) != IS_ARRAY) { |
---|
| 1119 | php_error_docref(NULL TSRMLS_CC, E_ERROR, "_SERVER is corrupted"); |
---|
| 1120 | zend_bailout(); |
---|
| 1121 | } |
---|
| 1122 | ht = HASH_OF((*server)); |
---|
| 1123 | |
---|
| 1124 | if (zend_hash_find(ht, "PHP_AUTH_USER", sizeof("PHP_AUTH_USER"), (void **) &user) == FAILURE) { |
---|
| 1125 | user = NULL; |
---|
| 1126 | } |
---|
| 1127 | else if (Z_TYPE_PP(user) != IS_STRING) { |
---|
| 1128 | user = NULL; |
---|
| 1129 | } |
---|
| 1130 | |
---|
| 1131 | if (zend_hash_find(ht, "PHP_AUTH_PW", sizeof("PHP_AUTH_PW"), (void **) &pass) == FAILURE) { |
---|
| 1132 | pass = NULL; |
---|
| 1133 | } |
---|
| 1134 | else if (Z_TYPE_PP(pass) != IS_STRING) { |
---|
| 1135 | pass = NULL; |
---|
| 1136 | } |
---|
| 1137 | |
---|
| 1138 | if (user != NULL && pass != NULL && strcmp(admin_user, Z_STRVAL_PP(user)) == 0) { |
---|
| 1139 | PHP_MD5_CTX context; |
---|
| 1140 | char md5str[33]; |
---|
| 1141 | unsigned char digest[16]; |
---|
| 1142 | |
---|
| 1143 | PHP_MD5Init(&context); |
---|
[91] | 1144 | PHP_MD5Update(&context, (unsigned char *) Z_STRVAL_PP(pass), Z_STRLEN_PP(pass)); |
---|
[34] | 1145 | PHP_MD5Final(digest, &context); |
---|
| 1146 | |
---|
| 1147 | md5str[0] = '\0'; |
---|
| 1148 | make_digest(md5str, digest); |
---|
| 1149 | if (strcmp(admin_pass, md5str) == 0) { |
---|
| 1150 | return 1; |
---|
| 1151 | } |
---|
| 1152 | } |
---|
| 1153 | |
---|
| 1154 | #define STR "WWW-authenticate: basic realm='XCache Administration'" |
---|
| 1155 | sapi_add_header_ex(STR, sizeof(STR) - 1, 1, 1 TSRMLS_CC); |
---|
| 1156 | #undef STR |
---|
| 1157 | #define STR "HTTP/1.0 401 Unauthorized" |
---|
| 1158 | sapi_add_header_ex(STR, sizeof(STR) - 1, 1, 1 TSRMLS_CC); |
---|
| 1159 | #undef STR |
---|
| 1160 | ZEND_PUTS("XCache Auth Failed. User and Password is case sense\n"); |
---|
| 1161 | |
---|
| 1162 | zend_bailout(); |
---|
| 1163 | return 0; |
---|
| 1164 | } |
---|
| 1165 | /* }}} */ |
---|
| 1166 | /* {{{ xcache_admin_operate */ |
---|
[1] | 1167 | typedef enum { XC_OP_COUNT, XC_OP_INFO, XC_OP_LIST, XC_OP_CLEAR } xcache_op_type; |
---|
[34] | 1168 | static void xcache_admin_operate(xcache_op_type optype, INTERNAL_FUNCTION_PARAMETERS) |
---|
[1] | 1169 | { |
---|
| 1170 | long type; |
---|
| 1171 | int size; |
---|
| 1172 | xc_cache_t **caches, *cache; |
---|
| 1173 | long id = 0; |
---|
| 1174 | |
---|
[11] | 1175 | if (!xc_initized) { |
---|
| 1176 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "XCache is not initized"); |
---|
| 1177 | RETURN_FALSE; |
---|
| 1178 | } |
---|
| 1179 | |
---|
[34] | 1180 | xcache_admin_auth_check(TSRMLS_C); |
---|
| 1181 | |
---|
[1] | 1182 | if (optype == XC_OP_COUNT) { |
---|
| 1183 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &type) == FAILURE) { |
---|
| 1184 | return; |
---|
| 1185 | } |
---|
| 1186 | } |
---|
| 1187 | else if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &type, &id) == FAILURE) { |
---|
| 1188 | return; |
---|
| 1189 | } |
---|
| 1190 | |
---|
| 1191 | switch (type) { |
---|
| 1192 | case XC_TYPE_PHP: |
---|
| 1193 | size = xc_php_hcache.size; |
---|
| 1194 | caches = xc_php_caches; |
---|
| 1195 | break; |
---|
| 1196 | |
---|
| 1197 | case XC_TYPE_VAR: |
---|
| 1198 | size = xc_var_hcache.size; |
---|
| 1199 | caches = xc_var_caches; |
---|
| 1200 | break; |
---|
| 1201 | |
---|
| 1202 | default: |
---|
| 1203 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Unknown type %ld", type); |
---|
| 1204 | RETURN_FALSE; |
---|
| 1205 | } |
---|
| 1206 | |
---|
| 1207 | switch (optype) { |
---|
| 1208 | case XC_OP_COUNT: |
---|
| 1209 | RETURN_LONG(size) |
---|
| 1210 | break; |
---|
| 1211 | |
---|
| 1212 | case XC_OP_INFO: |
---|
| 1213 | case XC_OP_LIST: |
---|
| 1214 | if (id < 0 || id >= size) { |
---|
| 1215 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cache not exists"); |
---|
| 1216 | RETURN_FALSE; |
---|
| 1217 | } |
---|
| 1218 | |
---|
| 1219 | array_init(return_value); |
---|
| 1220 | |
---|
| 1221 | cache = caches[id]; |
---|
| 1222 | ENTER_LOCK(cache) { |
---|
| 1223 | if (optype == XC_OP_INFO) { |
---|
| 1224 | xc_fillinfo_dmz(cache, return_value TSRMLS_CC); |
---|
| 1225 | } |
---|
| 1226 | else { |
---|
| 1227 | xc_filllist_dmz(cache, return_value TSRMLS_CC); |
---|
| 1228 | } |
---|
| 1229 | } LEAVE_LOCK(cache); |
---|
| 1230 | break; |
---|
| 1231 | case XC_OP_CLEAR: |
---|
| 1232 | { |
---|
| 1233 | xc_entry_t *e; |
---|
| 1234 | int i, c; |
---|
| 1235 | |
---|
| 1236 | if (id < 0 || id >= size) { |
---|
| 1237 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "Cache not exists"); |
---|
| 1238 | RETURN_FALSE; |
---|
| 1239 | } |
---|
| 1240 | |
---|
| 1241 | cache = caches[id]; |
---|
| 1242 | ENTER_LOCK(cache) { |
---|
| 1243 | for (i = 0, c = cache->hentry->size; i < c; i ++) { |
---|
| 1244 | for (e = cache->entries[i]; e; e = e->next) { |
---|
| 1245 | xc_entry_remove_dmz(e TSRMLS_CC); |
---|
| 1246 | } |
---|
| 1247 | cache->entries[i] = NULL; |
---|
| 1248 | } |
---|
| 1249 | } LEAVE_LOCK(cache); |
---|
| 1250 | xc_entry_gc(TSRMLS_C); |
---|
| 1251 | } |
---|
| 1252 | break; |
---|
| 1253 | |
---|
| 1254 | default: |
---|
| 1255 | assert(0); |
---|
| 1256 | } |
---|
| 1257 | } |
---|
| 1258 | /* }}} */ |
---|
[9] | 1259 | /* {{{ proto int xcache_count(int type) |
---|
| 1260 | Return count of cache on specified cache type */ |
---|
[1] | 1261 | PHP_FUNCTION(xcache_count) |
---|
| 1262 | { |
---|
[34] | 1263 | xcache_admin_operate(XC_OP_COUNT, INTERNAL_FUNCTION_PARAM_PASSTHRU); |
---|
[1] | 1264 | } |
---|
| 1265 | /* }}} */ |
---|
[9] | 1266 | /* {{{ proto array xcache_info(int type, int id) |
---|
| 1267 | Get cache info by id on specified cache type */ |
---|
[1] | 1268 | PHP_FUNCTION(xcache_info) |
---|
| 1269 | { |
---|
[34] | 1270 | xcache_admin_operate(XC_OP_INFO, INTERNAL_FUNCTION_PARAM_PASSTHRU); |
---|
[1] | 1271 | } |
---|
| 1272 | /* }}} */ |
---|
[9] | 1273 | /* {{{ proto array xcache_list(int type, int id) |
---|
| 1274 | Get cache entries list by id on specified cache type */ |
---|
[1] | 1275 | PHP_FUNCTION(xcache_list) |
---|
| 1276 | { |
---|
[34] | 1277 | xcache_admin_operate(XC_OP_LIST, INTERNAL_FUNCTION_PARAM_PASSTHRU); |
---|
[1] | 1278 | } |
---|
| 1279 | /* }}} */ |
---|
[9] | 1280 | /* {{{ proto array xcache_clear_cache(int type, int id) |
---|
| 1281 | Clear cache by id on specified cache type */ |
---|
[1] | 1282 | PHP_FUNCTION(xcache_clear_cache) |
---|
| 1283 | { |
---|
[34] | 1284 | xcache_admin_operate(XC_OP_CLEAR, INTERNAL_FUNCTION_PARAM_PASSTHRU); |
---|
[1] | 1285 | } |
---|
| 1286 | /* }}} */ |
---|
| 1287 | |
---|
| 1288 | static int xc_entry_init_key_var(xc_entry_t *xce, zval *name TSRMLS_DC) /* {{{ */ |
---|
| 1289 | { |
---|
| 1290 | xc_hash_value_t hv; |
---|
| 1291 | int cacheid; |
---|
| 1292 | |
---|
| 1293 | switch (Z_TYPE_P(name)) { |
---|
| 1294 | #ifdef IS_UNICODE |
---|
| 1295 | case IS_UNICODE: |
---|
| 1296 | #endif |
---|
| 1297 | case IS_STRING: |
---|
| 1298 | break; |
---|
| 1299 | default: |
---|
| 1300 | #ifdef IS_UNICODE |
---|
| 1301 | convert_to_text(name); |
---|
| 1302 | #else |
---|
| 1303 | convert_to_string(name); |
---|
| 1304 | #endif |
---|
| 1305 | } |
---|
| 1306 | #ifdef IS_UNICODE |
---|
| 1307 | xce->name_type = name->type; |
---|
| 1308 | #endif |
---|
| 1309 | xce->name = name->value; |
---|
| 1310 | |
---|
| 1311 | hv = xc_entry_hash_var(xce); |
---|
| 1312 | |
---|
| 1313 | cacheid = (hv & xc_var_hcache.mask); |
---|
| 1314 | xce->cache = xc_var_caches[cacheid]; |
---|
| 1315 | hv >>= xc_var_hcache.bits; |
---|
| 1316 | xce->hvalue = (hv & xc_var_hentry.mask); |
---|
| 1317 | |
---|
| 1318 | xce->type = XC_TYPE_VAR; |
---|
| 1319 | return SUCCESS; |
---|
| 1320 | } |
---|
| 1321 | /* }}} */ |
---|
| 1322 | #define TIME_MAX (sizeof(time_t) == sizeof(long) ? LONG_MAX : INT_MAX) |
---|
[9] | 1323 | /* {{{ proto mixed xcache_get(string name) |
---|
| 1324 | Get cached data by specified name */ |
---|
[1] | 1325 | PHP_FUNCTION(xcache_get) |
---|
| 1326 | { |
---|
| 1327 | xc_entry_t xce, *stored_xce; |
---|
| 1328 | xc_entry_data_var_t var; |
---|
| 1329 | zval *name; |
---|
| 1330 | |
---|
| 1331 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &name) == FAILURE) { |
---|
| 1332 | return; |
---|
| 1333 | } |
---|
| 1334 | xce.data.var = &var; |
---|
| 1335 | xc_entry_init_key_var(&xce, name TSRMLS_CC); |
---|
| 1336 | |
---|
| 1337 | ENTER_LOCK(xce.cache) { |
---|
| 1338 | stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC); |
---|
| 1339 | if (stored_xce) { |
---|
| 1340 | if (XG(request_time) <= stored_xce->data.var->etime) { |
---|
| 1341 | xc_processor_restore_zval(return_value, stored_xce->data.var->value TSRMLS_CC); |
---|
| 1342 | /* return */ |
---|
| 1343 | break; |
---|
| 1344 | } |
---|
| 1345 | else { |
---|
[11] | 1346 | xc_entry_remove_dmz(stored_xce TSRMLS_CC); |
---|
[1] | 1347 | } |
---|
| 1348 | } |
---|
| 1349 | |
---|
| 1350 | RETVAL_NULL(); |
---|
| 1351 | } LEAVE_LOCK(xce.cache); |
---|
| 1352 | } |
---|
| 1353 | /* }}} */ |
---|
[9] | 1354 | /* {{{ proto bool xcache_set(string name, mixed value [, int ttl]) |
---|
| 1355 | Store data to cache by specified name */ |
---|
[1] | 1356 | PHP_FUNCTION(xcache_set) |
---|
| 1357 | { |
---|
| 1358 | xc_entry_t xce, *stored_xce; |
---|
| 1359 | xc_entry_data_var_t var; |
---|
| 1360 | zval *name; |
---|
| 1361 | zval *value; |
---|
| 1362 | long ttl = 0; |
---|
| 1363 | |
---|
| 1364 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "zz|l", &name, &value, &ttl) == FAILURE) { |
---|
| 1365 | return; |
---|
| 1366 | } |
---|
| 1367 | xce.data.var = &var; |
---|
| 1368 | xc_entry_init_key_var(&xce, name TSRMLS_CC); |
---|
| 1369 | |
---|
| 1370 | ENTER_LOCK(xce.cache) { |
---|
| 1371 | stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC); |
---|
| 1372 | if (stored_xce) { |
---|
[11] | 1373 | xc_entry_remove_dmz(stored_xce TSRMLS_CC); |
---|
[1] | 1374 | } |
---|
| 1375 | var.value = value; |
---|
| 1376 | var.etime = ttl ? XG(request_time) + ttl : TIME_MAX; |
---|
[11] | 1377 | RETVAL_BOOL(xc_entry_store_dmz(&xce TSRMLS_CC) != NULL ? 1 : 0); |
---|
[1] | 1378 | } LEAVE_LOCK(xce.cache); |
---|
| 1379 | } |
---|
| 1380 | /* }}} */ |
---|
[9] | 1381 | /* {{{ proto bool xcache_isset(string name) |
---|
| 1382 | Check if an entry exists in cache by specified name */ |
---|
[1] | 1383 | PHP_FUNCTION(xcache_isset) |
---|
| 1384 | { |
---|
| 1385 | xc_entry_t xce, *stored_xce; |
---|
| 1386 | xc_entry_data_var_t var; |
---|
| 1387 | zval *name; |
---|
| 1388 | |
---|
| 1389 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &name) == FAILURE) { |
---|
| 1390 | return; |
---|
| 1391 | } |
---|
| 1392 | xce.data.var = &var; |
---|
| 1393 | xc_entry_init_key_var(&xce, name TSRMLS_CC); |
---|
| 1394 | |
---|
| 1395 | ENTER_LOCK(xce.cache) { |
---|
| 1396 | stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC); |
---|
| 1397 | if (stored_xce) { |
---|
| 1398 | if (XG(request_time) <= stored_xce->data.var->etime) { |
---|
| 1399 | RETVAL_TRUE; |
---|
| 1400 | /* return */ |
---|
| 1401 | break; |
---|
| 1402 | } |
---|
| 1403 | else { |
---|
[11] | 1404 | xc_entry_remove_dmz(stored_xce TSRMLS_CC); |
---|
[1] | 1405 | } |
---|
| 1406 | } |
---|
| 1407 | |
---|
| 1408 | RETVAL_FALSE; |
---|
| 1409 | } LEAVE_LOCK(xce.cache); |
---|
| 1410 | } |
---|
| 1411 | /* }}} */ |
---|
[9] | 1412 | /* {{{ proto bool xcache_unset(string name) |
---|
| 1413 | Unset existing data in cache by specified name */ |
---|
[1] | 1414 | PHP_FUNCTION(xcache_unset) |
---|
| 1415 | { |
---|
| 1416 | xc_entry_t xce, *stored_xce; |
---|
| 1417 | xc_entry_data_var_t var; |
---|
| 1418 | zval *name; |
---|
| 1419 | |
---|
| 1420 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &name) == FAILURE) { |
---|
| 1421 | return; |
---|
| 1422 | } |
---|
| 1423 | xce.data.var = &var; |
---|
| 1424 | xc_entry_init_key_var(&xce, name TSRMLS_CC); |
---|
| 1425 | |
---|
| 1426 | ENTER_LOCK(xce.cache) { |
---|
| 1427 | stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC); |
---|
| 1428 | if (stored_xce) { |
---|
[11] | 1429 | xc_entry_remove_dmz(stored_xce TSRMLS_CC); |
---|
[1] | 1430 | RETVAL_TRUE; |
---|
| 1431 | } |
---|
| 1432 | else { |
---|
| 1433 | RETVAL_FALSE; |
---|
| 1434 | } |
---|
| 1435 | } LEAVE_LOCK(xce.cache); |
---|
| 1436 | } |
---|
| 1437 | /* }}} */ |
---|
| 1438 | static inline void xc_var_inc_dec(int inc, INTERNAL_FUNCTION_PARAMETERS) /* {{{ */ |
---|
| 1439 | { |
---|
| 1440 | xc_entry_t xce, *stored_xce; |
---|
| 1441 | xc_entry_data_var_t var, *stored_var; |
---|
| 1442 | zval *name; |
---|
| 1443 | long count = 1; |
---|
| 1444 | long ttl = 0; |
---|
| 1445 | long value = 0; |
---|
| 1446 | zval oldzval; |
---|
| 1447 | |
---|
| 1448 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z|ll", &name, &count, &ttl) == FAILURE) { |
---|
| 1449 | return; |
---|
| 1450 | } |
---|
| 1451 | xce.data.var = &var; |
---|
| 1452 | xc_entry_init_key_var(&xce, name TSRMLS_CC); |
---|
| 1453 | |
---|
| 1454 | ENTER_LOCK(xce.cache) { |
---|
| 1455 | stored_xce = xc_entry_find_dmz(&xce TSRMLS_CC); |
---|
| 1456 | if (stored_xce) { |
---|
| 1457 | #ifdef DEBUG |
---|
| 1458 | fprintf(stderr, "incdec: gotxce %s\n", xce.name.str.val); |
---|
| 1459 | #endif |
---|
| 1460 | stored_var = stored_xce->data.var; |
---|
| 1461 | /* timeout */ |
---|
| 1462 | if (XG(request_time) > stored_var->etime) { |
---|
| 1463 | #ifdef DEBUG |
---|
| 1464 | fprintf(stderr, "incdec: expired\n"); |
---|
| 1465 | #endif |
---|
[11] | 1466 | xc_entry_remove_dmz(stored_xce TSRMLS_CC); |
---|
[1] | 1467 | stored_xce = NULL; |
---|
| 1468 | } |
---|
| 1469 | else { |
---|
| 1470 | /* do it in place */ |
---|
| 1471 | if (Z_TYPE_P(stored_var->value) == IS_LONG) { |
---|
| 1472 | #ifdef DEBUG |
---|
| 1473 | fprintf(stderr, "incdec: islong\n"); |
---|
| 1474 | #endif |
---|
| 1475 | value = Z_LVAL_P(stored_var->value); |
---|
| 1476 | value += (inc == 1 ? count : - count); |
---|
| 1477 | RETVAL_LONG(value); |
---|
| 1478 | Z_LVAL_P(stored_var->value) = value; |
---|
| 1479 | break; |
---|
| 1480 | } |
---|
| 1481 | else { |
---|
| 1482 | #ifdef DEBUG |
---|
| 1483 | fprintf(stderr, "incdec: notlong\n"); |
---|
| 1484 | #endif |
---|
| 1485 | xc_processor_restore_zval(&oldzval, stored_xce->data.var->value TSRMLS_CC); |
---|
| 1486 | convert_to_long(&oldzval); |
---|
| 1487 | value = Z_LVAL(oldzval); |
---|
| 1488 | zval_dtor(&oldzval); |
---|
| 1489 | } |
---|
| 1490 | } |
---|
| 1491 | } |
---|
| 1492 | #ifdef DEBUG |
---|
| 1493 | else { |
---|
| 1494 | fprintf(stderr, "incdec: %s not found\n", xce.name.str.val); |
---|
| 1495 | } |
---|
| 1496 | #endif |
---|
| 1497 | |
---|
| 1498 | value += (inc == 1 ? count : - count); |
---|
| 1499 | RETVAL_LONG(value); |
---|
| 1500 | var.value = return_value; |
---|
| 1501 | var.etime = ttl ? XG(request_time) + ttl : TIME_MAX; |
---|
| 1502 | if (stored_xce) { |
---|
| 1503 | xce.atime = stored_xce->atime; |
---|
| 1504 | xce.ctime = stored_xce->ctime; |
---|
| 1505 | xce.hits = stored_xce->hits; |
---|
[11] | 1506 | xc_entry_remove_dmz(stored_xce TSRMLS_CC); |
---|
[1] | 1507 | } |
---|
[11] | 1508 | xc_entry_store_dmz(&xce TSRMLS_CC); |
---|
[1] | 1509 | |
---|
| 1510 | } LEAVE_LOCK(xce.cache); |
---|
| 1511 | } |
---|
| 1512 | /* }}} */ |
---|
[9] | 1513 | /* {{{ proto int xcache_inc(string name [, int value [, int ttl]]) |
---|
| 1514 | Increase an int counter in cache by specified name, create it if not exists */ |
---|
[1] | 1515 | PHP_FUNCTION(xcache_inc) |
---|
| 1516 | { |
---|
| 1517 | xc_var_inc_dec(1, INTERNAL_FUNCTION_PARAM_PASSTHRU); |
---|
| 1518 | } |
---|
| 1519 | /* }}} */ |
---|
[9] | 1520 | /* {{{ proto int xcache_dec(string name [, int value [, int ttl]]) |
---|
| 1521 | Decrease an int counter in cache by specified name, create it if not exists */ |
---|
[1] | 1522 | PHP_FUNCTION(xcache_dec) |
---|
| 1523 | { |
---|
| 1524 | xc_var_inc_dec(-1, INTERNAL_FUNCTION_PARAM_PASSTHRU); |
---|
| 1525 | } |
---|
| 1526 | /* }}} */ |
---|
[9] | 1527 | /* {{{ proto string xcache_asm(string filename) |
---|
| 1528 | */ |
---|
[1] | 1529 | #ifdef HAVE_XCACHE_ASSEMBLER |
---|
| 1530 | PHP_FUNCTION(xcache_asm) |
---|
| 1531 | { |
---|
| 1532 | } |
---|
| 1533 | #endif |
---|
| 1534 | /* }}} */ |
---|
| 1535 | #ifdef HAVE_XCACHE_DISASSEMBLER |
---|
[9] | 1536 | /* {{{ proto array xcache_dasm_file(string filename) |
---|
| 1537 | Disassemble file into opcode array by filename */ |
---|
[1] | 1538 | PHP_FUNCTION(xcache_dasm_file) |
---|
| 1539 | { |
---|
| 1540 | char *filename; |
---|
| 1541 | long filename_len; |
---|
| 1542 | |
---|
| 1543 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &filename, &filename_len) == FAILURE) { |
---|
| 1544 | return; |
---|
| 1545 | } |
---|
| 1546 | if (!filename_len) RETURN_FALSE; |
---|
| 1547 | |
---|
| 1548 | xc_dasm_file(return_value, filename TSRMLS_CC); |
---|
| 1549 | } |
---|
| 1550 | /* }}} */ |
---|
[9] | 1551 | /* {{{ proto array xcache_dasm_string(string code) |
---|
| 1552 | Disassemble php code into opcode array */ |
---|
[1] | 1553 | PHP_FUNCTION(xcache_dasm_string) |
---|
| 1554 | { |
---|
| 1555 | zval *code; |
---|
| 1556 | |
---|
| 1557 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &code) == FAILURE) { |
---|
| 1558 | return; |
---|
| 1559 | } |
---|
| 1560 | xc_dasm_string(return_value, code TSRMLS_CC); |
---|
| 1561 | } |
---|
| 1562 | /* }}} */ |
---|
| 1563 | #endif |
---|
[9] | 1564 | /* {{{ proto string xcache_encode(string filename) |
---|
| 1565 | Encode php file into XCache opcode encoded format */ |
---|
[1] | 1566 | #ifdef HAVE_XCACHE_ENCODER |
---|
| 1567 | PHP_FUNCTION(xcache_encode) |
---|
| 1568 | { |
---|
| 1569 | } |
---|
| 1570 | #endif |
---|
| 1571 | /* }}} */ |
---|
[9] | 1572 | /* {{{ proto bool xcache_decode_file(string filename) |
---|
| 1573 | Decode(load) opcode from XCache encoded format file */ |
---|
[1] | 1574 | #ifdef HAVE_XCACHE_DECODER |
---|
[9] | 1575 | PHP_FUNCTION(xcache_decode_file) |
---|
[1] | 1576 | { |
---|
| 1577 | } |
---|
| 1578 | #endif |
---|
| 1579 | /* }}} */ |
---|
[9] | 1580 | /* {{{ proto bool xcache_decode_string(string data) |
---|
| 1581 | Decode(load) opcode from XCache encoded format data */ |
---|
| 1582 | #ifdef HAVE_XCACHE_DECODER |
---|
| 1583 | PHP_FUNCTION(xcache_decode_string) |
---|
| 1584 | { |
---|
| 1585 | } |
---|
| 1586 | #endif |
---|
| 1587 | /* }}} */ |
---|
[1] | 1588 | /* {{{ xc_call_getter */ |
---|
| 1589 | typedef const char *(xc_name_getter_t)(zend_uchar type); |
---|
| 1590 | static void xc_call_getter(xc_name_getter_t getter, int count, INTERNAL_FUNCTION_PARAMETERS) |
---|
| 1591 | { |
---|
| 1592 | long spec; |
---|
| 1593 | const char *name; |
---|
| 1594 | |
---|
| 1595 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &spec) == FAILURE) { |
---|
| 1596 | return; |
---|
| 1597 | } |
---|
| 1598 | if (spec >= 0 && spec < count) { |
---|
[11] | 1599 | name = getter((zend_uchar) spec); |
---|
[1] | 1600 | if (name) { |
---|
| 1601 | /* RETURN_STRING */ |
---|
| 1602 | int len = strlen(name); |
---|
| 1603 | return_value->value.str.len = len; |
---|
| 1604 | return_value->value.str.val = estrndup(name, len); |
---|
| 1605 | return_value->type = IS_STRING; |
---|
| 1606 | return; |
---|
| 1607 | } |
---|
| 1608 | } |
---|
| 1609 | RETURN_NULL(); |
---|
| 1610 | } |
---|
| 1611 | /* }}} */ |
---|
| 1612 | /* {{{ proto string xcache_get_op_type(int op_type) */ |
---|
| 1613 | PHP_FUNCTION(xcache_get_op_type) |
---|
| 1614 | { |
---|
| 1615 | xc_call_getter(xc_get_op_type, xc_get_op_type_count(), INTERNAL_FUNCTION_PARAM_PASSTHRU); |
---|
| 1616 | } |
---|
| 1617 | /* }}} */ |
---|
| 1618 | /* {{{ proto string xcache_get_data_type(int type) */ |
---|
| 1619 | PHP_FUNCTION(xcache_get_data_type) |
---|
| 1620 | { |
---|
| 1621 | xc_call_getter(xc_get_data_type, xc_get_data_type_count(), INTERNAL_FUNCTION_PARAM_PASSTHRU); |
---|
| 1622 | } |
---|
| 1623 | /* }}} */ |
---|
| 1624 | /* {{{ proto string xcache_get_opcode(int opcode) */ |
---|
| 1625 | PHP_FUNCTION(xcache_get_opcode) |
---|
| 1626 | { |
---|
| 1627 | xc_call_getter(xc_get_opcode, xc_get_opcode_count(), INTERNAL_FUNCTION_PARAM_PASSTHRU); |
---|
| 1628 | } |
---|
| 1629 | /* }}} */ |
---|
| 1630 | /* {{{ proto string xcache_get_op_spec(int op_type) */ |
---|
| 1631 | PHP_FUNCTION(xcache_get_op_spec) |
---|
| 1632 | { |
---|
| 1633 | xc_call_getter(xc_get_op_spec, xc_get_op_spec_count(), INTERNAL_FUNCTION_PARAM_PASSTHRU); |
---|
| 1634 | } |
---|
| 1635 | /* }}} */ |
---|
[8] | 1636 | #ifdef HAVE_XCACHE_OPCODE_SPEC_DEF |
---|
[1] | 1637 | /* {{{ proto string xcache_get_opcode_spec(int opcode) */ |
---|
| 1638 | PHP_FUNCTION(xcache_get_opcode_spec) |
---|
| 1639 | { |
---|
| 1640 | long spec; |
---|
| 1641 | const xc_opcode_spec_t *opspec; |
---|
| 1642 | |
---|
| 1643 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &spec) == FAILURE) { |
---|
| 1644 | return; |
---|
| 1645 | } |
---|
[17] | 1646 | if ((zend_uchar) spec <= xc_get_opcode_spec_count()) { |
---|
[11] | 1647 | opspec = xc_get_opcode_spec((zend_uchar) spec); |
---|
[1] | 1648 | if (opspec) { |
---|
| 1649 | array_init(return_value); |
---|
| 1650 | add_assoc_long_ex(return_value, ZEND_STRS("ext"), opspec->ext); |
---|
| 1651 | add_assoc_long_ex(return_value, ZEND_STRS("op1"), opspec->op1); |
---|
| 1652 | add_assoc_long_ex(return_value, ZEND_STRS("op2"), opspec->op2); |
---|
| 1653 | add_assoc_long_ex(return_value, ZEND_STRS("res"), opspec->res); |
---|
| 1654 | return; |
---|
| 1655 | } |
---|
| 1656 | } |
---|
| 1657 | RETURN_NULL(); |
---|
| 1658 | } |
---|
| 1659 | /* }}} */ |
---|
[8] | 1660 | #endif |
---|
[1] | 1661 | /* {{{ proto mixed xcache_get_special_value(zval value) */ |
---|
| 1662 | PHP_FUNCTION(xcache_get_special_value) |
---|
| 1663 | { |
---|
| 1664 | zval *value; |
---|
| 1665 | |
---|
| 1666 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) == FAILURE) { |
---|
| 1667 | return; |
---|
| 1668 | } |
---|
| 1669 | |
---|
| 1670 | if (value->type == IS_CONSTANT) { |
---|
| 1671 | *return_value = *value; |
---|
| 1672 | zval_copy_ctor(return_value); |
---|
| 1673 | return_value->type = UNISW(IS_STRING, UG(unicode) ? IS_UNICODE : IS_STRING); |
---|
| 1674 | return; |
---|
| 1675 | } |
---|
| 1676 | |
---|
| 1677 | if (value->type == IS_CONSTANT_ARRAY) { |
---|
| 1678 | *return_value = *value; |
---|
| 1679 | zval_copy_ctor(return_value); |
---|
| 1680 | return_value->type = IS_ARRAY; |
---|
| 1681 | return; |
---|
| 1682 | } |
---|
| 1683 | |
---|
| 1684 | RETURN_NULL(); |
---|
| 1685 | } |
---|
| 1686 | /* }}} */ |
---|
| 1687 | /* {{{ proto string xcache_coredump(int op_type) */ |
---|
| 1688 | PHP_FUNCTION(xcache_coredump) |
---|
| 1689 | { |
---|
[9] | 1690 | if (xc_test) { |
---|
| 1691 | raise(SIGSEGV); |
---|
| 1692 | } |
---|
| 1693 | else { |
---|
| 1694 | php_error_docref(NULL TSRMLS_CC, E_WARNING, "xcache.test must be enabled to test xcache_coredump()"); |
---|
| 1695 | } |
---|
[1] | 1696 | } |
---|
| 1697 | /* }}} */ |
---|
| 1698 | /* {{{ proto string xcache_is_autoglobal(string name) */ |
---|
| 1699 | PHP_FUNCTION(xcache_is_autoglobal) |
---|
| 1700 | { |
---|
| 1701 | char *name; |
---|
| 1702 | long name_len; |
---|
| 1703 | |
---|
| 1704 | if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", &name, &name_len) == FAILURE) { |
---|
| 1705 | return; |
---|
| 1706 | } |
---|
| 1707 | |
---|
| 1708 | RETURN_BOOL(zend_hash_exists(CG(auto_globals), name, name_len + 1)); |
---|
| 1709 | } |
---|
| 1710 | /* }}} */ |
---|
| 1711 | static function_entry xcache_functions[] = /* {{{ */ |
---|
| 1712 | { |
---|
| 1713 | PHP_FE(xcache_count, NULL) |
---|
| 1714 | PHP_FE(xcache_info, NULL) |
---|
| 1715 | PHP_FE(xcache_list, NULL) |
---|
| 1716 | PHP_FE(xcache_clear_cache, NULL) |
---|
| 1717 | PHP_FE(xcache_coredump, NULL) |
---|
| 1718 | #ifdef HAVE_XCACHE_ASSEMBLER |
---|
| 1719 | PHP_FE(xcache_asm, NULL) |
---|
| 1720 | #endif |
---|
| 1721 | #ifdef HAVE_XCACHE_DISASSEMBLER |
---|
| 1722 | PHP_FE(xcache_dasm_file, NULL) |
---|
| 1723 | PHP_FE(xcache_dasm_string, NULL) |
---|
| 1724 | #endif |
---|
| 1725 | #ifdef HAVE_XCACHE_ENCODER |
---|
| 1726 | PHP_FE(xcache_encode, NULL) |
---|
| 1727 | #endif |
---|
| 1728 | #ifdef HAVE_XCACHE_DECODER |
---|
[9] | 1729 | PHP_FE(xcache_decode_file, NULL) |
---|
| 1730 | PHP_FE(xcache_decode_string, NULL) |
---|
[1] | 1731 | #endif |
---|
[27] | 1732 | #ifdef HAVE_XCACHE_COVERAGER |
---|
| 1733 | PHP_FE(xcache_coverager_decode, NULL) |
---|
[1] | 1734 | #endif |
---|
| 1735 | PHP_FE(xcache_get_special_value, NULL) |
---|
| 1736 | PHP_FE(xcache_get_op_type, NULL) |
---|
| 1737 | PHP_FE(xcache_get_data_type, NULL) |
---|
| 1738 | PHP_FE(xcache_get_opcode, NULL) |
---|
[8] | 1739 | #ifdef HAVE_XCACHE_OPCODE_SPEC_DEF |
---|
[1] | 1740 | PHP_FE(xcache_get_opcode_spec, NULL) |
---|
[8] | 1741 | #endif |
---|
[1] | 1742 | PHP_FE(xcache_is_autoglobal, NULL) |
---|
| 1743 | PHP_FE(xcache_inc, NULL) |
---|
| 1744 | PHP_FE(xcache_dec, NULL) |
---|
| 1745 | PHP_FE(xcache_get, NULL) |
---|
| 1746 | PHP_FE(xcache_set, NULL) |
---|
| 1747 | PHP_FE(xcache_isset, NULL) |
---|
| 1748 | PHP_FE(xcache_unset, NULL) |
---|
| 1749 | {NULL, NULL, NULL} |
---|
| 1750 | }; |
---|
| 1751 | /* }}} */ |
---|
| 1752 | |
---|
[75] | 1753 | /* old signal handlers {{{ */ |
---|
| 1754 | typedef void (*xc_sighandler_t)(int); |
---|
| 1755 | #define FOREACH_SIG(sig) static xc_sighandler_t old_##sig##_handler = NULL |
---|
| 1756 | #include "foreachcoresig.h" |
---|
| 1757 | #undef FOREACH_SIG |
---|
| 1758 | /* }}} */ |
---|
| 1759 | static void xcache_signal_handler(int sig); |
---|
| 1760 | static void xcache_restore_signal_handler() /* {{{ */ |
---|
[1] | 1761 | { |
---|
[75] | 1762 | #define FOREACH_SIG(sig) do { \ |
---|
| 1763 | if (old_##sig##_handler != xcache_signal_handler) { \ |
---|
| 1764 | signal(sig, old_##sig##_handler); \ |
---|
| 1765 | } \ |
---|
| 1766 | else { \ |
---|
| 1767 | signal(sig, SIG_DFL); \ |
---|
| 1768 | } \ |
---|
| 1769 | } while (0) |
---|
| 1770 | #include "foreachcoresig.h" |
---|
| 1771 | #undef FOREACH_SIG |
---|
| 1772 | } |
---|
| 1773 | /* }}} */ |
---|
| 1774 | static void xcache_init_signal_handler() /* {{{ */ |
---|
| 1775 | { |
---|
| 1776 | #define FOREACH_SIG(sig) \ |
---|
| 1777 | old_##sig##_handler = signal(sig, xcache_signal_handler) |
---|
| 1778 | #include "foreachcoresig.h" |
---|
| 1779 | #undef FOREACH_SIG |
---|
| 1780 | } |
---|
| 1781 | /* }}} */ |
---|
| 1782 | static void xcache_signal_handler(int sig) /* {{{ */ |
---|
| 1783 | { |
---|
| 1784 | xcache_restore_signal_handler(); |
---|
[1] | 1785 | if (xc_coredump_dir && xc_coredump_dir[0]) { |
---|
| 1786 | chdir(xc_coredump_dir); |
---|
| 1787 | } |
---|
[65] | 1788 | raise(sig); |
---|
[1] | 1789 | } |
---|
| 1790 | /* }}} */ |
---|
| 1791 | |
---|
| 1792 | /* {{{ PHP_INI */ |
---|
| 1793 | |
---|
| 1794 | static PHP_INI_MH(xc_OnUpdateBool) |
---|
| 1795 | { |
---|
| 1796 | zend_bool *p = (zend_bool *)mh_arg1; |
---|
| 1797 | |
---|
| 1798 | if (strncasecmp("on", new_value, sizeof("on"))) { |
---|
| 1799 | *p = (zend_bool) atoi(new_value); |
---|
| 1800 | } |
---|
| 1801 | else { |
---|
| 1802 | *p = (zend_bool) 1; |
---|
| 1803 | } |
---|
| 1804 | return SUCCESS; |
---|
| 1805 | } |
---|
| 1806 | |
---|
| 1807 | static PHP_INI_MH(xc_OnUpdateString) |
---|
| 1808 | { |
---|
| 1809 | char **p = (char**)mh_arg1; |
---|
| 1810 | if (*p) { |
---|
| 1811 | pefree(*p, 1); |
---|
| 1812 | } |
---|
| 1813 | *p = pemalloc(strlen(new_value) + 1, 1); |
---|
| 1814 | strcpy(*p, new_value); |
---|
| 1815 | return SUCCESS; |
---|
| 1816 | } |
---|
[82] | 1817 | |
---|
[1] | 1818 | #ifdef ZEND_ENGINE_2 |
---|
| 1819 | #define OnUpdateInt OnUpdateLong |
---|
| 1820 | #endif |
---|
| 1821 | |
---|
[21] | 1822 | #ifdef ZEND_WIN32 |
---|
| 1823 | # define DEFAULT_PATH "xcache" |
---|
| 1824 | #else |
---|
| 1825 | # define DEFAULT_PATH "/dev/zero" |
---|
| 1826 | #endif |
---|
[1] | 1827 | PHP_INI_BEGIN() |
---|
[21] | 1828 | PHP_INI_ENTRY1 ("xcache.mmap_path", DEFAULT_PATH, PHP_INI_SYSTEM, xc_OnUpdateString, &xc_mmap_path) |
---|
[1] | 1829 | PHP_INI_ENTRY1 ("xcache.coredump_directory", "", PHP_INI_SYSTEM, xc_OnUpdateString, &xc_coredump_dir) |
---|
| 1830 | PHP_INI_ENTRY1 ("xcache.test", "0", PHP_INI_SYSTEM, xc_OnUpdateBool, &xc_test) |
---|
| 1831 | PHP_INI_ENTRY1 ("xcache.readonly_protection", "0", PHP_INI_SYSTEM, xc_OnUpdateBool, &xc_readonly_protection) |
---|
| 1832 | |
---|
| 1833 | STD_PHP_INI_BOOLEAN("xcache.cacher", "1", PHP_INI_ALL, OnUpdateBool, cacher, zend_xcache_globals, xcache_globals) |
---|
| 1834 | #ifdef HAVE_XCACHE_OPTIMIZER |
---|
| 1835 | STD_PHP_INI_BOOLEAN("xcache.optimizer", "0", PHP_INI_ALL, OnUpdateBool, optimizer, zend_xcache_globals, xcache_globals) |
---|
| 1836 | #endif |
---|
[27] | 1837 | #ifdef HAVE_XCACHE_COVERAGER |
---|
[39] | 1838 | PHP_INI_ENTRY1 ("xcache.coveragedump_directory", "/tmp/pcov/", PHP_INI_SYSTEM, xc_OnUpdateString, &xc_coveragedump_dir) |
---|
| 1839 | STD_PHP_INI_BOOLEAN("xcache.coveragedumper" , "0", PHP_INI_ALL, OnUpdateBool, coveragedumper, zend_xcache_globals, xcache_globals) |
---|
[1] | 1840 | #endif |
---|
| 1841 | PHP_INI_END() |
---|
| 1842 | /* }}} */ |
---|
[82] | 1843 | static int xc_config_long_disp(char *name, char *default_value) /* {{{ */ |
---|
| 1844 | { |
---|
| 1845 | char *value; |
---|
| 1846 | char buf[100]; |
---|
| 1847 | |
---|
| 1848 | if (cfg_get_string(name, &value) != SUCCESS) { |
---|
| 1849 | sprintf(buf, "%s (default)", default_value); |
---|
| 1850 | php_info_print_table_row(2, name, buf); |
---|
| 1851 | } |
---|
| 1852 | else { |
---|
| 1853 | php_info_print_table_row(2, name, value); |
---|
| 1854 | } |
---|
| 1855 | |
---|
| 1856 | return SUCCESS; |
---|
| 1857 | } |
---|
| 1858 | /* }}} */ |
---|
| 1859 | #define xc_config_hash_disp xc_config_long_disp |
---|
[1] | 1860 | /* {{{ PHP_MINFO_FUNCTION(xcache) */ |
---|
| 1861 | static PHP_MINFO_FUNCTION(xcache) |
---|
| 1862 | { |
---|
[82] | 1863 | char buf[100]; |
---|
| 1864 | char *ptr; |
---|
| 1865 | |
---|
[1] | 1866 | php_info_print_table_start(); |
---|
[82] | 1867 | php_info_print_table_header(2, "XCache Support", XCACHE_MODULES); |
---|
[1] | 1868 | php_info_print_table_row(2, "Version", XCACHE_VERSION); |
---|
[26] | 1869 | php_info_print_table_row(2, "Modules Built", XCACHE_MODULES); |
---|
[1] | 1870 | php_info_print_table_row(2, "Readonly Protection", xc_readonly_protection ? "enabled" : "N/A"); |
---|
[82] | 1871 | |
---|
| 1872 | if (xc_php_size) { |
---|
| 1873 | ptr = _php_math_number_format(xc_php_size, 0, '.', ','); |
---|
| 1874 | sprintf(buf, "enabled, %s bytes, %d split(s), with %d slots each", ptr, xc_php_hcache.size, xc_php_hentry.size); |
---|
| 1875 | php_info_print_table_row(2, "Opcode Cache", buf); |
---|
| 1876 | efree(ptr); |
---|
| 1877 | } |
---|
| 1878 | else { |
---|
| 1879 | php_info_print_table_row(2, "Opcode Cache", "disabled"); |
---|
| 1880 | } |
---|
| 1881 | if (xc_var_size) { |
---|
| 1882 | ptr = _php_math_number_format(xc_var_size, 0, '.', ','); |
---|
| 1883 | sprintf(buf, "enabled, %s bytes, %d split(s), with %d slots each", ptr, xc_var_hcache.size, xc_var_hentry.size); |
---|
| 1884 | php_info_print_table_row(2, "Variable Cache", buf); |
---|
| 1885 | efree(ptr); |
---|
| 1886 | } |
---|
| 1887 | else { |
---|
| 1888 | php_info_print_table_row(2, "Variable Cache", "disabled"); |
---|
| 1889 | } |
---|
[26] | 1890 | #ifdef HAVE_XCACHE_COVERAGER |
---|
| 1891 | php_info_print_table_row(2, "Coverage Dumper", XG(coveragedumper) && xc_coveragedump_dir && xc_coveragedump_dir[0] ? "enabled" : "disabled"); |
---|
| 1892 | #endif |
---|
[1] | 1893 | php_info_print_table_end(); |
---|
[82] | 1894 | |
---|
| 1895 | php_info_print_table_start(); |
---|
| 1896 | php_info_print_table_header(2, "Directive ", "Value"); |
---|
| 1897 | xc_config_long_disp("xcache.size", "0"); |
---|
| 1898 | xc_config_hash_disp("xcache.count", "1"); |
---|
| 1899 | xc_config_hash_disp("xcache.slots", "8K"); |
---|
| 1900 | |
---|
| 1901 | xc_config_long_disp("xcache.var_size", "0"); |
---|
| 1902 | xc_config_hash_disp("xcache.var_count", "1"); |
---|
| 1903 | xc_config_hash_disp("xcache.var_slots", "8K"); |
---|
| 1904 | php_info_print_table_end(); |
---|
| 1905 | |
---|
[1] | 1906 | DISPLAY_INI_ENTRIES(); |
---|
| 1907 | } |
---|
| 1908 | /* }}} */ |
---|
| 1909 | /* {{{ extension startup */ |
---|
| 1910 | static void xc_zend_extension_register(zend_extension *new_extension, DL_HANDLE handle) |
---|
| 1911 | { |
---|
| 1912 | zend_extension extension; |
---|
| 1913 | |
---|
| 1914 | extension = *new_extension; |
---|
| 1915 | extension.handle = handle; |
---|
| 1916 | |
---|
| 1917 | zend_extension_dispatch_message(ZEND_EXTMSG_NEW_EXTENSION, &extension); |
---|
| 1918 | |
---|
| 1919 | zend_llist_add_element(&zend_extensions, &extension); |
---|
| 1920 | #ifdef DEBUG |
---|
| 1921 | fprintf(stderr, "registered\n"); |
---|
| 1922 | #endif |
---|
| 1923 | } |
---|
| 1924 | |
---|
| 1925 | /* dirty check */ |
---|
| 1926 | #if defined(COMPILE_DL_XCACHE) && (defined(ZEND_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)) |
---|
| 1927 | # define zend_append_version_info(x) do { } while (0) |
---|
| 1928 | #else |
---|
| 1929 | extern void zend_append_version_info(zend_extension *extension); |
---|
| 1930 | #endif |
---|
| 1931 | static int xc_zend_extension_startup(zend_extension *extension) |
---|
| 1932 | { |
---|
| 1933 | if (extension->startup) { |
---|
| 1934 | if (extension->startup(extension) != SUCCESS) { |
---|
| 1935 | return FAILURE; |
---|
| 1936 | } |
---|
| 1937 | zend_append_version_info(extension); |
---|
| 1938 | } |
---|
| 1939 | return SUCCESS; |
---|
| 1940 | } |
---|
| 1941 | /* }}} */ |
---|
[82] | 1942 | static int xc_config_hash(xc_hash_t *p, char *name, char *default_value) /* {{{ */ |
---|
| 1943 | { |
---|
| 1944 | int bits, size; |
---|
| 1945 | char *value; |
---|
| 1946 | |
---|
| 1947 | if (cfg_get_string(name, &value) != SUCCESS) { |
---|
| 1948 | value = default_value; |
---|
| 1949 | } |
---|
| 1950 | |
---|
| 1951 | p->size = zend_atoi(value, strlen(value)); |
---|
| 1952 | for (size = 1, bits = 1; size < p->size; bits ++, size <<= 1) { |
---|
| 1953 | /* empty body */ |
---|
| 1954 | } |
---|
| 1955 | p->size = size; |
---|
| 1956 | p->bits = bits; |
---|
| 1957 | p->mask = size - 1; |
---|
| 1958 | |
---|
| 1959 | return SUCCESS; |
---|
| 1960 | } |
---|
| 1961 | /* }}} */ |
---|
[90] | 1962 | static int xc_config_long(zend_ulong *p, char *name, char *default_value) /* {{{ */ |
---|
[82] | 1963 | { |
---|
| 1964 | char *value; |
---|
| 1965 | |
---|
| 1966 | if (cfg_get_string(name, &value) != SUCCESS) { |
---|
| 1967 | value = default_value; |
---|
| 1968 | } |
---|
| 1969 | |
---|
| 1970 | *p = zend_atoi(value, strlen(value)); |
---|
| 1971 | return SUCCESS; |
---|
| 1972 | } |
---|
| 1973 | /* }}} */ |
---|
[1] | 1974 | /* {{{ PHP_MINIT_FUNCTION(xcache) */ |
---|
| 1975 | static PHP_MINIT_FUNCTION(xcache) |
---|
| 1976 | { |
---|
| 1977 | char *env; |
---|
| 1978 | |
---|
| 1979 | xc_module_gotup = 1; |
---|
| 1980 | if (!xc_zend_extension_gotup) { |
---|
| 1981 | if (zend_get_extension(XCACHE_NAME) == NULL) { |
---|
| 1982 | xc_zend_extension_register(&zend_extension_entry, 0); |
---|
| 1983 | xc_zend_extension_startup(&zend_extension_entry); |
---|
| 1984 | } |
---|
| 1985 | } |
---|
| 1986 | |
---|
[17] | 1987 | ZEND_INIT_MODULE_GLOBALS(xcache, xc_init_globals, xc_shutdown_globals); |
---|
| 1988 | REGISTER_INI_ENTRIES(); |
---|
| 1989 | |
---|
[1] | 1990 | if (strcmp(sapi_module.name, "cli") == 0) { |
---|
| 1991 | if ((env = getenv("XCACHE_TEST")) != NULL) { |
---|
| 1992 | zend_alter_ini_entry("xcache.test", sizeof("xcache.test"), env, strlen(env) + 1, PHP_INI_SYSTEM, PHP_INI_STAGE_STARTUP); |
---|
| 1993 | } |
---|
| 1994 | if (!xc_test) { |
---|
| 1995 | /* disable cache for cli except for test */ |
---|
| 1996 | xc_php_size = xc_var_size = 0; |
---|
| 1997 | } |
---|
| 1998 | } |
---|
| 1999 | |
---|
[82] | 2000 | xc_config_long(&xc_php_size, "xcache.size", "0"); |
---|
| 2001 | xc_config_hash(&xc_php_hcache, "xcache.count", "1"); |
---|
| 2002 | xc_config_hash(&xc_php_hentry, "xcache.slots", "8K"); |
---|
| 2003 | |
---|
| 2004 | xc_config_long(&xc_var_size, "xcache.var_size", "0"); |
---|
| 2005 | xc_config_hash(&xc_var_hcache, "xcache.var_count", "1"); |
---|
| 2006 | xc_config_hash(&xc_var_hentry, "xcache.var_slots", "8K"); |
---|
| 2007 | |
---|
[1] | 2008 | if (xc_php_size <= 0) { |
---|
| 2009 | xc_php_size = xc_php_hcache.size = 0; |
---|
| 2010 | } |
---|
| 2011 | if (xc_var_size <= 0) { |
---|
| 2012 | xc_var_size = xc_var_hcache.size = 0; |
---|
| 2013 | } |
---|
| 2014 | |
---|
[65] | 2015 | if (xc_coredump_dir && xc_coredump_dir[0]) { |
---|
[75] | 2016 | xcache_init_signal_handler(); |
---|
[65] | 2017 | } |
---|
[1] | 2018 | |
---|
| 2019 | xc_init_constant(module_number TSRMLS_CC); |
---|
| 2020 | |
---|
| 2021 | if ((xc_php_size || xc_var_size) && xc_mmap_path && xc_mmap_path[0]) { |
---|
| 2022 | if (!xc_init(module_number TSRMLS_CC)) { |
---|
[21] | 2023 | zend_error(E_ERROR, "XCache: Cannot init"); |
---|
[1] | 2024 | goto err_init; |
---|
| 2025 | } |
---|
| 2026 | xc_initized = 1; |
---|
| 2027 | } |
---|
| 2028 | |
---|
[27] | 2029 | #ifdef HAVE_XCACHE_COVERAGER |
---|
| 2030 | xc_coverager_init(module_number TSRMLS_CC); |
---|
[1] | 2031 | #endif |
---|
| 2032 | |
---|
| 2033 | return SUCCESS; |
---|
| 2034 | |
---|
| 2035 | err_init: |
---|
| 2036 | return FAILURE; |
---|
| 2037 | } |
---|
| 2038 | /* }}} */ |
---|
| 2039 | /* {{{ PHP_MSHUTDOWN_FUNCTION(xcache) */ |
---|
| 2040 | static PHP_MSHUTDOWN_FUNCTION(xcache) |
---|
| 2041 | { |
---|
| 2042 | if (xc_initized) { |
---|
| 2043 | xc_destroy(); |
---|
| 2044 | xc_initized = 0; |
---|
| 2045 | } |
---|
| 2046 | if (xc_mmap_path) { |
---|
| 2047 | pefree(xc_mmap_path, 1); |
---|
| 2048 | xc_mmap_path = NULL; |
---|
| 2049 | } |
---|
| 2050 | |
---|
[27] | 2051 | #ifdef HAVE_XCACHE_COVERAGER |
---|
| 2052 | xc_coverager_destroy(); |
---|
[1] | 2053 | #endif |
---|
| 2054 | |
---|
[65] | 2055 | if (xc_coredump_dir && xc_coredump_dir[0]) { |
---|
[75] | 2056 | xcache_restore_signal_handler(); |
---|
[65] | 2057 | } |
---|
[1] | 2058 | if (xc_coredump_dir) { |
---|
| 2059 | pefree(xc_coredump_dir, 1); |
---|
| 2060 | xc_coredump_dir = NULL; |
---|
| 2061 | } |
---|
[25] | 2062 | #ifdef ZTS |
---|
| 2063 | ts_free_id(xcache_globals_id); |
---|
| 2064 | #else |
---|
[1] | 2065 | xc_shutdown_globals(&xcache_globals TSRMLS_CC); |
---|
| 2066 | #endif |
---|
| 2067 | |
---|
| 2068 | UNREGISTER_INI_ENTRIES(); |
---|
| 2069 | return SUCCESS; |
---|
| 2070 | } |
---|
| 2071 | /* }}} */ |
---|
| 2072 | /* {{{ PHP_RINIT_FUNCTION(xcache) */ |
---|
| 2073 | static PHP_RINIT_FUNCTION(xcache) |
---|
| 2074 | { |
---|
| 2075 | xc_request_init(TSRMLS_C); |
---|
| 2076 | return SUCCESS; |
---|
| 2077 | } |
---|
| 2078 | /* }}} */ |
---|
| 2079 | /* {{{ PHP_RSHUTDOWN_FUNCTION(xcache) */ |
---|
| 2080 | #ifndef ZEND_ENGINE_2 |
---|
| 2081 | static PHP_RSHUTDOWN_FUNCTION(xcache) |
---|
| 2082 | #else |
---|
| 2083 | static ZEND_MODULE_POST_ZEND_DEACTIVATE_D(xcache) |
---|
| 2084 | #endif |
---|
| 2085 | { |
---|
[18] | 2086 | #ifdef ZEND_ENGINE_2 |
---|
[11] | 2087 | TSRMLS_FETCH(); |
---|
[18] | 2088 | #endif |
---|
[11] | 2089 | |
---|
[1] | 2090 | xc_request_shutdown(TSRMLS_C); |
---|
| 2091 | return SUCCESS; |
---|
| 2092 | } |
---|
| 2093 | /* }}} */ |
---|
| 2094 | /* {{{ module definition structure */ |
---|
| 2095 | |
---|
| 2096 | zend_module_entry xcache_module_entry = { |
---|
| 2097 | STANDARD_MODULE_HEADER, |
---|
[21] | 2098 | "XCache", |
---|
[1] | 2099 | xcache_functions, |
---|
| 2100 | PHP_MINIT(xcache), |
---|
| 2101 | PHP_MSHUTDOWN(xcache), |
---|
| 2102 | PHP_RINIT(xcache), |
---|
| 2103 | #ifndef ZEND_ENGINE_2 |
---|
| 2104 | PHP_RSHUTDOWN(xcache), |
---|
| 2105 | #else |
---|
| 2106 | NULL, |
---|
| 2107 | #endif |
---|
| 2108 | PHP_MINFO(xcache), |
---|
| 2109 | XCACHE_VERSION, |
---|
| 2110 | #ifdef ZEND_ENGINE_2 |
---|
| 2111 | ZEND_MODULE_POST_ZEND_DEACTIVATE_N(xcache), |
---|
| 2112 | #else |
---|
| 2113 | NULL, |
---|
| 2114 | NULL, |
---|
| 2115 | #endif |
---|
| 2116 | STANDARD_MODULE_PROPERTIES_EX |
---|
| 2117 | }; |
---|
| 2118 | |
---|
| 2119 | #ifdef COMPILE_DL_XCACHE |
---|
| 2120 | ZEND_GET_MODULE(xcache) |
---|
| 2121 | #endif |
---|
| 2122 | /* }}} */ |
---|
| 2123 | ZEND_DLEXPORT int xcache_zend_startup(zend_extension *extension) /* {{{ */ |
---|
| 2124 | { |
---|
| 2125 | if (xc_zend_extension_gotup) { |
---|
| 2126 | return FAILURE; |
---|
| 2127 | } |
---|
| 2128 | xc_zend_extension_gotup = 1; |
---|
| 2129 | if (!xc_module_gotup) { |
---|
| 2130 | return zend_startup_module(&xcache_module_entry); |
---|
| 2131 | } |
---|
| 2132 | return SUCCESS; |
---|
| 2133 | } |
---|
| 2134 | /* }}} */ |
---|
| 2135 | ZEND_DLEXPORT void xcache_zend_shutdown(zend_extension *extension) /* {{{ */ |
---|
| 2136 | { |
---|
| 2137 | /* empty */ |
---|
| 2138 | } |
---|
| 2139 | /* }}} */ |
---|
| 2140 | ZEND_DLEXPORT void xcache_statement_handler(zend_op_array *op_array) /* {{{ */ |
---|
| 2141 | { |
---|
[27] | 2142 | #ifdef HAVE_XCACHE_COVERAGER |
---|
| 2143 | xc_coverager_handle_ext_stmt(op_array, ZEND_EXT_STMT); |
---|
[1] | 2144 | #endif |
---|
| 2145 | } |
---|
| 2146 | /* }}} */ |
---|
| 2147 | ZEND_DLEXPORT void xcache_fcall_begin_handler(zend_op_array *op_array) /* {{{ */ |
---|
| 2148 | { |
---|
| 2149 | #if 0 |
---|
[27] | 2150 | xc_coverager_handle_ext_stmt(op_array, ZEND_EXT_FCALL_BEGIN); |
---|
[1] | 2151 | #endif |
---|
| 2152 | } |
---|
| 2153 | /* }}} */ |
---|
| 2154 | ZEND_DLEXPORT void xcache_fcall_end_handler(zend_op_array *op_array) /* {{{ */ |
---|
| 2155 | { |
---|
| 2156 | #if 0 |
---|
[27] | 2157 | xc_coverager_handle_ext_stmt(op_array, ZEND_EXT_FCALL_END); |
---|
[1] | 2158 | #endif |
---|
| 2159 | } |
---|
| 2160 | /* }}} */ |
---|
| 2161 | /* {{{ zend extension definition structure */ |
---|
| 2162 | ZEND_DLEXPORT zend_extension zend_extension_entry = { |
---|
| 2163 | XCACHE_NAME, |
---|
| 2164 | XCACHE_VERSION, |
---|
| 2165 | XCACHE_AUTHOR, |
---|
| 2166 | XCACHE_URL, |
---|
| 2167 | XCACHE_COPYRIGHT, |
---|
| 2168 | xcache_zend_startup, |
---|
| 2169 | xcache_zend_shutdown, |
---|
| 2170 | NULL, /* activate_func_t */ |
---|
| 2171 | NULL, /* deactivate_func_t */ |
---|
| 2172 | NULL, /* message_handler_func_t */ |
---|
| 2173 | NULL, /* op_array_handler_func_t */ |
---|
| 2174 | xcache_statement_handler, |
---|
| 2175 | xcache_fcall_begin_handler, |
---|
| 2176 | xcache_fcall_end_handler, |
---|
| 2177 | NULL, /* op_array_ctor_func_t */ |
---|
| 2178 | NULL, /* op_array_dtor_func_t */ |
---|
| 2179 | STANDARD_ZEND_EXTENSION_PROPERTIES |
---|
| 2180 | }; |
---|
| 2181 | |
---|
| 2182 | #ifndef ZEND_EXT_API |
---|
| 2183 | # define ZEND_EXT_API ZEND_DLEXPORT |
---|
| 2184 | #endif |
---|
| 2185 | #if COMPILE_DL_XCACHE |
---|
| 2186 | ZEND_EXTENSION(); |
---|
| 2187 | #endif |
---|
| 2188 | /* }}} */ |
---|