XCache is a fast, stable PHP opcode cacher that has been proven and is now running on production servers under high load. https://xcache.lighttpd.net/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1511 lines
38 KiB

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