File: utils.h

package info (click to toggle)
xcache 2.0.0-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,724 kB
  • sloc: ansic: 8,175; php: 4,557; awk: 285; sh: 135; makefile: 75
file content (192 lines) | stat: -rw-r--r-- 5,599 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include "php.h"
#include "xcache.h"

#ifdef XCACHE_DEBUG
#	define IFDEBUG(x) (x)
int xc_vtrace(const char *fmt, va_list args);
int xc_trace(const char *fmt, ...) ZEND_ATTRIBUTE_PTR_FORMAT(printf, 1, 2);

#	ifdef ZEND_WIN32
static inline int TRACE(const char *fmt, ...) 
{
	va_list args;
	int ret;

	va_start(args, fmt);
	ret = xc_vtrace(fmt, args);
	va_end(args);
	return ret;
}
#	else
#		define TRACE(fmt, ...) \
		xc_trace("%s:%d: " fmt "\r\n", __FILE__, __LINE__, __VA_ARGS__)
#	endif /* ZEND_WIN32 */
#   undef NDEBUG
#   undef inline
#   define inline
#else /* XCACHE_DEBUG */

#	ifdef ZEND_WIN32
static inline int TRACE_DUMMY(const char *fmt, ...)
{
	return 0;
}
#		define TRACE 1 ? 0 : TRACE_DUMMY
#	else
#		define TRACE(fmt, ...) do { } while (0)
#	endif /* ZEND_WIN32 */

#	define IFDEBUG(x) do { } while (0)
#endif /* XCACHE_DEBUG */
#include <assert.h>

int xc_util_init(int module_number TSRMLS_DC);
void xc_util_destroy();

typedef struct {
	int alloc;
	zend_op_array *op_array;
	HashTable *function_table;
	HashTable *class_table;
} xc_compile_result_t;

xc_compile_result_t *xc_compile_result_init(xc_compile_result_t *cr,
		zend_op_array *op_array,
		HashTable *function_table,
		HashTable *class_table);
void xc_compile_result_free(xc_compile_result_t *cr);
xc_compile_result_t *xc_compile_result_init_cur(xc_compile_result_t *cr, zend_op_array *op_array TSRMLS_DC);
/* apply func */
int xc_apply_function(zend_function *zf, apply_func_t applyer TSRMLS_DC);
int xc_apply_class(zend_class_entry *ce, apply_func_t applyer TSRMLS_DC);
int xc_apply_op_array(xc_compile_result_t *cr, apply_func_t applyer TSRMLS_DC);

int xc_undo_pass_two(zend_op_array *op_array TSRMLS_DC);
int xc_redo_pass_two(zend_op_array *op_array TSRMLS_DC);
int xc_fix_opcode(zend_op_array *op_array TSRMLS_DC);
int xc_undo_fix_opcode(zend_op_array *op_array TSRMLS_DC);
zend_uchar xc_get_fixed_opcode(zend_uchar opcode, int line);

int 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);

/* installer */
#ifdef HAVE_XCACHE_CONSTANT
void xc_install_constant(ZEND_24(NOTHING, const) char *filename, zend_constant *constant, zend_uchar type, const24_zstr key, uint len, ulong h TSRMLS_DC);
#endif
void xc_install_function(ZEND_24(NOTHING, const) char *filename, zend_function *func, zend_uchar type, const24_zstr key, uint len, ulong h TSRMLS_DC);
ZESW(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);

#if defined(E_STRICT) || defined(E_DEPRECATED)
#define XCACHE_ERROR_CACHING
#endif

/* sandbox */
typedef struct {
	int alloc;
	ZEND_24(NOTHING, const) char *filename;

	HashTable orig_included_files;
	HashTable *tmp_included_files;

#ifdef HAVE_XCACHE_CONSTANT
	HashTable *orig_zend_constants;
	HashTable tmp_zend_constants;
#endif
	HashTable *orig_function_table;
	HashTable *orig_class_table;
	HashTable *orig_auto_globals;
	HashTable tmp_function_table;
	HashTable tmp_class_table;
	HashTable tmp_auto_globals;
#ifdef HAVE_XCACHE_CONSTANT
	Bucket    *tmp_internal_constant_tail;
#endif
	Bucket    *tmp_internal_function_tail;
	Bucket    *tmp_internal_class_tail;

#ifdef XCACHE_ERROR_CACHING
	int orig_user_error_handler_error_reporting;
	zend_uint compilererror_cnt;
	zend_uint compilererror_size;
	xc_compilererror_t *compilererrors;
#endif

#ifdef ZEND_COMPILE_IGNORE_INTERNAL_CLASSES
	zend_uint orig_compiler_options;
#endif
} xc_sandbox_t;

typedef enum _xc_install_action_t {
    XC_NoInstall,
    XC_Install,
    XC_InstallNoBinding
} xc_install_action_t;

void xc_zend_class_add_ref(zend_class_entry ZESW(*ce, **ce));
xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, ZEND_24(NOTHING, const) char *filename TSRMLS_DC);
void xc_sandbox_free(xc_sandbox_t *sandbox, xc_install_action_t install TSRMLS_DC);

typedef zend_bool (*xc_if_func_t)(void *data);

void xc_hash_copy_if(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size, xc_if_func_t checker);
#ifdef HAVE_XCACHE_CONSTANT
void xc_zend_constant_ctor(zend_constant *c);
void xc_zend_constant_dtor(zend_constant *c);
void xc_copy_internal_zend_constants(HashTable *target, HashTable *source);
#endif

#ifndef ZEND_ENGINE_2_3
size_t xc_dirname(char *path, size_t len);
#define zend_dirname xc_dirname
long xc_atol(const char *str, int len);
#define zend_atol xc_atol
#endif

typedef struct {
	zend_uint size;
	zend_uint cnt;
	void *data;
} xc_vector_t;

#define xc_vector_init(type, vector) do { \
	(vector)->cnt = 0;     \
	(vector)->size = 0;    \
	(vector)->data = NULL; \
} while (0)

#define xc_vector_add(type, vector, value) do { \
	if ((vector)->cnt == (vector)->size) { \
		if ((vector)->size) { \
			(vector)->size <<= 1; \
			(vector)->data = erealloc((vector)->data, sizeof(type) * (vector)->size); \
		} \
		else { \
			(vector)->size = 8; \
			(vector)->data = emalloc(sizeof(type) * (vector)->size); \
		} \
	} \
	((type *) (vector)->data)[(vector)->cnt++] = value; \
} while (0)

static inline void *xc_vector_detach_impl(xc_vector_t *vector)
{
	void *data = vector->data;
	vector->data = NULL;
	vector->size = 0;
	vector->cnt = 0;
	return data;
}

#define xc_vector_detach(type, vector) ((type *) xc_vector_detach_impl(vector))

static inline void xc_vector_free_impl(xc_vector_t *vector TSRMLS_DC)
{
	if (vector->data) {
		efree(vector->data);
	}
	vector->size = 0;
	vector->cnt = 0;
}

#define xc_vector_free(type, vector) xc_vector_free_impl(vector TSRMLS_CC)