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