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