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