[1] | 1 | dnl {{{ === program start ======================================== |
---|
| 2 | divert(0) |
---|
| 3 | #include <string.h> |
---|
| 4 | #include <stdio.h> |
---|
| 5 | |
---|
| 6 | #include "php.h" |
---|
[189] | 7 | #include "zend_extensions.h" |
---|
[1] | 8 | #include "zend_compile.h" |
---|
| 9 | #include "zend_API.h" |
---|
[4] | 10 | #include "zend_ini.h" |
---|
[1] | 11 | |
---|
| 12 | #include "xcache.h" |
---|
| 13 | #include "align.h" |
---|
| 14 | #include "const_string.h" |
---|
| 15 | #include "processor.h" |
---|
| 16 | #include "stack.h" |
---|
| 17 | #include "xcache_globals.h" |
---|
| 18 | |
---|
[58] | 19 | #if defined(HARDENING_PATCH_HASH_PROTECT) && HARDENING_PATCH_HASH_PROTECT |
---|
| 20 | extern unsigned int zend_hash_canary; |
---|
| 21 | #endif |
---|
| 22 | |
---|
[1] | 23 | define(`SIZEOF_zend_uint', `sizeof(zend_uint)') |
---|
| 24 | define(`COUNTOF_zend_uint', `1') |
---|
| 25 | define(`SIZEOF_int', `sizeof(int)') |
---|
| 26 | define(`COUNTOF_int', `1') |
---|
| 27 | define(`SIZEOF_zend_function', `sizeof(zend_function)') |
---|
| 28 | define(`COUNTOF_zend_function', `1') |
---|
| 29 | define(`SIZEOF_zval_ptr', `sizeof(zval_ptr)') |
---|
| 30 | define(`COUNTOF_zval_ptr', `1') |
---|
[825] | 31 | define(`SIZEOF_zval_ptr_nullable', `sizeof(zval_ptr_nullable)') |
---|
| 32 | define(`COUNTOF_zval_ptr_nullable', `1') |
---|
[836] | 33 | define(`SIZEOF_zend_trait_alias_ptr', `sizeof(zend_trait_alias)') |
---|
| 34 | define(`COUNTOF_zend_trait_alias_ptr', `1') |
---|
| 35 | define(`SIZEOF_zend_trait_precedence_ptr', `sizeof(zend_trait_precedence)') |
---|
| 36 | define(`COUNTOF_zend_trait_precedence_ptr', `1') |
---|
[1] | 37 | define(`SIZEOF_xc_entry_name_t', `sizeof(xc_entry_name_t)') |
---|
| 38 | define(`COUNTOF_xc_entry_name_t', `1') |
---|
[843] | 39 | define(`SIZEOF_xc_ztstring', `sizeof(xc_ztstring)') |
---|
| 40 | define(`COUNTOF_xc_ztstring', `1') |
---|
[1] | 41 | |
---|
| 42 | ifdef(`XCACHE_ENABLE_TEST', ` |
---|
| 43 | #undef NDEBUG |
---|
| 44 | #include <assert.h> |
---|
[29] | 45 | m4_errprint(`AUTOCHECK INFO: runtime autocheck Enabled (debug build)') |
---|
| 46 | ', ` |
---|
| 47 | m4_errprint(`AUTOCHECK INFO: runtime autocheck Disabled (optimized build)') |
---|
[1] | 48 | ') |
---|
[300] | 49 | ifdef(`DEBUG_SIZE', `static int xc_totalsize = 0;') |
---|
| 50 | |
---|
[29] | 51 | sinclude(builddir`/structinfo.m4') |
---|
| 52 | |
---|
[1] | 53 | #ifndef NDEBUG |
---|
| 54 | # undef inline |
---|
| 55 | #define inline |
---|
| 56 | #endif |
---|
| 57 | |
---|
| 58 | typedef zval *zval_ptr; |
---|
[825] | 59 | typedef zval *zval_ptr_nullable; |
---|
[843] | 60 | typedef char *xc_ztstring; |
---|
[836] | 61 | #ifdef ZEND_ENGINE_2_4 |
---|
| 62 | typedef zend_trait_alias *zend_trait_alias_ptr; |
---|
| 63 | typedef zend_trait_precedence *zend_trait_precedence_ptr; |
---|
| 64 | #endif |
---|
| 65 | |
---|
[843] | 66 | typedef zend_uchar xc_zval_data_type; |
---|
| 67 | typedef int xc_op_type; |
---|
| 68 | typedef zend_uchar xc_opcode; |
---|
[103] | 69 | #ifdef IS_UNICODE |
---|
| 70 | typedef UChar zstr_uchar; |
---|
| 71 | #endif |
---|
| 72 | typedef char zstr_char; |
---|
[1] | 73 | |
---|
| 74 | #define MAX_DUP_STR_LEN 256 |
---|
| 75 | dnl }}} |
---|
[178] | 76 | /* export: typedef struct _xc_processor_t xc_processor_t; :export {{{ */ |
---|
| 77 | struct _xc_processor_t { |
---|
[1] | 78 | char *p; |
---|
| 79 | zend_uint size; |
---|
| 80 | HashTable strings; |
---|
| 81 | HashTable zvalptrs; |
---|
| 82 | zend_bool reference; /* enable if to deal with reference */ |
---|
[233] | 83 | zend_bool have_references; |
---|
[851] | 84 | const xc_entry_php_t *entry_php_src; |
---|
| 85 | const xc_entry_php_t *entry_php_dst; |
---|
[311] | 86 | const xc_entry_data_php_t *php_src; |
---|
| 87 | const xc_entry_data_php_t *php_dst; |
---|
| 88 | const xc_cache_t *cache; |
---|
[1] | 89 | const zend_class_entry *cache_ce; |
---|
[662] | 90 | zend_uint cache_class_index; |
---|
[1] | 91 | |
---|
[779] | 92 | const zend_op_array *active_op_array_src; |
---|
| 93 | zend_op_array *active_op_array_dst; |
---|
[1] | 94 | const zend_class_entry *active_class_entry_src; |
---|
| 95 | zend_class_entry *active_class_entry_dst; |
---|
[662] | 96 | zend_uint active_class_index; |
---|
| 97 | zend_uint active_op_array_index; |
---|
| 98 | const xc_op_array_info_t *active_op_array_infos_src; |
---|
[1] | 99 | |
---|
| 100 | zend_bool readonly_protection; /* wheather it's present */ |
---|
[877] | 101 | IFAUTOCHECK(xc_stack_t allocsizes;) |
---|
[1] | 102 | }; |
---|
| 103 | /* }}} */ |
---|
[836] | 104 | /* {{{ memsetptr */ |
---|
[877] | 105 | IFAUTOCHECK(`dnl |
---|
[836] | 106 | static void *memsetptr(void *mem, void *content, size_t n) |
---|
| 107 | { |
---|
| 108 | void **p = (void **) mem; |
---|
[844] | 109 | void **end = (void **) ((char *) mem + n); |
---|
[838] | 110 | while (p < end - sizeof(content)) { |
---|
[836] | 111 | *p = content; |
---|
| 112 | p += sizeof(content); |
---|
| 113 | } |
---|
[838] | 114 | if (p < end) { |
---|
| 115 | memset(p, -1, end - p); |
---|
| 116 | } |
---|
[836] | 117 | return mem; |
---|
| 118 | } |
---|
| 119 | ') |
---|
| 120 | /* }}} */ |
---|
[230] | 121 | #ifdef HAVE_XCACHE_DPRINT |
---|
[1] | 122 | static void xc_dprint_indent(int indent) /* {{{ */ |
---|
| 123 | { |
---|
| 124 | int i; |
---|
| 125 | for (i = 0; i < indent; i ++) { |
---|
| 126 | fprintf(stderr, " "); |
---|
| 127 | } |
---|
| 128 | } |
---|
[230] | 129 | /* }}} */ |
---|
| 130 | static void xc_dprint_str_len(const char *str, int len) /* {{{ */ |
---|
| 131 | { |
---|
[295] | 132 | const unsigned char *p = (const unsigned char *) str; |
---|
[230] | 133 | int i; |
---|
| 134 | for (i = 0; i < len; i ++) { |
---|
| 135 | if (p[i] < 32 || p[i] == 127) { |
---|
| 136 | fprintf(stderr, "\\%03o", (unsigned int) p[i]); |
---|
| 137 | } |
---|
| 138 | else { |
---|
| 139 | fputc(p[i], stderr); |
---|
| 140 | } |
---|
| 141 | } |
---|
| 142 | } |
---|
| 143 | /* }}} */ |
---|
[1] | 144 | #endif |
---|
[103] | 145 | /* {{{ xc_zstrlen_char */ |
---|
[844] | 146 | static inline int xc_zstrlen_char(const_zstr s) |
---|
[103] | 147 | { |
---|
| 148 | return strlen(ZSTR_S(s)); |
---|
| 149 | } |
---|
| 150 | /* }}} */ |
---|
| 151 | #ifdef IS_UNICODE |
---|
| 152 | /* {{{ xc_zstrlen_uchar */ |
---|
| 153 | static inline int xc_zstrlen_uchar(zstr s) |
---|
| 154 | { |
---|
[512] | 155 | return u_strlen(ZSTR_U(s)); |
---|
[103] | 156 | } |
---|
| 157 | /* }}} */ |
---|
| 158 | /* {{{ xc_zstrlen */ |
---|
[844] | 159 | static inline int xc_zstrlen(int type, const_zstr s) |
---|
[103] | 160 | { |
---|
| 161 | return type == IS_UNICODE ? xc_zstrlen_uchar(s) : xc_zstrlen_char(s); |
---|
| 162 | } |
---|
| 163 | /* }}} */ |
---|
| 164 | #else |
---|
| 165 | /* {{{ xc_zstrlen */ |
---|
| 166 | #define xc_zstrlen(dummy, s) xc_zstrlen_char(s) |
---|
| 167 | /* }}} */ |
---|
| 168 | #endif |
---|
[1] | 169 | /* {{{ xc_calc_string_n */ |
---|
[878] | 170 | REDEF(`PROCESSOR_TYPE', `calc') |
---|
[690] | 171 | #undef C_RELAYLINE |
---|
| 172 | #define C_RELAYLINE |
---|
[877] | 173 | IFAUTOCHECK(` |
---|
[690] | 174 | #undef C_RELAYLINE |
---|
| 175 | #define C_RELAYLINE , __LINE__ |
---|
| 176 | ') |
---|
[877] | 177 | static inline void xc_calc_string_n(xc_processor_t *processor, zend_uchar type, const_zstr str, long size IFAUTOCHECK(`, int relayline')) { |
---|
[1] | 178 | pushdef(`__LINE__', `relayline') |
---|
| 179 | int realsize = UNISW(size, (type == IS_UNICODE) ? UBYTES(size) : size); |
---|
[103] | 180 | long dummy = 1; |
---|
[1] | 181 | |
---|
| 182 | if (realsize > MAX_DUP_STR_LEN) { |
---|
| 183 | ALLOC(, char, realsize) |
---|
| 184 | } |
---|
[103] | 185 | else if (zend_u_hash_add(&processor->strings, type, str, size, (void *) &dummy, sizeof(dummy), NULL) == SUCCESS) { |
---|
[1] | 186 | /* new string */ |
---|
| 187 | ALLOC(, char, realsize) |
---|
| 188 | } |
---|
[877] | 189 | IFAUTOCHECK(` |
---|
[1] | 190 | else { |
---|
[103] | 191 | dnl fprintf(stderr, "dupstr %s\n", ZSTR_S(str)); |
---|
[1] | 192 | } |
---|
| 193 | ') |
---|
| 194 | popdef(`__LINE__') |
---|
| 195 | } |
---|
| 196 | /* }}} */ |
---|
| 197 | /* {{{ xc_store_string_n */ |
---|
[878] | 198 | REDEF(`PROCESSOR_TYPE', `store') |
---|
[877] | 199 | static inline zstr xc_store_string_n(xc_processor_t *processor, zend_uchar type, const_zstr str, long size IFAUTOCHECK(`, int relayline')) { |
---|
[1] | 200 | pushdef(`__LINE__', `relayline') |
---|
| 201 | int realsize = UNISW(size, (type == IS_UNICODE) ? UBYTES(size) : size); |
---|
[103] | 202 | zstr ret, *pret; |
---|
[1] | 203 | |
---|
| 204 | if (realsize > MAX_DUP_STR_LEN) { |
---|
[103] | 205 | ALLOC(ZSTR_V(ret), char, realsize) |
---|
| 206 | memcpy(ZSTR_V(ret), ZSTR_V(str), realsize); |
---|
| 207 | return ret; |
---|
[1] | 208 | } |
---|
[103] | 209 | |
---|
| 210 | if (zend_u_hash_find(&processor->strings, type, str, size, (void **) &pret) == SUCCESS) { |
---|
| 211 | return *pret; |
---|
[1] | 212 | } |
---|
[103] | 213 | |
---|
| 214 | /* new string */ |
---|
| 215 | ALLOC(ZSTR_V(ret), char, realsize) |
---|
| 216 | memcpy(ZSTR_V(ret), ZSTR_V(str), realsize); |
---|
| 217 | zend_u_hash_add(&processor->strings, type, str, size, (void *) &ret, sizeof(zstr), NULL); |
---|
| 218 | return ret; |
---|
| 219 | |
---|
[1] | 220 | popdef(`__LINE__') |
---|
| 221 | } |
---|
| 222 | /* }}} */ |
---|
| 223 | /* {{{ xc_get_class_num |
---|
| 224 | * return class_index + 1 |
---|
| 225 | */ |
---|
[178] | 226 | static zend_ulong xc_get_class_num(xc_processor_t *processor, zend_class_entry *ce) { |
---|
[90] | 227 | zend_ulong i; |
---|
[311] | 228 | const xc_entry_data_php_t *php = processor->php_src; |
---|
[1] | 229 | zend_class_entry *ceptr; |
---|
| 230 | |
---|
| 231 | if (processor->cache_ce == ce) { |
---|
[662] | 232 | return processor->cache_class_index + 1; |
---|
[1] | 233 | } |
---|
[311] | 234 | for (i = 0; i < php->classinfo_cnt; i ++) { |
---|
| 235 | ceptr = CestToCePtr(php->classinfos[i].cest); |
---|
[1] | 236 | if (ZCEP_REFCOUNT_PTR(ceptr) == ZCEP_REFCOUNT_PTR(ce)) { |
---|
| 237 | processor->cache_ce = ceptr; |
---|
[667] | 238 | processor->cache_class_index = i; |
---|
[1] | 239 | return i + 1; |
---|
| 240 | } |
---|
| 241 | } |
---|
| 242 | assert(0); |
---|
[90] | 243 | return (zend_ulong) -1; |
---|
[1] | 244 | } |
---|
[662] | 245 | define(`xc_get_class_num', `xc_get_class_numNOTDEFINED') |
---|
[1] | 246 | /* }}} */ |
---|
| 247 | /* {{{ xc_get_class */ |
---|
| 248 | #ifdef ZEND_ENGINE_2 |
---|
[178] | 249 | static zend_class_entry *xc_get_class(xc_processor_t *processor, zend_ulong class_num) { |
---|
[1] | 250 | /* must be parent or currrent class */ |
---|
[662] | 251 | assert(class_num <= processor->active_class_index + 1); |
---|
[311] | 252 | return CestToCePtr(processor->php_dst->classinfos[class_num - 1].cest); |
---|
[1] | 253 | } |
---|
| 254 | #endif |
---|
[662] | 255 | define(`xc_get_class', `xc_get_classNOTDEFINED') |
---|
[1] | 256 | /* }}} */ |
---|
| 257 | #ifdef ZEND_ENGINE_2 |
---|
| 258 | /* fix method on store */ |
---|
[507] | 259 | static void xc_fix_method(xc_processor_t *processor, zend_op_array *dst TSRMLS_DC) /* {{{ */ |
---|
[1] | 260 | { |
---|
| 261 | zend_function *zf = (zend_function *) dst; |
---|
| 262 | zend_class_entry *ce = processor->active_class_entry_dst; |
---|
[507] | 263 | const zend_class_entry *srcce = processor->active_class_entry_src; |
---|
[1] | 264 | |
---|
| 265 | /* Fixing up the default functions for objects here since |
---|
| 266 | * we need to compare with the newly allocated functions |
---|
| 267 | * |
---|
| 268 | * caveat: a sub-class method can have the same name as the |
---|
| 269 | * parent~s constructor and create problems. |
---|
| 270 | */ |
---|
| 271 | |
---|
| 272 | if (zf->common.fn_flags & ZEND_ACC_CTOR) { |
---|
| 273 | if (!ce->constructor) { |
---|
| 274 | ce->constructor = zf; |
---|
| 275 | } |
---|
| 276 | } |
---|
| 277 | else if (zf->common.fn_flags & ZEND_ACC_DTOR) { |
---|
| 278 | ce->destructor = zf; |
---|
| 279 | } |
---|
| 280 | else if (zf->common.fn_flags & ZEND_ACC_CLONE) { |
---|
| 281 | ce->clone = zf; |
---|
| 282 | } |
---|
| 283 | else { |
---|
[507] | 284 | pushdef(`SET_IF_SAME_NAMEs', ` |
---|
[1] | 285 | SET_IF_SAME_NAME(__get); |
---|
| 286 | SET_IF_SAME_NAME(__set); |
---|
[56] | 287 | #ifdef ZEND_ENGINE_2_1 |
---|
[1] | 288 | SET_IF_SAME_NAME(__unset); |
---|
| 289 | SET_IF_SAME_NAME(__isset); |
---|
[56] | 290 | #endif |
---|
[1] | 291 | SET_IF_SAME_NAME(__call); |
---|
[480] | 292 | #ifdef ZEND_CALLSTATIC_FUNC_NAME |
---|
| 293 | SET_IF_SAME_NAME(__callstatic); |
---|
| 294 | #endif |
---|
[94] | 295 | #if defined(ZEND_ENGINE_2_2) || PHP_MAJOR_VERSION >= 6 |
---|
[1] | 296 | SET_IF_SAME_NAME(__tostring); |
---|
| 297 | #endif |
---|
[507] | 298 | ') |
---|
| 299 | #ifdef IS_UNICODE |
---|
| 300 | if (UG(unicode)) { |
---|
| 301 | #define SET_IF_SAME_NAME(member) \ |
---|
| 302 | do { \ |
---|
[509] | 303 | if (srcce->member && u_strcmp(ZSTR_U(zf->common.function_name), ZSTR_U(srcce->member->common.function_name)) == 0) { \ |
---|
[507] | 304 | ce->member = zf; \ |
---|
| 305 | } \ |
---|
| 306 | } \ |
---|
| 307 | while(0) |
---|
[1] | 308 | |
---|
[507] | 309 | SET_IF_SAME_NAMEs() |
---|
[1] | 310 | #undef SET_IF_SAME_NAME |
---|
[507] | 311 | } |
---|
| 312 | else |
---|
| 313 | #endif |
---|
| 314 | do { |
---|
| 315 | #define SET_IF_SAME_NAME(member) \ |
---|
| 316 | do { \ |
---|
| 317 | if (srcce->member && strcmp(ZSTR_S(zf->common.function_name), ZSTR_S(srcce->member->common.function_name)) == 0) { \ |
---|
| 318 | ce->member = zf; \ |
---|
| 319 | } \ |
---|
| 320 | } \ |
---|
| 321 | while(0) |
---|
| 322 | |
---|
| 323 | SET_IF_SAME_NAMEs() |
---|
| 324 | #undef SET_IF_SAME_NAME |
---|
| 325 | } while (0); |
---|
| 326 | |
---|
| 327 | popdef(`SET_IF_SAME_NAMEs') |
---|
| 328 | |
---|
[1] | 329 | } |
---|
| 330 | } |
---|
| 331 | /* }}} */ |
---|
[199] | 332 | #endif |
---|
[195] | 333 | /* {{{ call op_array ctor handler */ |
---|
| 334 | extern zend_bool xc_have_op_array_ctor; |
---|
| 335 | static void xc_zend_extension_op_array_ctor_handler(zend_extension *extension, zend_op_array *op_array TSRMLS_DC) |
---|
| 336 | { |
---|
| 337 | if (extension->op_array_ctor) { |
---|
| 338 | extension->op_array_ctor(op_array); |
---|
| 339 | } |
---|
| 340 | } |
---|
| 341 | /* }}} */ |
---|
[719] | 342 | /* {{{ field name checker */ |
---|
[877] | 343 | IFAUTOCHECK(`dnl |
---|
[836] | 344 | static int xc_check_names(const char *file, int line, const char *functionName, const char **assert_names, int assert_names_count, HashTable *done_names) |
---|
[719] | 345 | { |
---|
| 346 | int errors = 0; |
---|
| 347 | if (assert_names_count) { |
---|
| 348 | int i; |
---|
| 349 | Bucket *b; |
---|
| 350 | |
---|
| 351 | for (i = 0; i < assert_names_count; ++i) { |
---|
[860] | 352 | if (!zend_u_hash_exists(done_names, IS_STRING, assert_names[i], strlen(assert_names[i]) + 1)) { |
---|
[719] | 353 | fprintf(stderr |
---|
| 354 | , "missing field at %s `#'%d %s`' : %s\n" |
---|
| 355 | , file, line, functionName |
---|
| 356 | , assert_names[i] |
---|
| 357 | ); |
---|
| 358 | ++errors; |
---|
| 359 | } |
---|
| 360 | } |
---|
| 361 | |
---|
| 362 | for (b = done_names->pListHead; b != NULL; b = b->pListNext) { |
---|
| 363 | int known = 0; |
---|
| 364 | int i; |
---|
| 365 | for (i = 0; i < assert_names_count; ++i) { |
---|
| 366 | if (strcmp(assert_names[i], BUCKET_KEY_S(b)) == 0) { |
---|
| 367 | known = 1; |
---|
| 368 | break; |
---|
| 369 | } |
---|
| 370 | } |
---|
| 371 | if (!known) { |
---|
| 372 | fprintf(stderr |
---|
| 373 | , "unknown field at %s `#'%d %s`' : %s\n" |
---|
| 374 | , file, line, functionName |
---|
| 375 | , BUCKET_KEY_S(b) |
---|
| 376 | ); |
---|
| 377 | ++errors; |
---|
| 378 | } |
---|
| 379 | } |
---|
| 380 | } |
---|
| 381 | return errors; |
---|
| 382 | } |
---|
| 383 | ') |
---|
| 384 | /* }}} */ |
---|
[1] | 385 | dnl ================ export API |
---|
[311] | 386 | define(`DEFINE_STORE_API', ` |
---|
[854] | 387 | /* export: $1 *xc_processor_store_$1(xc_cache_t *cache, $1 *src TSRMLS_DC); :export {{{ */ |
---|
| 388 | $1 *xc_processor_store_$1(xc_cache_t *cache, $1 *src TSRMLS_DC) { |
---|
[311] | 389 | $1 *dst; |
---|
[178] | 390 | xc_processor_t processor; |
---|
[1] | 391 | |
---|
| 392 | memset(&processor, 0, sizeof(processor)); |
---|
[233] | 393 | processor.reference = 1; |
---|
[854] | 394 | processor.cache = cache; |
---|
[1] | 395 | |
---|
[877] | 396 | IFAUTOCHECK(`xc_stack_init(&processor.allocsizes);') |
---|
[1] | 397 | |
---|
| 398 | /* calc size */ { |
---|
| 399 | zend_hash_init(&processor.strings, 0, NULL, NULL, 0); |
---|
| 400 | if (processor.reference) { |
---|
| 401 | zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0); |
---|
| 402 | } |
---|
| 403 | |
---|
| 404 | processor.size = 0; |
---|
| 405 | /* allocate */ |
---|
| 406 | processor.size = ALIGN(processor.size + sizeof(src[0])); |
---|
| 407 | |
---|
[311] | 408 | xc_calc_$1(&processor, src TSRMLS_CC); |
---|
[1] | 409 | if (processor.reference) { |
---|
| 410 | zend_hash_destroy(&processor.zvalptrs); |
---|
| 411 | } |
---|
| 412 | zend_hash_destroy(&processor.strings); |
---|
| 413 | } |
---|
[856] | 414 | src->ifelse( |
---|
| 415 | `$1', `xc_entry_data_php_t', `', |
---|
| 416 | `', `', entry.)size = processor.size; |
---|
[851] | 417 | ifelse( |
---|
[854] | 418 | `$1', `xc_entry_var_t', `src->have_references = processor.have_references;', |
---|
[851] | 419 | `$1', `xc_entry_data_php_t', `src->have_references = processor.have_references;' |
---|
| 420 | ) |
---|
[1] | 421 | |
---|
[877] | 422 | IFAUTOCHECK(`xc_stack_reverse(&processor.allocsizes);') |
---|
[1] | 423 | /* store {{{ */ |
---|
| 424 | { |
---|
[877] | 425 | IFAUTOCHECK(`char *oldp;') |
---|
[1] | 426 | zend_hash_init(&processor.strings, 0, NULL, NULL, 0); |
---|
| 427 | if (processor.reference) { |
---|
| 428 | zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0); |
---|
| 429 | } |
---|
| 430 | |
---|
| 431 | /* mem :) */ |
---|
[311] | 432 | processor.p = (char *) processor.cache->mem->handlers->malloc(processor.cache->mem, processor.size); |
---|
[1] | 433 | if (processor.p == NULL) { |
---|
| 434 | dst = NULL; |
---|
| 435 | goto err_alloc; |
---|
| 436 | } |
---|
[877] | 437 | IFAUTOCHECK(`oldp = processor.p;') |
---|
[1] | 438 | assert(processor.p == (char *) ALIGN(processor.p)); |
---|
| 439 | |
---|
| 440 | /* allocate */ |
---|
[311] | 441 | dst = ($1 *) processor.p; |
---|
[1] | 442 | processor.p = (char *) ALIGN(processor.p + sizeof(dst[0])); |
---|
| 443 | |
---|
[311] | 444 | xc_store_$1(&processor, dst, src TSRMLS_CC); |
---|
[877] | 445 | IFAUTOCHECK(` { |
---|
[1] | 446 | int real = processor.p - oldp; |
---|
| 447 | int should = processor.size; |
---|
| 448 | if (real != processor.size) { |
---|
| 449 | fprintf(stderr, "real %d - should %d = %d\n", real, should, real - should); |
---|
| 450 | abort(); |
---|
| 451 | } |
---|
| 452 | }') |
---|
| 453 | err_alloc: |
---|
| 454 | if (processor.reference) { |
---|
| 455 | zend_hash_destroy(&processor.zvalptrs); |
---|
| 456 | } |
---|
| 457 | zend_hash_destroy(&processor.strings); |
---|
| 458 | } |
---|
| 459 | /* }}} */ |
---|
| 460 | |
---|
[877] | 461 | IFAUTOCHECK(`xc_stack_destroy(&processor.allocsizes);') |
---|
[1] | 462 | |
---|
| 463 | return dst; |
---|
| 464 | } |
---|
| 465 | /* }}} */ |
---|
[311] | 466 | ') |
---|
[856] | 467 | DEFINE_STORE_API(`xc_entry_var_t') |
---|
[851] | 468 | DEFINE_STORE_API(`xc_entry_php_t') |
---|
[311] | 469 | DEFINE_STORE_API(`xc_entry_data_php_t') |
---|
[851] | 470 | /* export: xc_entry_php_t *xc_processor_restore_xc_entry_php_t(xc_entry_php_t *dst, const xc_entry_php_t *src TSRMLS_DC); :export {{{ */ |
---|
| 471 | xc_entry_php_t *xc_processor_restore_xc_entry_php_t(xc_entry_php_t *dst, const xc_entry_php_t *src TSRMLS_DC) { |
---|
[178] | 472 | xc_processor_t processor; |
---|
[1] | 473 | |
---|
| 474 | memset(&processor, 0, sizeof(processor)); |
---|
[851] | 475 | xc_restore_xc_entry_php_t(&processor, dst, src TSRMLS_CC); |
---|
[311] | 476 | |
---|
| 477 | return dst; |
---|
| 478 | } |
---|
| 479 | /* }}} */ |
---|
[865] | 480 | /* export: xc_entry_data_php_t *xc_processor_restore_xc_entry_data_php_t(const xc_entry_php_t *entry_php, xc_entry_data_php_t *dst, const xc_entry_data_php_t *src, zend_bool readonly_protection TSRMLS_DC); :export {{{ */ |
---|
| 481 | xc_entry_data_php_t *xc_processor_restore_xc_entry_data_php_t(const xc_entry_php_t *entry_php, xc_entry_data_php_t *dst, const xc_entry_data_php_t *src, zend_bool readonly_protection TSRMLS_DC) { |
---|
[311] | 482 | xc_processor_t processor; |
---|
| 483 | |
---|
| 484 | memset(&processor, 0, sizeof(processor)); |
---|
[1] | 485 | processor.readonly_protection = readonly_protection; |
---|
[311] | 486 | /* this function is used for php data only */ |
---|
[233] | 487 | if (src->have_references) { |
---|
| 488 | processor.reference = 1; |
---|
| 489 | } |
---|
[865] | 490 | processor.entry_php_src = entry_php; |
---|
[1] | 491 | |
---|
[233] | 492 | if (processor.reference) { |
---|
| 493 | zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0); |
---|
| 494 | } |
---|
[311] | 495 | xc_restore_xc_entry_data_php_t(&processor, dst, src TSRMLS_CC); |
---|
[233] | 496 | if (processor.reference) { |
---|
| 497 | zend_hash_destroy(&processor.zvalptrs); |
---|
| 498 | } |
---|
[1] | 499 | return dst; |
---|
| 500 | } |
---|
| 501 | /* }}} */ |
---|
[856] | 502 | /* export: xc_entry_var_t *xc_processor_restore_xc_entry_var_t(xc_entry_var_t *dst, const xc_entry_var_t *src TSRMLS_DC); :export {{{ */ |
---|
| 503 | xc_entry_var_t *xc_processor_restore_xc_entry_var_t(xc_entry_var_t *dst, const xc_entry_var_t *src TSRMLS_DC) { |
---|
[851] | 504 | xc_processor_t processor; |
---|
| 505 | |
---|
| 506 | memset(&processor, 0, sizeof(processor)); |
---|
[856] | 507 | xc_restore_xc_entry_var_t(&processor, dst, src TSRMLS_CC); |
---|
[851] | 508 | |
---|
| 509 | return dst; |
---|
| 510 | } |
---|
| 511 | /* }}} */ |
---|
[233] | 512 | /* export: zval *xc_processor_restore_zval(zval *dst, const zval *src, zend_bool have_references TSRMLS_DC); :export {{{ */ |
---|
| 513 | zval *xc_processor_restore_zval(zval *dst, const zval *src, zend_bool have_references TSRMLS_DC) { |
---|
[178] | 514 | xc_processor_t processor; |
---|
[1] | 515 | |
---|
| 516 | memset(&processor, 0, sizeof(processor)); |
---|
[233] | 517 | processor.reference = have_references; |
---|
[1] | 518 | |
---|
[233] | 519 | if (processor.reference) { |
---|
| 520 | zend_hash_init(&processor.zvalptrs, 0, NULL, NULL, 0); |
---|
| 521 | dnl fprintf(stderr, "mark[%p] = %p\n", src, dst); |
---|
| 522 | zend_hash_add(&processor.zvalptrs, (char *)src, sizeof(src), (void*)&dst, sizeof(dst), NULL); |
---|
| 523 | } |
---|
[1] | 524 | xc_restore_zval(&processor, dst, src TSRMLS_CC); |
---|
[233] | 525 | if (processor.reference) { |
---|
| 526 | zend_hash_destroy(&processor.zvalptrs); |
---|
| 527 | } |
---|
[1] | 528 | |
---|
| 529 | return dst; |
---|
| 530 | } |
---|
| 531 | /* }}} */ |
---|
[851] | 532 | /* export: void xc_dprint(xc_entry_php_t *src, int indent TSRMLS_DC); :export {{{ */ |
---|
[230] | 533 | #ifdef HAVE_XCACHE_DPRINT |
---|
[851] | 534 | void xc_dprint(xc_entry_php_t *src, int indent TSRMLS_DC) { |
---|
[856] | 535 | IFDPRINT(`INDENT()`'fprintf(stderr, "xc_entry_php_t:src");') |
---|
| 536 | xc_dprint_xc_entry_php_t(src, indent TSRMLS_CC); |
---|
[1] | 537 | } |
---|
| 538 | #endif |
---|
| 539 | /* }}} */ |
---|