| 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 "utils.h" |
|---|
| 33 | #include "const_string.h" |
|---|
| 34 | #include "opcode_spec.h" |
|---|
| 35 | |
|---|
| 36 | #ifdef DEBUG |
|---|
| 37 | # undef NDEBUG |
|---|
| 38 | # undef inline |
|---|
| 39 | # define inline |
|---|
| 40 | #else |
|---|
| 41 | # ifndef NDEBUG |
|---|
| 42 | # define NDEBUG |
|---|
| 43 | # endif |
|---|
| 44 | #endif |
|---|
| 45 | #include <assert.h> |
|---|
| 46 | |
|---|
| 47 | #define VAR_ENTRY_EXPIRED(pentry) ((pentry)->ttl && XG(request_time) > pentry->ctime + (pentry)->ttl) |
|---|
| 48 | #define CHECK(x, e) do { if ((x) == NULL) { zend_error(E_ERROR, "XCache: " e); goto err; } } while (0) |
|---|
| 49 | #define LOCK(x) xc_lock(x->lck) |
|---|
| 50 | #define UNLOCK(x) xc_unlock(x->lck) |
|---|
| 51 | |
|---|
| 52 | #define ENTER_LOCK_EX(x) \ |
|---|
| 53 | xc_lock(x->lck); \ |
|---|
| 54 | zend_try { \ |
|---|
| 55 | do |
|---|
| 56 | #define LEAVE_LOCK_EX(x) \ |
|---|
| 57 | while (0); \ |
|---|
| 58 | } zend_catch { \ |
|---|
| 59 | catched = 1; \ |
|---|
| 60 | } zend_end_try(); \ |
|---|
| 61 | xc_unlock(x->lck) |
|---|
| 62 | |
|---|
| 63 | #define ENTER_LOCK(x) do { \ |
|---|
| 64 | int catched = 0; \ |
|---|
| 65 | ENTER_LOCK_EX(x) |
|---|
| 66 | #define LEAVE_LOCK(x) \ |
|---|
| 67 | LEAVE_LOCK_EX(x); \ |
|---|
| 68 | if (catched) { \ |
|---|
| 69 | zend_bailout(); \ |
|---|
| 70 | } \ |
|---|
| 71 | } while(0) |
|---|
| 72 | |
|---|
| 73 | /* }}} */ |
|---|
| 74 | |
|---|
| 75 | /* {{{ globals */ |
|---|
| 76 | static char *xc_shm_scheme = NULL; |
|---|
| 77 | static char *xc_mmap_path = NULL; |
|---|
| 78 | static char *xc_coredump_dir = NULL; |
|---|
| 79 | |
|---|
| 80 | static xc_hash_t xc_php_hcache = {0}; |
|---|
| 81 | static xc_hash_t xc_php_hentry = {0}; |
|---|
| 82 | static xc_hash_t xc_var_hcache = {0}; |
|---|
| 83 | static xc_hash_t xc_var_hentry = {0}; |
|---|
| 84 | |
|---|
| 85 | static zend_ulong xc_php_ttl = 0; |
|---|
| 86 | static zend_ulong xc_var_maxttl = 0; |
|---|
| 87 | |
|---|
| 88 | enum { xc_deletes_gc_interval = 120 }; |
|---|
| 89 | static zend_ulong xc_php_gc_interval = 0; |
|---|
| 90 | static zend_ulong xc_var_gc_interval = 0; |
|---|
| 91 | |
|---|
| 92 | /* total size */ |
|---|
| 93 | static zend_ulong xc_php_size = 0; |
|---|
| 94 | static zend_ulong xc_var_size = 0; |
|---|
| 95 | |
|---|
| 96 | static xc_cache_t **xc_php_caches = NULL; |
|---|
| 97 | static xc_cache_t **xc_var_caches = NULL; |
|---|
| 98 | |
|---|
| 99 | static zend_bool xc_initized = 0; |
|---|
| 100 | static zend_compile_file_t *origin_compile_file = NULL; |
|---|
| 101 | static zend_compile_file_t *old_compile_file = NULL; |
|---|
| 102 | static zend_llist_element *xc_llist_zend_extension = NULL; |
|---|
| 103 | |
|---|
| 104 | static zend_bool xc_test = 0; |
|---|
| 105 | static zend_bool xc_readonly_protection = 0; |
|---|
| 106 | |
|---|
| 107 | zend_bool xc_have_op_array_ctor = 0; |
|---|
| 108 | |
|---|
| 109 | static zend_bool xc_module_gotup = 0; |
|---|
| 110 | static zend_bool xc_zend_extension_gotup = 0; |
|---|
|
|---|