Skip to content

Commit 649f695

Browse files
committed
Merge branch 'master' into jit-dynasm
* master: Fixed incorrect reallocation Fix #77027: tidy::getOptDoc() not available on Windows Run CI tests under opcache.protect_memory=1 Fixed comment Micro optimizations Mark "top-level" classes Immutable clases and op_arrays. Remove the "auto" encoding Fixed bug #77025 Add vtbls for EUC-TW encoding Remove unused variable makefile_am_files Classify object handlers are required/optional Add support for getting SKIP_TAGSTART and SKIP_WHITE options Remove some obsolete config_vars.mk occurrences Remove bsd_converted from .gitignore Remove configuration parser and scanners ignores Remove obsolete buildconf.stamp from .gitignore [ci skip] Add magicdata.patch exception to .gitignore Remove outdated ext/spl/examples items from .gitignore
2 parents c88b6f5 + a0a1c89 commit 649f695

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1617
-1665
lines changed

.gitignore

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ _libs
3838
acconfig.h
3939
aclocal.m4
4040
autom4te.cache
41-
bsd_converted
42-
buildconf.stamp
4341
buildmk.stamp
4442
confdefs.h
4543
config.h
@@ -48,11 +46,6 @@ config.h.in
4846
config.log
4947
config.nice
5048
config.status
51-
config_vars.mk
52-
configuration-parser.c
53-
configuration-parser.h
54-
configuration-parser.output
55-
configuration-scanner.c
5649
configure
5750
conftest
5851
conftest.c
@@ -172,8 +165,6 @@ ext/phar/phar.phar
172165
ext/phar/phar.1
173166
ext/phar/phar.phar.1
174167
ext/phar/phar.php
175-
ext/spl/examples/.htaccess
176-
ext/spl/examples/*.phps
177168
ext/sqlite3/tests/phpsql*
178169

179170
# ------------------------------------------------------------------------------ Windows
@@ -205,5 +196,6 @@ ext/sqlite3/tests/phpsql*
205196

206197
# Special cases to invert previous ignore rules
207198
!ext/fileinfo/libmagic.patch
199+
!ext/fileinfo/magicdata.patch
208200
!ext/mbstring/oniguruma.patch
209201
!ext/pcre/pcre2lib/config.h

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ before_script:
6969

7070
# Run PHPs run-tests.php
7171
script:
72-
- ./sapi/cli/php run-tests.php -p `pwd`/sapi/cli/php $(if [ $ENABLE_DEBUG == 0 ]; then echo "-d opcache.enable_cli=1 -d zend_extension=`pwd`/modules/opcache.so"; fi) -g "FAIL,XFAIL,BORK,WARN,LEAK,SKIP" --offline --show-diff --show-slow 1000 --set-timeout 120
72+
- ./sapi/cli/php run-tests.php -p `pwd`/sapi/cli/php $(if [ $ENABLE_DEBUG == 0 ]; then echo "-d opcache.enable_cli=1 -d opcache.protect_memory=1 -d zend_extension=`pwd`/modules/opcache.so"; fi) -g "FAIL,XFAIL,BORK,WARN,LEAK,SKIP" --offline --show-diff --show-slow 1000 --set-timeout 120
7373

7474
after_success:
7575
- ccache --show-stats

UPGRADING.INTERNALS

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ PHP 7.4 INTERNALS UPGRADE NOTES
77
d. Removed zend_check_private()
88
e. php_win32_error_to_msg() memory management
99
f. get_properties_for() handler / Z_OBJDEBUG_P
10+
g. Required object handlers
11+
h. Immutable classes and op_arrays
1012

1113
2. Build system changes
1214
a. Abstract
@@ -98,6 +100,42 @@ PHP 7.4 INTERNALS UPGRADE NOTES
98100
// ...
99101
zend_release_properties(ht);
100102

103+
g. The following object handlers are now required (must be non-NULL):
104+
105+
* free_obj
106+
* dtor_obj
107+
* read_property
108+
* write_property
109+
* read_dimension
110+
* write_dimension
111+
* get_property_ptr_ptr
112+
* has_property
113+
* unset_property
114+
* has_dimension
115+
* unset_dimension
116+
* get_properties
117+
* get_method
118+
* get_constructor
119+
* get_class_name
120+
* get_gc
121+
122+
It is recommended to initialize object handler structures by copying the
123+
std object handlers and only overwriting those you want to change.
124+
125+
h. Opcache may make classes and op_arrays immutable. Such classes are marked
126+
by ZEND_ACC_IMMUTABLE flag, they are not going to be copied from opcache
127+
shared memory to process memory and must not be modified at all.
128+
Few related data structures were changed to allow addressing mutable data
129+
structures from immutable ones. This access is implemented through
130+
ZEND_MAP_PTR... abstraction macros and, basically, uses additional level of
131+
indirection. op_array->run_time_cache, op_array->static_variables_ptr and
132+
class_entry->static_members_table now have to be accessed through
133+
ZEND_MAP_PTR... macros.
134+
It's also not allowed to change op_array->reserved[] handles of immutable
135+
op_arrays. Instead, now you have to reserve op_array handle using
136+
zend_get_op_array_extension_handle() during MINIT and access its value
137+
using ZEND_OP_ARRAY_EXTENSION(op_array, handle).
138+
101139
========================
102140
2. Build system changes
103141
========================

Zend/zend.c

Lines changed: 106 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
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
3739
ZEND_API int compiler_globals_id;
3840
ZEND_API int executor_globals_id;
@@ -41,7 +43,6 @@ static HashTable *global_class_table = NULL;
4143
static HashTable *global_constants_table = NULL;
4244
static HashTable *global_auto_globals_table = NULL;
4345
static HashTable *global_persistent_list = NULL;
44-
static zend_uintptr_t global_last_static_member = 0;
4546
ZEND_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-
10911121
void 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 ZEND_MAP_PTR_PTR2OFFSET(ptr);
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

Zend/zend.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define ZEND_ENGINE_3
2626

2727
#include "zend_types.h"
28+
#include "zend_map_ptr.h"
2829
#include "zend_errors.h"
2930
#include "zend_alloc.h"
3031
#include "zend_llist.h"
@@ -127,10 +128,7 @@ struct _zend_class_entry {
127128
int default_static_members_count;
128129
zval *default_properties_table;
129130
zval *default_static_members_table;
130-
union {
131-
zval *static_members_table;
132-
zend_uintptr_t static_members_table_idx;
133-
};
131+
ZEND_MAP_PTR_DEF(zval *, static_members_table);
134132
HashTable function_table;
135133
HashTable properties_info;
136134
HashTable constants_table;
@@ -271,9 +269,8 @@ ZEND_API void zend_activate_modules(void);
271269
ZEND_API void zend_deactivate_modules(void);
272270
ZEND_API void zend_post_deactivate_modules(void);
273271

274-
void zend_reset_internal_classes(void);
275-
276272
ZEND_API void free_estring(char **str_p);
273+
277274
END_EXTERN_C()
278275

279276
/* output support */

0 commit comments

Comments
 (0)