3333#include "zend_smart_string.h"
3434#include "zend_cpuinfo.h"
3535
36+ static size_t global_map_ptr_last = 0 ;
37+
3638#ifdef ZTS
3739ZEND_API int compiler_globals_id ;
3840ZEND_API int executor_globals_id ;
@@ -41,7 +43,6 @@ static HashTable *global_class_table = NULL;
4143static HashTable * global_constants_table = NULL ;
4244static HashTable * global_auto_globals_table = NULL ;
4345static HashTable * global_persistent_list = NULL ;
44- static zend_uintptr_t global_last_static_member = 0 ;
4546ZEND_TSRMLS_CACHE_DEFINE ()
4647# define GLOBAL_FUNCTION_TABLE global_function_table
4748# define GLOBAL_CLASS_TABLE global_class_table
@@ -626,13 +627,22 @@ static void compiler_globals_ctor(zend_compiler_globals *compiler_globals) /* {{
626627 zend_hash_init_ex (compiler_globals -> auto_globals , 8 , NULL , auto_global_dtor , 1 , 0 );
627628 zend_hash_copy (compiler_globals -> auto_globals , global_auto_globals_table , auto_global_copy_ctor );
628629
629- compiler_globals -> last_static_member = global_last_static_member ;
630- if (compiler_globals -> last_static_member ) {
631- compiler_globals -> static_members_table = calloc (compiler_globals -> last_static_member + 1 , sizeof (zval * ));
632- } else {
633- compiler_globals -> static_members_table = NULL ;
634- }
635630 compiler_globals -> script_encoding_list = NULL ;
631+
632+ #if ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR_OR_OFFSET
633+ /* Map region is going to be created and resized at run-time. */
634+ compiler_globals -> map_ptr_base = NULL ;
635+ compiler_globals -> map_ptr_size = 0 ;
636+ compiler_globals -> map_ptr_last = global_map_ptr_last ;
637+ if (compiler_globals -> map_ptr_last ) {
638+ /* Allocate map_ptr table */
639+ compiler_globals -> map_ptr_size = ZEND_MM_ALIGNED_SIZE_EX (compiler_globals -> map_ptr_last , 4096 );
640+ compiler_globals -> map_ptr_base = pemalloc (compiler_globals -> map_ptr_size * sizeof (void * ), 1 );
641+ memset (compiler_globals -> map_ptr_base , 0 , compiler_globals -> map_ptr_last * sizeof (void * ));
642+ }
643+ #else
644+ # error "Unknown ZEND_MAP_PTR_KIND"
645+ #endif
636646}
637647/* }}} */
638648
@@ -650,13 +660,14 @@ static void compiler_globals_dtor(zend_compiler_globals *compiler_globals) /* {{
650660 zend_hash_destroy (compiler_globals -> auto_globals );
651661 free (compiler_globals -> auto_globals );
652662 }
653- if (compiler_globals -> static_members_table ) {
654- free (compiler_globals -> static_members_table );
655- }
656663 if (compiler_globals -> script_encoding_list ) {
657664 pefree ((char * )compiler_globals -> script_encoding_list , 1 );
658665 }
659- compiler_globals -> last_static_member = 0 ;
666+ if (compiler_globals -> map_ptr_base ) {
667+ free (compiler_globals -> map_ptr_base );
668+ compiler_globals -> map_ptr_base = NULL ;
669+ compiler_globals -> map_ptr_size = 0 ;
670+ }
660671}
661672/* }}} */
662673
@@ -879,6 +890,22 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions) /
879890#ifdef ZEND_WIN32
880891 zend_get_windows_version_info (& EG (windows_version_info ));
881892#endif
893+ # if ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR
894+ /* Create a map region, used for indirect pointers from shared to
895+ * process memory. It's allocatred once and never resized.
896+ * All processes must map it into the same address space.
897+ */
898+ CG (map_ptr_size ) = 1024 * 1024 ; // TODO: initial size ???
899+ CG (map_ptr_last ) = 0 ;
900+ CG (map_ptr_base ) = pemalloc (CG (map_ptr_size ) * sizeof (void * ), 1 );
901+ # elif ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR_OR_OFFSET
902+ /* Map region is going to be created and resized at run-time. */
903+ CG (map_ptr_base ) = NULL ;
904+ CG (map_ptr_size ) = 0 ;
905+ CG (map_ptr_last ) = 0 ;
906+ # else
907+ # error "Unknown ZEND_MAP_PTR_KIND"
908+ # endif
882909#endif
883910 EG (error_reporting ) = E_ALL & ~E_NOTICE ;
884911
@@ -931,7 +958,7 @@ int zend_post_startup(void) /* {{{ */
931958 * GLOBAL_FUNCTION_TABLE = * compiler_globals -> function_table ;
932959 * GLOBAL_CLASS_TABLE = * compiler_globals -> class_table ;
933960 * GLOBAL_CONSTANTS_TABLE = * executor_globals -> zend_constants ;
934- global_last_static_member = compiler_globals -> last_static_member ;
961+ global_map_ptr_last = compiler_globals -> map_ptr_last ;
935962
936963 short_tags_default = CG (short_tags );
937964 compiler_options_default = CG (compiler_options );
@@ -950,6 +977,8 @@ int zend_post_startup(void) /* {{{ */
950977 executor_globals_ctor (executor_globals );
951978 global_persistent_list = & EG (persistent_list );
952979 zend_copy_ini_directives ();
980+ #else
981+ global_map_ptr_last = CG (map_ptr_last );
953982#endif
954983
955984 if (zend_post_startup_cb ) {
@@ -996,6 +1025,12 @@ void zend_shutdown(void) /* {{{ */
9961025 GLOBAL_CLASS_TABLE = NULL ;
9971026 GLOBAL_AUTO_GLOBALS_TABLE = NULL ;
9981027 GLOBAL_CONSTANTS_TABLE = NULL ;
1028+ #else
1029+ if (CG (map_ptr_base )) {
1030+ free (CG (map_ptr_base ));
1031+ CG (map_ptr_base ) = NULL ;
1032+ CG (map_ptr_size ) = 0 ;
1033+ }
9991034#endif
10001035 zend_destroy_rsrc_list_dtors ();
10011036}
@@ -1077,17 +1112,12 @@ ZEND_API void zend_activate(void) /* {{{ */
10771112 init_compiler ();
10781113 init_executor ();
10791114 startup_scanner ();
1115+ if (CG (map_ptr_last )) {
1116+ memset (CG (map_ptr_base ), 0 , CG (map_ptr_last ) * sizeof (void * ));
1117+ }
10801118}
10811119/* }}} */
10821120
1083- #ifdef ZTS
1084- void zend_reset_internal_classes (void ) /* {{{ */
1085- {
1086- CG (last_static_member ) = global_last_static_member ;
1087- }
1088- /* }}} */
1089- #endif
1090-
10911121void zend_call_destructors (void ) /* {{{ */
10921122{
10931123 zend_try {
@@ -1619,6 +1649,62 @@ void free_estring(char **str_p) /* {{{ */
16191649}
16201650/* }}} */
16211651
1652+ ZEND_API void zend_map_ptr_reset (void )
1653+ {
1654+ CG (map_ptr_last ) = global_map_ptr_last ;
1655+ }
1656+
1657+ ZEND_API void * zend_map_ptr_new (void )
1658+ {
1659+ void * * ptr ;
1660+
1661+ if (CG (map_ptr_last ) >= CG (map_ptr_size )) {
1662+ #if ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR
1663+ // TODO: error ???
1664+ ZEND_ASSERT (0 );
1665+ #elif ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR_OR_OFFSET
1666+ /* Grow map_ptr table */
1667+ CG (map_ptr_size ) = ZEND_MM_ALIGNED_SIZE_EX (CG (map_ptr_last ) + 1 , 4096 );
1668+ CG (map_ptr_base ) = perealloc (CG (map_ptr_base ), CG (map_ptr_size ) * sizeof (void * ), 1 );
1669+ #else
1670+ # error "Unknown ZEND_MAP_PTR_KIND"
1671+ #endif
1672+ }
1673+ ptr = (void * * )CG (map_ptr_base ) + CG (map_ptr_last );
1674+ * ptr = NULL ;
1675+ CG (map_ptr_last )++ ;
1676+ #if ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR
1677+ return ptr ;
1678+ #elif ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR_OR_OFFSET
1679+ return (void * )((CG (map_ptr_last ) * sizeof (void * )) - (sizeof (void * ) - 1 ));
1680+ #else
1681+ # error "Unknown ZEND_MAP_PTR_KIND"
1682+ #endif
1683+ }
1684+
1685+ ZEND_API void zend_map_ptr_extend (size_t last )
1686+ {
1687+ if (last > CG (map_ptr_last )) {
1688+ void * * ptr ;
1689+
1690+ if (last >= CG (map_ptr_size )) {
1691+ #if ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR
1692+ /* This may never happen */
1693+ ZEND_ASSERT (0 );
1694+ #elif ZEND_MAP_PTR_KIND == ZEND_MAP_PTR_KIND_PTR_OR_OFFSET
1695+ /* Grow map_ptr table */
1696+ CG (map_ptr_size ) = ZEND_MM_ALIGNED_SIZE_EX (last , 4096 );
1697+ CG (map_ptr_base ) = perealloc (CG (map_ptr_base ), CG (map_ptr_size ) * sizeof (void * ), 1 );
1698+ #else
1699+ # error "Unknown ZEND_MAP_PTR_KIND"
1700+ #endif
1701+ }
1702+ ptr = (void * * )CG (map_ptr_base ) + CG (map_ptr_last );
1703+ memset (ptr , 0 , (last - CG (map_ptr_last )) * sizeof (void * ));
1704+ CG (map_ptr_last ) = last ;
1705+ }
1706+ }
1707+
16221708/*
16231709 * Local variables:
16241710 * tab-width: 4
0 commit comments