source: trunk/processor/processor.m4 @ 1281

Last change on this file since 1281 was 1281, checked in by moo, 12 months ago

remove php 4 support completely

  • Property svn:eol-style set to native
File size: 29.0 KB
Line 
1dnl ================
2/* {{{ Pre-declare */
3DECL_STRUCT_P_FUNC(`zval')
4DECL_STRUCT_P_FUNC(`zval_ptr')
5DECL_STRUCT_P_FUNC(`zval_ptr_nullable')
6DECL_STRUCT_P_FUNC(`zend_op_array')
7DECL_STRUCT_P_FUNC(`zend_class_entry')
8#ifdef HAVE_XCACHE_CONSTANT
9DECL_STRUCT_P_FUNC(`zend_constant')
10#endif
11DECL_STRUCT_P_FUNC(`zend_function')
12DECL_STRUCT_P_FUNC(`xc_entry_var_t')
13DECL_STRUCT_P_FUNC(`xc_entry_php_t')
14DECL_STRUCT_P_FUNC(`zend_property_info')
15/* }}} */
16dnl ====================================================
17#ifdef IS_CV
18DEF_STRUCT_P_FUNC(`zend_compiled_variable', , `dnl {{{
19    PROCESS(int, name_len)
20    PROC_ZSTRING_L(, name, name_len)
21    PROCESS(ulong, hash_value)
22')
23dnl }}}
24#endif
25DEF_STRUCT_P_FUNC(`zend_uint', , `dnl {{{
26    IFCOPY(`dst[0] = src[0];')
27    IFDPRINT(`
28        INDENT()
29        fprintf(stderr, "%u\n", src[0]);
30    ')
31    DONE_SIZE(sizeof(src[0]))
32')
33dnl }}}
34DEF_STRUCT_P_FUNC(`zend_try_catch_element', , `dnl {{{
35    PROCESS(zend_uint, try_op)
36    PROCESS(zend_uint, catch_op)
37#ifdef ZEND_ENGINE_2_5
38    PROCESS(zend_uint, finally_op)
39    PROCESS(zend_uint, finally_end)
40#endif
41')
42dnl }}}
43DEF_STRUCT_P_FUNC(`zend_brk_cont_element', , `dnl {{{
44#ifdef ZEND_ENGINE_2_2
45    PROCESS(int, start)
46#endif
47    PROCESS(int, cont)
48    PROCESS(int, brk)
49    PROCESS(int, parent)
50')
51dnl }}}
52DEF_HASH_TABLE_FUNC(`HashTable_zval_ptr',           `zval_ptr')
53DEF_HASH_TABLE_FUNC(`HashTable_zend_function',      `zend_function')
54DEF_HASH_TABLE_FUNC(`HashTable_zend_property_info', `zend_property_info')
55DEF_STRUCT_P_FUNC(`zval', , `dnl {{{
56    IFDASM(`do {
57        zval_dtor(dst);
58        *dst = *src;
59        zval_copy_ctor(dst);
60        Z_SET_REFCOUNT(*dst, 1);
61        DONE(value)
62        DONE(type)
63#ifdef ZEND_ENGINE_2_3
64        DONE(is_ref__gc)
65        DONE(refcount__gc)
66#else
67        DONE(is_ref)
68        DONE(refcount)
69#endif
70    } while(0);
71    ', `
72        dnl IFDASM else
73        /* Variable information */
74dnl {{{ zvalue_value
75        DISABLECHECK(`
76        switch ((Z_TYPE_P(src) & IS_CONSTANT_TYPE_MASK)) {
77            case IS_LONG:
78            case IS_RESOURCE:
79            case IS_BOOL:
80                PROCESS(long, value.lval)
81                break;
82            case IS_DOUBLE:
83                PROCESS(double, value.dval)
84                break;
85            case IS_NULL:
86                IFDPRINT(`INDENT()`'fprintf(stderr, "\tNULL\n");')
87                break;
88
89            case IS_CONSTANT:
90#ifdef IS_UNICODE
91                if (UG(unicode)) {
92                    goto proc_unicode;
93                }
94#endif
95            case IS_STRING:
96#ifdef FLAG_IS_BC
97            case FLAG_IS_BC:
98#endif
99                PROCESS(int, value.str.len)
100                PROC_STRING_L(value.str.val, value.str.len)
101                break;
102#ifdef IS_UNICODE
103            case IS_UNICODE:
104proc_unicode:
105                PROCESS(int32_t, value.uni.len)
106                PROC_ZSTRING_L(1, value.uni.val, value.uni.len)
107                break;
108#endif
109
110            case IS_ARRAY:
111            case IS_CONSTANT_ARRAY:
112                STRUCT_P(HashTable, value.ht, HashTable_zval_ptr)
113                break;
114
115            case IS_OBJECT:
116                IFNOTMEMCPY(`IFCOPY(`memcpy(dst, src, sizeof(src[0]));')')
117                dnl STRUCT(value.obj)
118                break;
119
120            default:
121                assert(0);
122        }
123        ')
124dnl }}}
125        DONE(value)
126        PROCESS(xc_zval_type_t, type)
127#ifdef ZEND_ENGINE_2_3
128        PROCESS(zend_uchar, is_ref__gc)
129#else
130        PROCESS(zend_uchar, is_ref)
131#endif
132
133#ifdef ZEND_ENGINE_2_3
134        PROCESS(zend_uint, refcount__gc)
135#else
136        PROCESS(zend_uint, refcount)
137#endif
138    ')dnl IFDASM
139')
140dnl }}}
141DEF_STRUCT_P_FUNC(`zval_ptr', , `dnl {{{
142    IFDASM(`
143        pushdefFUNC_NAME(`zval')
144        FUNC_NAME (dasm, dst, src[0] TSRMLS_CC);
145        popdef(`FUNC_NAME')
146    ', `
147        do {
148            IFCALCCOPY(`
149                if (processor->reference) {
150                    zval_ptr *ppzv;
151                    if (zend_hash_find(&processor->zvalptrs, (char *) &src[0], sizeof(src[0]), (void **) &ppzv) == SUCCESS) {
152                        IFCOPY(`
153                            dst[0] = *ppzv;
154                            /* *dst is updated */
155                            dnl fprintf(stderr, "*dst is set to %p, PROCESSOR_TYPE is_shm %d\n", dst[0], xc_is_shm(dst[0]));
156                        ')
157                        IFCALCSTORE(`processor->have_references = 1;')
158                        IFSTORE(`assert(xc_is_shm(dst[0]));')
159                        IFRESTORE(`assert(!xc_is_shm(dst[0]));')
160                        break;
161                    }
162                }
163            ')
164           
165            ALLOC(dst[0], zval)
166            IFCALCCOPY(`
167                if (processor->reference) {
168                    IFCALC(`
169                        /* make dummy */
170                        zval_ptr pzv = (zval_ptr)-1;
171                    ', `
172                        zval_ptr pzv = dst[0];
173                        FIXPOINTER_EX(zval, pzv)
174                    ')
175                    if (zend_hash_add(&processor->zvalptrs, (char *) &src[0], sizeof(src[0]), (void *) &pzv, sizeof(pzv), NULL) == SUCCESS) {
176                        /* first add, go on */
177                        dnl fprintf(stderr, "mark[%p] = %p\n", src[0], pzv);
178                    }
179                    else {
180                        assert(0);
181                    }
182                }
183            ')
184            IFCOPY(`
185                dnl fprintf(stderr, "copy from %p to %p\n", src[0], dst[0]);
186            ')
187            IFDPRINT(`INDENT()`'fprintf(stderr, "[%p] ", src[0]);')
188            STRUCT_P_EX(zval, dst[0], src[0], `[0]', `', ` ')
189            FIXPOINTER_EX(zval, dst[0])
190        } while (0);
191    ')
192    DONE_SIZE(sizeof(zval_ptr))
193')
194dnl }}}
195DEF_STRUCT_P_FUNC(`zval_ptr_nullable', , `dnl {{{
196    if (src[0]) {
197        STRUCT_P_EX(zval_ptr, dst, src, `', `', ` ')
198    }
199    else {
200        IFCOPY(`COPYNULL_EX(src[0], src)')
201    }
202    DONE_SIZE(sizeof(zval_ptr_nullable))
203')
204dnl }}}
205DEF_STRUCT_P_FUNC(`zend_arg_info', , `dnl {{{
206    PROCESS(zend_uint, name_len)
207    PROC_ZSTRING_L(, name, name_len)
208    PROCESS(zend_uint, class_name_len)
209    PROC_ZSTRING_L(, class_name, class_name_len)
210#ifdef ZEND_ENGINE_2_4
211    PROCESS(zend_uchar, type_hint)
212#else
213    PROCESS(zend_bool, array_type_hint)
214#endif
215    PROCESS(zend_bool, allow_null)
216    PROCESS(zend_bool, pass_by_reference)
217#ifndef ZEND_ENGINE_2_4
218    PROCESS(zend_bool, return_reference)
219    PROCESS(int, required_num_args)
220#endif
221')
222dnl }}}
223#ifdef HAVE_XCACHE_CONSTANT
224DEF_STRUCT_P_FUNC(`zend_constant', , `dnl {{{
225    STRUCT(zval, value)
226    PROCESS(int, flags)
227    PROCESS(uint, name_len)
228    pushdef(`estrndup', `zend_strndup')
229    PROC_ZSTRING_N(, name, name_len)
230    popdef(`estrndup')
231    PROCESS(int, module_number)
232')
233dnl }}}
234#endif
235DEF_STRUCT_P_FUNC(`zend_function', , `dnl {{{
236    DISABLECHECK(`
237    switch (src->type) {
238    case ZEND_INTERNAL_FUNCTION:
239    case ZEND_OVERLOADED_FUNCTION:
240        IFNOTMEMCPY(`IFCOPY(`memcpy(dst, src, sizeof(src[0]));')')
241        break;
242
243    case ZEND_USER_FUNCTION:
244    case ZEND_EVAL_CODE:
245        DONE(type)
246        STRUCT(zend_op_array, op_array)
247        break;
248
249    default:
250        assert(0);
251    }
252    ')
253    DONE_SIZE(sizeof(src[0]))
254')
255dnl }}}
256DEF_STRUCT_P_FUNC(`zend_property_info', , `dnl {{{
257    PROCESS(zend_uint, flags)
258    PROCESS(int, name_length)
259    PROC_ZSTRING_L(, name, name_length)
260    PROCESS(ulong, h)
261#ifdef ZEND_ENGINE_2_4
262    PROCESS(int, offset)
263#endif
264#ifdef ZEND_ENGINE_2_1
265    PROCESS(int, doc_comment_len)
266    PROC_ZSTRING_L(, doc_comment, doc_comment_len)
267#endif
268    dnl isnt in php6 yet
269#if defined(ZEND_ENGINE_2_2)
270    PROC_CLASS_ENTRY_P(ce)
271#endif
272')
273dnl }}}
274#ifdef ZEND_ENGINE_2_4
275DEF_STRUCT_P_FUNC(`zend_trait_method_reference', , `dnl {{{
276    PROCESS(unsigned int, mname_len)
277    PROC_STRING_L(method_name, mname_len)
278    COPYNULL(ce)
279    PROCESS(unsigned int, cname_len)
280    PROC_STRING_L(class_name, cname_len)
281')
282dnl }}}
283DEF_STRUCT_P_FUNC(`zend_trait_alias', , `dnl {{{
284    STRUCT_P(zend_trait_method_reference, trait_method)
285    PROCESS(unsigned int, alias_len)
286    PROC_STRING_L(alias, alias_len)
287    PROCESS(zend_uint, modifiers)
288#ifndef ZEND_ENGINE_2_5
289    COPYNULL(function)
290#endif
291')
292dnl }}}
293DEF_STRUCT_P_FUNC(`zend_trait_precedence', , `dnl {{{
294    STRUCT_P(zend_trait_method_reference, trait_method)
295    PROCESS_ARRAY(, xc_ztstring, exclude_from_classes, zend_class_entry*)
296#ifndef ZEND_ENGINE_2_5
297    COPYNULL(function)
298#endif
299')
300dnl }}}
301DEF_STRUCT_P_FUNC(`zend_trait_alias_ptr', , `dnl {{{
302    IFDASM(`
303        pushdefFUNC_NAME(`zend_trait_alias')
304        FUNC_NAME (dasm, dst, src[0] TSRMLS_CC);
305        popdef(`FUNC_NAME')
306    ', `
307        ALLOC(dst[0], zend_trait_alias)
308        STRUCT_P_EX(zend_trait_alias, dst[0], src[0], `[0]', `', ` ')
309        FIXPOINTER_EX(zend_trait_alias, dst[0])
310    ')
311    DONE_SIZE(sizeof(zend_trait_alias))
312')
313dnl }}}
314DEF_STRUCT_P_FUNC(`zend_trait_precedence_ptr', , `dnl {{{
315    IFDASM(`
316        pushdefFUNC_NAME(`zend_trait_precedence')
317        FUNC_NAME (dasm, dst, src[0] TSRMLS_CC);
318        popdef(`FUNC_NAME')
319    ', `
320        ALLOC(dst[0], zend_trait_precedence)
321        STRUCT_P_EX(zend_trait_precedence, dst[0], src[0], `[0]', `', ` ')
322        FIXPOINTER_EX(zend_trait_precedence, dst[0])
323    ')
324    DONE_SIZE(sizeof(zend_trait_precedence))
325')
326dnl }}}
327#endif
328DEF_STRUCT_P_FUNC(`zend_class_entry', , `dnl {{{
329    IFCALCCOPY(`
330        processor->active_class_entry_src = src;
331        IFCOPY(`processor->active_class_entry_dst = dst;')
332    ')
333    PROCESS(char, type)
334    PROCESS(zend_uint, name_length)
335    PROC_ZSTRING_L(, name, name_length)
336    PROC_CLASS_ENTRY_P(parent)
337    PROCESS(int, refcount)
338#ifndef ZEND_ENGINE_2_4
339    PROCESS(zend_bool, constants_updated)
340#endif
341    PROCESS(zend_uint, ce_flags)
342
343    STRUCT(HashTable, properties_info, HashTable_zend_property_info)
344
345#ifdef ZEND_ENGINE_2_4
346    STRUCT_ARRAY(int, default_properties_count, zval_ptr_nullable, default_properties_table)
347    PROCESS(int, default_properties_count)
348    STRUCT_ARRAY(int, default_static_members_count, zval_ptr_nullable, default_static_members_table)
349    PROCESS(int, default_static_members_count)
350    IFCOPY(`dst->static_members_table = dst->default_static_members_table;')
351    DONE(static_members_table)
352#else
353    IFCOPY(`dst->builtin_functions = src->builtin_functions;')
354    DONE(builtin_functions)
355    STRUCT(HashTable, default_properties, HashTable_zval_ptr)
356#   ifdef ZEND_ENGINE_2_1
357    STRUCT(HashTable, default_static_members, HashTable_zval_ptr)
358    IFCOPY(`dst->static_members = &dst->default_static_members;')
359    DONE(static_members)
360#   else
361    STRUCT_P(HashTable, static_members, HashTable_zval_ptr)
362#   endif
363#endif /* ZEND_ENGINE_2_4 */
364
365    STRUCT(HashTable, constants_table, HashTable_zval_ptr)
366
367#ifdef ZEND_ENGINE_2_2
368    dnl runtime binding: ADD_INTERFACE will deal with it
369    COPYNULL(`interfaces')
370    COPYZERO(`num_interfaces')
371
372#   ifdef ZEND_ENGINE_2_4
373    dnl runtime binding: ADD_TRAIT will deal with it
374    COPYNULL(traits)
375    COPYZERO(num_traits)
376    STRUCT_ARRAY(, , zend_trait_alias_ptr, trait_aliases)
377    STRUCT_ARRAY(, , zend_trait_precedence_ptr, trait_precedences)
378#   endif
379#else
380    IFRESTORE(`
381        if (src->num_interfaces) {
382            CALLOC(dst->interfaces, zend_class_entry*, src->num_interfaces)
383            DONE(`interfaces')
384        }
385        else {
386            COPYNULL(`interfaces')
387        }
388    ', `
389        DONE(`interfaces')
390    ')
391    PROCESS(zend_uint, num_interfaces)
392#endif
393
394#   ifdef ZEND_ENGINE_2_4
395    DISABLECHECK(`
396    IFRESTORE(`dst->info.user.filename = processor->entry_php_src->filepath;', `PROC_STRING(info.user.filename)')
397    PROCESS(zend_uint, info.user.line_start)
398    PROCESS(zend_uint, info.user.line_end)
399    PROCESS(zend_uint, info.user.doc_comment_len)
400    PROC_ZSTRING_L(, info.user.doc_comment, info.user.doc_comment_len)
401    ')
402    DONE(info)
403#   else
404    IFRESTORE(`dst->filename = processor->entry_php_src->filepath;DONE(filename)', `PROC_STRING(filename)')
405    PROCESS(zend_uint, line_start)
406    PROCESS(zend_uint, line_end)
407#       ifdef ZEND_ENGINE_2_1
408    PROCESS(zend_uint, doc_comment_len)
409    PROC_ZSTRING_L(, doc_comment, doc_comment_len)
410#       endif
411#   endif
412
413    /* # NOT DONE */
414    COPY(serialize_func)
415    COPY(unserialize_func)
416    COPY(iterator_funcs)
417    COPY(create_object)
418    COPY(get_iterator)
419    COPY(interface_gets_implemented)
420#   ifdef ZEND_ENGINE_2_3
421    COPY(get_static_method)
422#   endif
423    COPY(serialize)
424    COPY(unserialize)
425    /* deal with it inside xc_fix_method */
426    SETNULL(constructor)
427    COPY(destructor)
428    COPY(clone)
429    COPY(__get)
430    COPY(__set)
431/* should be >5.1 */
432#   ifdef ZEND_ENGINE_2_1
433    COPY(__unset)
434    COPY(__isset)
435#    if defined(ZEND_ENGINE_2_2) || PHP_MAJOR_VERSION >= 6
436    COPY(__tostring)
437#    endif
438#   endif
439    COPY(__call)
440#   ifdef ZEND_CALLSTATIC_FUNC_NAME
441    COPY(__callstatic)
442#   endif
443#   ifndef ZEND_ENGINE_2_4
444    /* # NOT DONE */
445    COPY(module)
446#   endif
447    dnl must do after SETNULL(constructor) and dst->parent
448    STRUCT(HashTable, function_table, HashTable_zend_function)
449    IFRESTORE(`dst->function_table.pDestructor = ZEND_FUNCTION_DTOR;')
450    IFCALCCOPY(`
451        processor->active_class_entry_src = NULL;
452        IFCOPY(`processor->active_class_entry_dst = NULL;')
453    ')
454')
455dnl }}}
456#ifdef ZEND_ENGINE_2_4
457undefine(`UNION_znode_op')
458define(`UNION_znode_op', `dnl {{{
459#ifndef NDEBUG
460    switch ((src->$1_type ifelse($1, `result', & ~EXT_TYPE_UNUSED))) {
461    case IS_CONST:
462    case IS_VAR:
463    case IS_CV:
464    case IS_TMP_VAR:
465    case IS_UNUSED:
466        break;
467
468    default:
469        assert(0);
470    }
471#endif
472
473    dnl dirty dispatch
474    DISABLECHECK(`
475    switch ((src->$1_type ifelse($1, `result', & ~EXT_TYPE_UNUSED))) {
476        case IS_CONST:
477            ifelse($1, `result', `
478                PROCESS(zend_uint, $1.constant)
479            ', `
480                IFDASM(`{
481                    zval *zv;
482                    ALLOC_INIT_ZVAL(zv);
483                    *zv = dasm->active_op_array_src->literals[src->$1.constant].constant;
484                    zval_copy_ctor(zv);
485                    add_assoc_zval_ex(dst, ZEND_STRS("$1.constant"), zv);
486                }
487                ', `
488                    IFCOPY(`
489                        dst->$1 = src->$1;
490                    ', `
491                        PROCESS(zend_uint, $1.constant)
492                    ')
493                ')
494            ')
495            break;
496        IFCOPY(`
497            IFNOTMEMCPY(`
498                default:
499                    $1 = $2;
500            ')
501        ', `
502        case IS_VAR:
503        case IS_TMP_VAR:
504        case IS_CV:
505            PROCESS(zend_uint, $1.var)
506            break;
507        case IS_UNUSED:
508            IFDASM(`PROCESS(zend_uint, $1.var)')
509            PROCESS(zend_uint, $1.opline_num)
510            break;
511        ')
512    }
513    ')
514    DONE($1)
515')
516dnl }}}
517#else
518DEF_STRUCT_P_FUNC(`znode', , `dnl {{{
519    PROCESS(xc_op_type, op_type)
520
521#ifdef IS_CV
522#   define XCACHE_IS_CV IS_CV
523#else
524/* compatible with zend optimizer */
525#   define XCACHE_IS_CV 16
526#endif
527    assert(src->op_type == IS_CONST ||
528        src->op_type == IS_VAR ||
529        src->op_type == XCACHE_IS_CV ||
530        src->op_type == IS_TMP_VAR ||
531        src->op_type == IS_UNUSED);
532    dnl dirty dispatch
533    DISABLECHECK(`
534    switch (src->op_type) {
535        case IS_CONST:
536            STRUCT(zval, u.constant)
537            break;
538        IFCOPY(`
539            IFNOTMEMCPY(`
540                default:
541                    memcpy(&dst->u, &src->u, sizeof(src->u));
542            ')
543        ', `
544        case IS_VAR:
545        case IS_TMP_VAR:
546        case XCACHE_IS_CV:
547            PROCESS(zend_uint, u.var)
548            PROCESS(zend_uint, u.EA.type)
549            break;
550        case IS_UNUSED:
551            IFDASM(`PROCESS(zend_uint, u.var)')
552            PROCESS(zend_uint, u.opline_num)
553            PROCESS(zend_uint, u.EA.type)
554            break;
555        ')
556    }
557    ')
558    DONE(u)
559#if 0
560    DONE(EA)
561#endif
562#undef XCACHE_IS_CV
563')
564dnl }}}
565#endif
566DEF_STRUCT_P_FUNC(`zend_op', , `dnl {{{
567    PROCESS(xc_opcode, opcode)
568#ifdef ZEND_ENGINE_2_4
569    IFRESTORE(`', `
570    switch (src->opcode) {
571    case ZEND_BIND_TRAITS:
572        ((zend_op *) src)->op2_type = IS_UNUSED;
573        break;
574    }
575    ')
576    UNION_znode_op(result)
577    UNION_znode_op(op1)
578    UNION_znode_op(op2)
579#else
580    STRUCT(znode, result)
581    STRUCT(znode, op1)
582    STRUCT(znode, op2)
583#endif
584    PROCESS(ulong, extended_value)
585    PROCESS(uint, lineno)
586#ifdef ZEND_ENGINE_2_1
587#ifdef ZEND_ENGINE_2_4
588    PROCESS(zend_uchar, op1_type)
589    PROCESS(zend_uchar, op2_type)
590    PROCESS(zend_uchar, result_type)
591#endif
592    IFCOPY(`
593        assert(processor->active_op_array_src);
594        assert(processor->active_op_array_dst);
595#ifdef ZEND_ENGINE_2_4
596        pushdef(`UNION_znode_op_literal', `
597            if (src->$1_type == IS_CONST) {
598                dst->$1.constant = src->$1.literal - processor->active_op_array_src->literals;
599                dst->$1.literal = &processor->active_op_array_dst->literals[dst->$1.constant];
600            }
601        ')
602        UNION_znode_op_literal(op1)
603        UNION_znode_op_literal(op2)
604#endif
605        popdef(`UNION_znode_op_literal')
606        switch (src->opcode) {
607#ifdef ZEND_GOTO
608            case ZEND_GOTO:
609#endif
610            case ZEND_JMP:
611#ifdef ZEND_FAST_CALL
612            case ZEND_FAST_CALL:
613#endif
614                assert(Z_OP(src->op1).jmp_addr >= processor->active_op_array_src->opcodes && Z_OP(src->op1).jmp_addr - processor->active_op_array_src->opcodes < processor->active_op_array_src->last);
615                Z_OP(dst->op1).jmp_addr = processor->active_op_array_dst->opcodes + (Z_OP(src->op1).jmp_addr - processor->active_op_array_src->opcodes);
616                assert(Z_OP(dst->op1).jmp_addr >= processor->active_op_array_dst->opcodes && Z_OP(dst->op1).jmp_addr - processor->active_op_array_dst->opcodes < processor->active_op_array_dst->last);
617                break;
618
619            case ZEND_JMPZ:
620            case ZEND_JMPNZ:
621            case ZEND_JMPZ_EX:
622            case ZEND_JMPNZ_EX:
623#ifdef ZEND_JMP_SET
624            case ZEND_JMP_SET:
625#endif
626#ifdef ZEND_JMP_SET_VAR
627            case ZEND_JMP_SET_VAR:
628#endif
629                assert(Z_OP(src->op2).jmp_addr >= processor->active_op_array_src->opcodes && Z_OP(src->op2).jmp_addr - processor->active_op_array_src->opcodes < processor->active_op_array_src->last);
630                Z_OP(dst->op2).jmp_addr = processor->active_op_array_dst->opcodes + (Z_OP(src->op2).jmp_addr - processor->active_op_array_src->opcodes);
631                assert(Z_OP(dst->op2).jmp_addr >= processor->active_op_array_dst->opcodes && Z_OP(dst->op2).jmp_addr - processor->active_op_array_dst->opcodes < processor->active_op_array_dst->last);
632                break;
633
634            default:
635                break;
636        }
637    ')
638    PROCESS(opcode_handler_t, handler)
639#endif
640')
641dnl }}}
642#ifdef ZEND_ENGINE_2_4
643DEF_STRUCT_P_FUNC(`zend_literal', , `dnl {{{
644    STRUCT(zval, constant)
645    PROCESS(zend_ulong, hash_value)
646    PROCESS(zend_uint,  cache_slot)
647')
648dnl }}}
649#endif
650DEF_STRUCT_P_FUNC(`zend_op_array', , `dnl {{{
651    IFCOPY(`
652        processor->active_op_array_dst = dst;
653        processor->active_op_array_src = src;
654    ')
655    IFDASM(`
656        dasm->active_op_array_src = src;
657    ')
658    {
659    IFRESTORE(`
660    const xc_op_array_info_t *op_array_info = &processor->active_op_array_infos_src[processor->active_op_array_index++];
661    dnl shadow copy must NOT meet:
662    dnl readonly_protection=on
663    dnl main op_array && have early binding
664#ifdef ZEND_COMPILE_DELAYED_BINDING
665    zend_bool need_early_binding = 0;
666#else
667    zend_bool need_early_binding = processor->php_src->have_early_binding;
668#endif
669    zend_bool shallow_copy = !processor->readonly_protection && !(src == processor->php_src->op_array && need_early_binding);
670    if (shallow_copy) {
671        zend_bool gc_arg_info = 0;
672        zend_bool gc_opcodes  = 0;
673#ifdef ZEND_ENGINE_2_4
674        zend_bool gc_literals = 0;
675#endif
676        /* really fast shallow copy */
677        memcpy(dst, src, sizeof(src[0]));
678        dst->refcount[0] = 1000;
679#ifdef ZEND_ACC_ALIAS
680        if ((processor->active_class_entry_src && (processor->active_class_entry_src->ce_flags & ZEND_ACC_TRAIT))) {
681            PROC_ZSTRING(, function_name)
682        }
683#endif
684        /* deep */
685        STRUCT_P(HashTable, static_variables, HashTable_zval_ptr)
686        STRUCT_ARRAY(zend_uint, num_args, zend_arg_info, arg_info)
687        gc_arg_info = 1;
688        dst->filename = processor->entry_php_src->filepath;
689#ifdef ZEND_ENGINE_2_4
690        if (src->literals) {
691            gc_opcodes = 1;
692            if (op_array_info->literalinfo_cnt) {
693                gc_literals = 1;
694            }
695        }
696#else
697        if (op_array_info->oplineinfo_cnt) {
698            gc_opcodes = 1;
699        }
700#endif
701#ifdef ZEND_ENGINE_2_4
702        if (gc_literals) {
703            dnl used when copying opcodes
704            COPY_N_EX(last_literal, zend_literal, literals)
705        }
706#endif
707        if (gc_opcodes) {
708            zend_op *opline, *end;
709            COPY_N_EX(last, zend_op, opcodes)
710
711            for (opline = dst->opcodes, end = opline + src->last; opline < end; ++opline) {
712#ifdef ZEND_ENGINE_2_4
713                pushdef(`UNION_znode_op_literal', `
714                    if (opline->$1_type == IS_CONST) {
715                        opline->$1.literal = &dst->literals[opline->$1.literal - src->literals];
716                    }
717                ')
718                UNION_znode_op_literal(op1)
719                UNION_znode_op_literal(op2)
720                popdef(`UNION_znode_op_literal')
721#endif
722
723                switch (opline->opcode) {
724#ifdef ZEND_GOTO
725                    case ZEND_GOTO:
726#endif
727                    case ZEND_JMP:
728#ifdef ZEND_FAST_CALL
729                    case ZEND_FAST_CALL:
730#endif
731                        Z_OP(opline->op1).jmp_addr = &dst->opcodes[Z_OP(opline->op1).jmp_addr - src->opcodes];
732                        break;
733
734                    case ZEND_JMPZ:
735                    case ZEND_JMPNZ:
736                    case ZEND_JMPZ_EX:
737                    case ZEND_JMPNZ_EX:
738#ifdef ZEND_JMP_SET
739                    case ZEND_JMP_SET:
740#endif
741#ifdef ZEND_JMP_SET_VAR
742            case ZEND_JMP_SET_VAR:
743#endif
744                        Z_OP(opline->op2).jmp_addr = &dst->opcodes[Z_OP(opline->op2).jmp_addr - src->opcodes];
745                        break;
746
747                    default:
748                        break;
749                }
750            }
751        }
752        if (gc_arg_info || gc_opcodes
753#ifdef ZEND_ENGINE_2_4
754         || gc_literals
755#endif
756        ) {
757            xc_gc_op_array_t gc_op_array;
758            gc_op_array.num_args = gc_arg_info ? dst->num_args : 0;
759            gc_op_array.arg_info = gc_arg_info ? dst->arg_info : NULL;
760            gc_op_array.opcodes  = gc_opcodes ? dst->opcodes : NULL;
761#ifdef ZEND_ENGINE_2_4
762            gc_op_array.literals = gc_literals ? dst->literals : NULL;
763#endif
764            xc_gc_add_op_array(&gc_op_array TSRMLS_CC);
765        }
766        IFAUTOCHECK(`xc_autocheck_skip = 1;')
767    }
768    else
769    ')
770    do {
771    dnl RESTORE is done above!
772
773    /* Common elements */
774    PROCESS(zend_uchar, type)
775    PROC_ZSTRING(, function_name)
776    PROCESS(zend_uint, fn_flags)
777    STRUCT_ARRAY(zend_uint, num_args, zend_arg_info, arg_info)
778    PROCESS(zend_uint, num_args)
779    PROCESS(zend_uint, required_num_args)
780#   ifndef ZEND_ENGINE_2_4
781    PROCESS(zend_bool, pass_rest_by_reference)
782#   endif
783#ifndef ZEND_ENGINE_2_4
784    PROCESS(unsigned char, return_reference)
785#endif
786    /* END of common elements */
787#ifdef IS_UNICODE
788    dnl SETNULL(u_twin)
789#endif
790
791    STRUCT_P(zend_uint, refcount)
792    UNFIXPOINTER(zend_uint, refcount)
793    IFSTORE(`dst->refcount[0] = 1;')
794
795#ifdef ZEND_ENGINE_2_4
796    dnl used when copying opcodes
797    STRUCT_ARRAY(int, last_literal, zend_literal, literals)
798    PROCESS(int, last_literal)
799#endif
800
801    dnl uses literals
802    STRUCT_ARRAY(zend_uint, last, zend_op, opcodes)
803    PROCESS(zend_uint, last)
804#ifndef ZEND_ENGINE_2_4
805    IFCOPY(`dst->size = src->last;DONE(size)', `PROCESS(zend_uint, size)')
806#endif
807
808#ifdef IS_CV
809    STRUCT_ARRAY(int, last_var, zend_compiled_variable, vars)
810    PROCESS(int, last_var)
811#   ifndef ZEND_ENGINE_2_4
812    IFCOPY(`dst->size_var = src->last_var;DONE(size_var)', `PROCESS(zend_uint, size_var)')
813#   endif
814#else
815    dnl zend_cv.m4 is illegal to be made public, don not ask me for it
816    IFDASM(`
817        sinclude(srcdir`/processor/zend_cv.m4')
818        ')
819#endif
820
821    PROCESS(zend_uint, T)
822
823#ifdef ZEND_ENGINE_2_5
824    PROCESS(zend_uint, nested_calls)
825    PROCESS(zend_uint, used_stack)
826#endif
827
828    STRUCT_ARRAY(last_brk_cont_t, last_brk_cont, zend_brk_cont_element, brk_cont_array)
829    PROCESS(last_brk_cont_t, last_brk_cont)
830#ifndef ZEND_ENGINE_2_4
831    PROCESS(zend_uint, current_brk_cont)
832#endif
833
834    STRUCT_ARRAY(int, last_try_catch, zend_try_catch_element, try_catch_array)
835    PROCESS(int, last_try_catch)
836#ifdef ZEND_ENGINE_2_5
837    PROCESS(zend_bool, has_finally_block)
838#endif
839
840    STRUCT_P(HashTable, static_variables, HashTable_zval_ptr)
841
842#ifndef ZEND_ENGINE_2_4
843    COPY(start_op)
844    PROCESS(int, backpatch_count)
845#endif
846#ifdef ZEND_ENGINE_2_3
847    PROCESS(zend_uint, this_var)
848#endif
849
850#ifndef ZEND_ENGINE_2_4
851    PROCESS(zend_bool, done_pass_two)
852#endif
853    /* 5.0 <= ver < 5.3 */
854#if defined(ZEND_ENGINE_2) && !defined(ZEND_ENGINE_2_3)
855    PROCESS(zend_bool, uses_this)
856#endif
857
858    IFRESTORE(`dst->filename = processor->entry_php_src->filepath;DONE(filename)', `PROC_STRING(filename)')
859#ifdef IS_UNICODE
860    IFRESTORE(`
861        COPY(script_encoding)
862    ', `
863        PROC_STRING(script_encoding)
864    ')
865#endif
866    PROCESS(zend_uint, line_start)
867    PROCESS(zend_uint, line_end)
868    PROCESS(int, doc_comment_len)
869    PROC_ZSTRING_L(, doc_comment, doc_comment_len)
870#ifdef ZEND_COMPILE_DELAYED_BINDING
871    PROCESS(zend_uint, early_binding);
872#endif
873
874    /* reserved */
875    DONE(reserved)
876#if defined(HARDENING_PATCH) && HARDENING_PATCH
877    PROCESS(zend_bool, created_by_eval)
878#endif
879#ifdef ZEND_ENGINE_2_4
880    SETNULL(run_time_cache)
881    PROCESS(int, last_cache_slot)
882#endif
883    } while (0);
884    IFRESTORE(`xc_fix_op_array_info(processor->entry_php_src, processor->php_src, dst, shallow_copy, op_array_info TSRMLS_CC);')
885
886    dnl mark it as -1 on store, and lookup parent on restore
887    IFSTORE(`dst->prototype = (processor->active_class_entry_src && src->prototype) ? (zend_function *) -1 : NULL;', `
888        IFRESTORE(`do {
889            zend_function *parent;
890            if (src->prototype != NULL
891             && zend_u_hash_find(&(processor->active_class_entry_dst->parent->function_table),
892                    UG(unicode) ? IS_UNICODE : IS_STRING,
893                    src->function_name, xc_zstrlen(UG(unicode) ? IS_UNICODE : IS_STRING, src->function_name) + 1,
894                    (void **) &parent) == SUCCESS) {
895                /* see do_inherit_method_check() */
896                if ((parent->common.fn_flags & ZEND_ACC_ABSTRACT)) {
897                    dst->prototype = parent;
898                } else if (!(parent->common.fn_flags & ZEND_ACC_CTOR) || (parent->common.prototype && (parent->common.prototype->common.scope->ce_flags & ZEND_ACC_INTERFACE))) {
899                    /* ctors only have a prototype if it comes from an interface */
900                    dst->prototype = parent->common.prototype ? parent->common.prototype : parent;
901                }
902                else {
903                    dst->prototype = NULL;
904                }
905            }
906            else {
907                dst->prototype = NULL;
908            }
909        } while (0);
910        ')
911    ')
912    DONE(prototype)
913
914    PROC_CLASS_ENTRY_P(scope)
915    IFCOPY(`
916        if (src->scope) {
917            xc_fix_method(processor, dst TSRMLS_CC);
918        }
919    ')
920
921    IFRESTORE(`
922        if (xc_have_op_array_ctor) {
923            zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) xc_zend_extension_op_array_ctor_handler, dst TSRMLS_CC);
924        }
925    ')
926    }
927    IFCOPY(`
928        processor->active_op_array_dst = NULL;
929        processor->active_op_array_src = NULL;
930    ')
931    IFDASM(`
932        dasm->active_op_array_src = NULL;
933    ')
934')
935dnl }}}
936
937#ifdef HAVE_XCACHE_CONSTANT
938DEF_STRUCT_P_FUNC(`xc_constinfo_t', , `dnl {{{
939    PROCESS(zend_uint, key_size)
940#ifdef IS_UNICODE
941    PROCESS(zend_uchar, type)
942#endif
943    IFRESTORE(`COPY(key)', `
944        PROC_ZSTRING_N(type, key, key_size)
945    ')
946    PROCESS(ulong, h)
947    STRUCT(zend_constant, constant)
948')
949dnl }}}
950#endif
951IFRESTORE(`', `
952DEF_STRUCT_P_FUNC(`xc_op_array_info_detail_t', , `dnl {{{
953    PROCESS(zend_uint, index)
954    PROCESS(zend_uint, info)
955')
956dnl }}}
957DEF_STRUCT_P_FUNC(`xc_op_array_info_t', , `dnl {{{
958#ifdef ZEND_ENGINE_2_4
959    PROCESS(zend_uint, literalinfo_cnt)
960    STRUCT_ARRAY(zend_uint, literalinfo_cnt, xc_op_array_info_detail_t, literalinfos)
961#else
962    PROCESS(zend_uint, oplineinfo_cnt)
963    STRUCT_ARRAY(zend_uint, oplineinfo_cnt, xc_op_array_info_detail_t, oplineinfos)
964#endif
965')
966dnl }}}
967')
968DEF_STRUCT_P_FUNC(`xc_funcinfo_t', , `dnl {{{
969    PROCESS(zend_uint, key_size)
970#ifdef IS_UNICODE
971    PROCESS(zend_uchar, type)
972#endif
973    IFRESTORE(`COPY(key)', `
974        PROC_ZSTRING_N(type, key, key_size)
975    ')
976    PROCESS(ulong, h)
977    IFRESTORE(`COPY(op_array_info)', `
978        STRUCT(xc_op_array_info_t, op_array_info)
979    ')
980    IFRESTORE(`
981        processor->active_op_array_infos_src = &src->op_array_info;
982        processor->active_op_array_index = 0;
983    ')
984    STRUCT(zend_function, func)
985')
986dnl }}}
987DEF_STRUCT_P_FUNC(`xc_classinfo_t', , `dnl {{{
988    PROCESS(zend_uint, key_size)
989#ifdef IS_UNICODE
990    PROCESS(zend_uchar, type)
991#endif
992    IFRESTORE(`COPY(key)', `
993        PROC_ZSTRING_N(type, key, key_size)
994    ')
995    PROCESS(ulong, h)
996    PROCESS(zend_uint, methodinfo_cnt)
997    IFRESTORE(`COPY(methodinfos)', `
998        STRUCT_ARRAY(zend_uint, methodinfo_cnt, xc_op_array_info_t, methodinfos)
999    ')
1000    IFRESTORE(`
1001        processor->active_op_array_infos_src = src->methodinfos;
1002        processor->active_op_array_index = 0;
1003    ')
1004    STRUCT_P(zend_class_entry, class_entry)
1005#ifndef ZEND_COMPILE_DELAYED_BINDING
1006    PROCESS(int, oplineno)
1007#endif
1008')
1009dnl }}}
1010IFRESTORE(`', `
1011#ifdef ZEND_ENGINE_2_1
1012DEF_STRUCT_P_FUNC(`xc_autoglobal_t', , `dnl {{{
1013    PROCESS(zend_uint, key_len)
1014#ifdef IS_UNICODE
1015    PROCESS(zend_uchar, type)
1016#endif
1017    IFRESTORE(`COPY(key)', `
1018        PROC_ZSTRING_L(type, key, key_len)
1019    ')
1020    PROCESS(ulong, h)
1021')
1022dnl }}}
1023#endif
1024')
1025IFRESTORE(`', `
1026#ifdef XCACHE_ERROR_CACHING
1027DEF_STRUCT_P_FUNC(`xc_compilererror_t', , `dnl {{{
1028    PROCESS(int, type)
1029    PROCESS(uint, lineno)
1030    PROCESS(int, error_len)
1031    PROC_STRING_L(error, error_len)
1032')
1033dnl }}}
1034#endif
1035')
1036DEF_STRUCT_P_FUNC(`xc_entry_data_php_t', , `dnl {{{
1037    IFCOPY(`
1038        processor->php_dst = dst;
1039        processor->php_src = src;
1040    ')
1041
1042    /* skip */
1043    DONE(next)
1044    PROCESS(xc_hash_value_t, hvalue)
1045    PROCESS(xc_md5sum_t, md5)
1046    PROCESS(zend_ulong, refcount)
1047
1048    PROCESS(zend_ulong, hits)
1049    PROCESS(size_t, size)
1050
1051    IFRESTORE(`COPY(op_array_info)', `
1052        STRUCT(xc_op_array_info_t, op_array_info)
1053    ')
1054    IFRESTORE(`
1055        processor->active_op_array_infos_src = &dst->op_array_info;
1056        processor->active_op_array_index = 0;
1057    ')
1058    STRUCT_P(zend_op_array, op_array)
1059
1060#ifdef HAVE_XCACHE_CONSTANT
1061    PROCESS(zend_uint, constinfo_cnt)
1062    STRUCT_ARRAY(zend_uint, constinfo_cnt, xc_constinfo_t, constinfos)
1063#endif
1064
1065    PROCESS(zend_uint, funcinfo_cnt)
1066    STRUCT_ARRAY(zend_uint, funcinfo_cnt, xc_funcinfo_t, funcinfos)
1067
1068    PROCESS(zend_uint, classinfo_cnt)
1069    STRUCT_ARRAY(zend_uint, classinfo_cnt, xc_classinfo_t, classinfos, , IFRESTORE(`processor->active_class_index'))
1070#ifdef ZEND_ENGINE_2_1
1071    PROCESS(zend_uint, autoglobal_cnt)
1072    IFRESTORE(`
1073        COPY(autoglobals)
1074    ', `
1075        STRUCT_ARRAY(zend_uint, autoglobal_cnt, xc_autoglobal_t, autoglobals)
1076    ')
1077#endif
1078#ifdef XCACHE_ERROR_CACHING
1079    PROCESS(zend_uint, compilererror_cnt)
1080    IFRESTORE(`
1081        COPY(compilererrors)
1082    ', `
1083        STRUCT_ARRAY(zend_uint, compilererror_cnt, xc_compilererror_t, compilererrors)
1084    ')
1085#endif
1086#ifndef ZEND_COMPILE_DELAYED_BINDING
1087    PROCESS(zend_bool, have_early_binding)
1088#endif
1089    PROCESS(zend_bool, have_references)
1090')
1091dnl }}}
1092DEF_STRUCT_P_FUNC(`xc_entry_t', , `dnl {{{
1093    /* skip */
1094    DONE(next)
1095    PROCESS(size_t, size)
1096
1097    PROCESS(time_t, ctime)
1098    PROCESS(time_t, atime)
1099    PROCESS(time_t, dtime)
1100    PROCESS(long, ttl)
1101    PROCESS(zend_ulong, hits)
1102    DONE(name) dnl handle in xc_entry_php_t and xc_entry_var_t
1103')
1104dnl }}}
1105DEF_STRUCT_P_FUNC(`xc_entry_php_t', , `dnl {{{
1106    STRUCT(xc_entry_t, entry)
1107    DISABLECHECK(`
1108        PROCESS(int, entry.name.str.len)
1109        IFRESTORE(`COPY(entry.name.str.val)', `
1110            PROC_STRING_L(entry.name.str.val, entry.name.str.len)
1111        ')
1112    ')
1113
1114    IFCALCCOPY(`COPY(php)', `STRUCT_P(xc_entry_data_php_t, php)')
1115
1116    IFSTORE(`dst->refcount = 0; DONE(refcount)', `PROCESS(long, refcount)')
1117    PROCESS(time_t, file_mtime)
1118    PROCESS(size_t, file_size)
1119    PROCESS(size_t, file_device)
1120    PROCESS(size_t, file_inode)
1121
1122    PROCESS(size_t, filepath_len)
1123    IFRESTORE(`COPY(filepath)', `PROC_STRING_L(filepath, filepath_len)')
1124    PROCESS(size_t, dirpath_len)
1125    IFRESTORE(`COPY(dirpath)', `PROC_STRING_L(dirpath, dirpath_len)')
1126#ifdef IS_UNICODE
1127    PROCESS(int, ufilepath_len)
1128    IFRESTORE(`COPY(ufilepath)', `PROC_USTRING_L(ufilepath, ufilepath_len)')
1129    PROCESS(int, udirpath_len)
1130    IFRESTORE(`COPY(udirpath)', `PROC_USTRING_L(udirpath, udirpath_len)')
1131#endif
1132')
1133dnl }}}
1134DEF_STRUCT_P_FUNC(`xc_entry_var_t', , `dnl {{{
1135    STRUCT(xc_entry_t, entry)
1136
1137#ifdef IS_UNICODE
1138    PROCESS(zend_uchar, name_type)
1139#endif
1140    dnl {{{ entry.name
1141    DISABLECHECK(`
1142#ifdef IS_UNICODE
1143        if (src->name_type == IS_UNICODE) {
1144            PROCESS(int32_t, entry.name.ustr.len)
1145        }
1146        else {
1147            PROCESS(int, entry.name.str.len)
1148        }
1149#else
1150        PROCESS(int, entry.name.str.len)
1151#endif
1152        IFRESTORE(`COPY(entry.name.str.val)', `
1153#ifdef IS_UNICODE
1154            PROC_ZSTRING_L(name_type, entry.name.uni.val, entry.name.uni.len)
1155#else
1156            PROC_STRING_L(entry.name.str.val, entry.name.str.len)
1157#endif
1158        ')
1159    ')
1160    dnl }}}
1161
1162    IFDPRINT(`INDENT()`'fprintf(stderr, "zval:value");')
1163    STRUCT_P_EX(zval_ptr, dst->value, src->value, `value', `', `&')
1164    PROCESS(zend_bool, have_references)
1165    DONE(value)
1166')
1167dnl }}}
1168dnl ====================================================
Note: See TracBrowser for help on using the repository browser.