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