source: trunk/processor/processor.m4 @ 873

Last change on this file since 873 was 873, checked in by moo, 3 years ago

fix build

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