source: trunk/utils.h @ 938

Last change on this file since 938 was 938, checked in by moo, 22 months ago

finished sandbox rewrite

  • Property svn:eol-style set to native
File size: 4.8 KB
RevLine 
[1]1#include "php.h"
[305]2#include "xcache.h"
[1]3
[543]4#ifdef XCACHE_DEBUG
[305]5#   define IFDEBUG(x) (x)
[349]6int xc_vtrace(const char *fmt, va_list args);
[305]7int xc_trace(const char *fmt, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2);
[349]8
9#   ifdef ZEND_WIN32
10static inline int TRACE(const char *fmt, ...) 
11{
12    va_list args;
13    int ret;
14
15    va_start(args, fmt);
16    ret = xc_vtrace(fmt, args);
17    va_end(args);
18    return ret;
19}
20#   else
21#       define TRACE(fmt, ...) \
22        xc_trace("%s:%d: " fmt "\r\n", __FILE__, __LINE__, __VA_ARGS__)
23#   endif /* ZEND_WIN32 */
[305]24#   undef NDEBUG
25#   undef inline
26#   define inline
[543]27#else /* XCACHE_DEBUG */
[349]28
29#   ifdef ZEND_WIN32
[350]30static inline int TRACE_DUMMY(const char *fmt, ...)
[349]31{
32    return 0;
33}
[351]34#       define TRACE 1 ? 0 : TRACE_DUMMY
[349]35#   else
36#       define TRACE(fmt, ...) do { } while (0)
37#   endif /* ZEND_WIN32 */
38
[305]39#   define IFDEBUG(x) do { } while (0)
[543]40#endif /* XCACHE_DEBUG */
[305]41#include <assert.h>
42
[903]43int xc_util_init(int module_number TSRMLS_DC);
44void xc_util_destroy();
45
[1]46typedef struct {
47    zend_op_array *op_array;
48    HashTable *function_table;
49    HashTable *class_table;
50} xc_compile_result_t;
51
52xc_compile_result_t *xc_compile_result_init(xc_compile_result_t *cr,
53        zend_op_array *op_array,
54        HashTable *function_table,
55        HashTable *class_table);
56void xc_compile_result_free(xc_compile_result_t *cr);
57xc_compile_result_t *xc_compile_result_init_cur(xc_compile_result_t *cr, zend_op_array *op_array TSRMLS_DC);
58/* apply func */
59int xc_apply_function(zend_function *zf, apply_func_t applyer TSRMLS_DC);
60int xc_apply_class(zend_class_entry *ce, apply_func_t applyer TSRMLS_DC);
61int xc_apply_op_array(xc_compile_result_t *cr, apply_func_t applyer TSRMLS_DC);
62
63int xc_undo_pass_two(zend_op_array *op_array TSRMLS_DC);
64int xc_redo_pass_two(zend_op_array *op_array TSRMLS_DC);
65int xc_fix_opcode(zend_op_array *op_array TSRMLS_DC);
66int xc_undo_fix_opcode(zend_op_array *op_array TSRMLS_DC);
67zend_uchar xc_get_fixed_opcode(zend_uchar opcode, int line);
68
[212]69int xc_foreach_early_binding_class(zend_op_array *op_array, void (*callback)(zend_op *opline, int oplineno, void *data TSRMLS_DC), void *data TSRMLS_DC);
70
[1]71/* installer */
[95]72#ifdef HAVE_XCACHE_CONSTANT
[860]73void xc_install_constant(ZEND_24(NOTHING, const) char *filename, zend_constant *constant, zend_uchar type, const24_zstr key, uint len, ulong h TSRMLS_DC);
[95]74#endif
[860]75void xc_install_function(ZEND_24(NOTHING, const) char *filename, zend_function *func, zend_uchar type, const24_zstr key, uint len, ulong h TSRMLS_DC);
76ZESW(xc_cest_t *, void) xc_install_class(ZEND_24(NOTHING, const) char *filename, xc_cest_t *cest, int oplineno, zend_uchar type, const24_zstr key, uint len, ulong h TSRMLS_DC);
[1]77
[669]78#if defined(E_STRICT) || defined(E_DEPRECATED)
79#define XCACHE_ERROR_CACHING
80#endif
81
[937]82/* return op_array to install */
83typedef zend_op_array *(*xc_sandboxed_func_t)(void *data TSRMLS_DC);
84zend_op_array *xc_sandbox(xc_sandboxed_func_t sandboxed_func, void *data, ZEND_24(NOTHING, const) char *filename TSRMLS_DC);
[938]85const Bucket *xc_sandbox_user_function_begin(TSRMLS_D);
86const Bucket *xc_sandbox_user_class_begin(TSRMLS_D);
87zend_uint xc_sandbox_compilererror_cnt(TSRMLS_D);
[669]88#ifdef XCACHE_ERROR_CACHING
[938]89xc_compilererror_t *xc_sandbox_compilererrors(TSRMLS_D);
90zend_uint xc_sandbox_compilererror_cnt(TSRMLS_D);
[496]91#endif
[548]92
[345]93void xc_zend_class_add_ref(zend_class_entry ZESW(*ce, **ce));
[640]94
95typedef zend_bool (*xc_if_func_t)(void *data);
96
97void xc_hash_copy_if(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size, xc_if_func_t checker);
98#ifdef HAVE_XCACHE_CONSTANT
99void xc_zend_constant_ctor(zend_constant *c);
100void xc_zend_constant_dtor(zend_constant *c);
101void xc_copy_internal_zend_constants(HashTable *target, HashTable *source);
102#endif
[662]103
[671]104#ifndef ZEND_ENGINE_2_3
[847]105size_t xc_dirname(char *path, size_t len);
106#define zend_dirname xc_dirname
107long xc_atol(const char *str, int len);
108#define zend_atol xc_atol
[671]109#endif
110
[662]111typedef struct {
112    zend_uint size;
113    zend_uint cnt;
114    void *data;
115} xc_vector_t;
116
117#define xc_vector_init(type, vector) do { \
118    (vector)->cnt = 0;     \
119    (vector)->size = 0;    \
120    (vector)->data = NULL; \
121} while (0)
122
123#define xc_vector_add(type, vector, value) do { \
124    if ((vector)->cnt == (vector)->size) { \
125        if ((vector)->size) { \
126            (vector)->size <<= 1; \
127            (vector)->data = erealloc((vector)->data, sizeof(type) * (vector)->size); \
128        } \
129        else { \
130            (vector)->size = 8; \
131            (vector)->data = emalloc(sizeof(type) * (vector)->size); \
132        } \
133    } \
134    ((type *) (vector)->data)[(vector)->cnt++] = value; \
135} while (0)
136
137static inline void *xc_vector_detach_impl(xc_vector_t *vector)
138{
139    void *data = vector->data;
140    vector->data = NULL;
141    vector->size = 0;
142    vector->cnt = 0;
143    return data;
144}
145
146#define xc_vector_detach(type, vector) ((type *) xc_vector_detach_impl(vector))
147
148static inline void xc_vector_free_impl(xc_vector_t *vector TSRMLS_DC)
149{
150    if (vector->data) {
151        efree(vector->data);
152    }
153    vector->size = 0;
154    vector->cnt = 0;
155}
156
157#define xc_vector_free(type, vector) xc_vector_free_impl(vector TSRMLS_CC)
158
Note: See TracBrowser for help on using the repository browser.