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