Skip to content

Commit a7f0ef8

Browse files
committed
Merge branch 'master' into jit-dynasm
* master: (52 commits) Removed IS_TYPE_COPYABLE flag from IS_STRING zvals. Moved IS_CONSTANT_VISITED_MARK, used for protection from recursive self-referencing class constants, from zval.u1.v.type_flags into zval.u2.access_flags. Updated NEWS Fixed #75838 (Memory leak in pg_escape_bytea()) Expand SEPARATE_STRING() Removed useless SEPARATE_STRING() (zend_string_extend() performs separation anyway) Clenaup SEPARATE_ZVAL...() macros (the behavior is unchanged) Add missing closing fold Eliminate duplication, increment_string() performs it anyway. Send by reference without duplication ZVAL_COPY_OR_DUP() instead of ZVAL_DUP() More effecient array duplication More effecient array duplication More effecient conversion Use ZVAL_COPY() instead og ZVAL_DUP(), because fault is an object Use zval_copy_ctor_func() instead of _zval_copy_ctor_func(). Add switches for Spectre variant 1 mitigation Scalar types don't have reference counter Eliminate duplication Use ZVAL_DUP() instead of zval_copy_ctor() ...
2 parents 9c1f2ba + 1ee94f5 commit a7f0ef8

Some content is hidden

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

65 files changed

+1111
-1005
lines changed

NEWS

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,11 @@ PHP NEWS
160160
used). (Anton Artamonov)
161161

162162
- Standard:
163-
. Fixed unzserialize(), to disable creation of unsupported data structures
163+
. Fixed unserialize(), to disable creation of unsupported data structures
164164
through manually crafted strings. (Dmitry)
165165
. Fixed bug #75409 (accept EFAULT in addition to ENOSYS as indicator
166166
that getrandom() is missing). (sarciszewski)
167+
. Fixed bug #74719 (fopen() should accept NULL as context). (Alexander Holman)
167168

168169
- Testing:
169170
. Implemented request #62055 (Make run-tests.php support --CGI-- sections).

UPGRADING.INTERNALS

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ PHP 7.3 INTERNALS UPGRADE NOTES
1414
k. zend_fcall_info_cache.initialized
1515
l. php_hrtime_current()
1616
m. zend_cpu_supports()
17+
n. IS_TYPE_COPYABLE
1718

1819
2. Build system changes
1920
a. Unix build system changes
@@ -102,6 +103,11 @@ PHP 7.3 INTERNALS UPGRADE NOTES
102103

103104
m. zend_cpu_supports() determines if a feature is supported by current cpu.
104105

106+
n. IS_STRING zvals don't set IS_TYPE_COPYALE anymore. This prevents string
107+
duplication by zval_copy_ctor(), ZVAL_DUP() and SEPARATE_ZVAL*() macros.
108+
Interned strings didn't set IS_TYPE_COPYALE, so they aren't affected at
109+
all.
110+
105111
========================
106112
2. Build system changes
107113
========================

Zend/README.ZEND_VM

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,3 @@ zend_vm_execute.h. Debugging with original file requires --with-lines
100100
option. By default ZE2 uses the following command to generate executor:
101101

102102
$ php zend_vm_gen.php --with-vm-kind=CALL
103-
104-
Zend Engine II currently includes two executors during the build process, one
105-
is the specialized version and the other is the old one non-specialized with
106-
function handlers. By default Zend Engine II uses the specialized one but you
107-
can switch to the old executor at runtime by calling zend_vm_use_old_executor().
108-

Zend/zend.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "zend_virtual_cwd.h"
3434
#include "zend_smart_str.h"
3535
#include "zend_smart_string.h"
36+
#include "zend_cpuinfo.h"
3637

3738
#ifdef ZTS
3839
ZEND_API int compiler_globals_id;
@@ -752,6 +753,10 @@ int zend_startup(zend_utility_functions *utility_functions, char **extensions) /
752753
extern zend_php_scanner_globals language_scanner_globals;
753754
#endif
754755

756+
#ifndef HAVE_FUNC_ATTRIBUTE_IFUNC
757+
zend_cpu_startup();
758+
#endif
759+
755760
#ifdef ZEND_WIN32
756761
php_win32_cp_set_by_id(65001);
757762
#endif

Zend/zend_API.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3624,7 +3624,7 @@ static inline zend_string *zval_make_interned_string(zval *zv) /* {{{ */
36243624
ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING);
36253625
Z_STR_P(zv) = zend_new_interned_string(Z_STR_P(zv));
36263626
if (ZSTR_IS_INTERNED(Z_STR_P(zv))) {
3627-
Z_TYPE_FLAGS_P(zv) &= ~ (IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
3627+
Z_TYPE_FLAGS_P(zv) = 0;
36283628
}
36293629
return Z_STR_P(zv);
36303630
}

Zend/zend_compile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ static inline zend_string *zval_make_interned_string(zval *zv) /* {{{ */
441441
ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING);
442442
Z_STR_P(zv) = zend_new_interned_string(Z_STR_P(zv));
443443
if (ZSTR_IS_INTERNED(Z_STR_P(zv))) {
444-
Z_TYPE_FLAGS_P(zv) &= ~ (IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
444+
Z_TYPE_FLAGS_P(zv) = 0;
445445
}
446446
return Z_STR_P(zv);
447447
}

Zend/zend_compile.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,6 @@ ZEND_API int zend_unmangle_property_name_ex(const zend_string *name, const char
765765

766766
zend_op *get_next_op(zend_op_array *op_array);
767767
void init_op(zend_op *op);
768-
uint32_t get_next_op_number(zend_op_array *op_array);
769768
ZEND_API int pass_two(zend_op_array *op_array);
770769
zend_brk_cont_element *get_next_brk_cont_element(void);
771770
ZEND_API zend_bool zend_is_compiling(void);
@@ -775,6 +774,11 @@ uint32_t zend_get_class_fetch_type(zend_string *name);
775774
ZEND_API zend_uchar zend_get_call_op(const zend_op *init_op, zend_function *fbc);
776775
ZEND_API int zend_is_smart_branch(zend_op *opline);
777776

777+
static zend_always_inline uint32_t get_next_op_number(zend_op_array *op_array)
778+
{
779+
return op_array->last;
780+
}
781+
778782
typedef zend_bool (*zend_auto_global_callback)(zend_string *name);
779783
typedef struct _zend_auto_global {
780784
zend_string *name;

Zend/zend_constants.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@
2828
#include "zend_globals.h"
2929
#include "zend_API.h"
3030

31+
/* Protection from recursive self-referencing class constants */
32+
#define IS_CONSTANT_VISITED_MARK 0x80
33+
34+
#define IS_CONSTANT_VISITED(zv) (Z_ACCESS_FLAGS_P(zv) & IS_CONSTANT_VISITED_MARK)
35+
#define MARK_CONSTANT_VISITED(zv) Z_ACCESS_FLAGS_P(zv) |= IS_CONSTANT_VISITED_MARK
36+
#define RESET_CONSTANT_VISITED(zv) Z_ACCESS_FLAGS_P(zv) &= ~IS_CONSTANT_VISITED_MARK
37+
3138
void free_zend_constant(zval *zv)
3239
{
3340
zend_constant *c = Z_PTR_P(zv);
@@ -353,20 +360,22 @@ ZEND_API zval *zend_get_constant_ex(zend_string *cname, zend_class_entry *scope,
353360
}
354361

355362
if (ret_constant && Z_TYPE_P(ret_constant) == IS_CONSTANT_AST) {
356-
if (Z_TYPE_P(ret_constant) == IS_CONSTANT_AST) {
357-
if (IS_CONSTANT_VISITED(ret_constant)) {
358-
zend_throw_error(NULL, "Cannot declare self-referencing constant '%s::%s'", ZSTR_VAL(class_name), ZSTR_VAL(constant_name));
359-
ret_constant = NULL;
360-
goto failure;
361-
}
362-
MARK_CONSTANT_VISITED(ret_constant);
363-
}
364-
if (UNEXPECTED(zval_update_constant_ex(ret_constant, c->ce) != SUCCESS)) {
365-
RESET_CONSTANT_VISITED(ret_constant);
363+
int ret;
364+
365+
if (IS_CONSTANT_VISITED(ret_constant)) {
366+
zend_throw_error(NULL, "Cannot declare self-referencing constant '%s::%s'", ZSTR_VAL(class_name), ZSTR_VAL(constant_name));
366367
ret_constant = NULL;
367368
goto failure;
368369
}
370+
371+
MARK_CONSTANT_VISITED(ret_constant);
372+
ret = zval_update_constant_ex(ret_constant, c->ce);
369373
RESET_CONSTANT_VISITED(ret_constant);
374+
375+
if (UNEXPECTED(ret != SUCCESS)) {
376+
ret_constant = NULL;
377+
goto failure;
378+
}
370379
}
371380
failure:
372381
zend_string_release(class_name);

Zend/zend_cpuinfo.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ typedef struct _zend_cpu_info {
2727
uint32_t initialized;
2828
} zend_cpu_info;
2929

30-
static zend_cpu_info cpuinfo;
30+
static zend_cpu_info cpuinfo = {0};
3131

3232
#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3333
static void __zend_cpuid(uint32_t func, uint32_t subfunc) {
@@ -40,23 +40,38 @@ static void __zend_cpuid(uint32_t func, uint32_t subfunc) {
4040
#elif defined(ZEND_WIN32)
4141
# include <intrin.h>
4242
static void __zend_cpuid(uint32_t func, uint32_t subfunc) {
43-
__cpuidex(&cpuinfo, func, subfunc)
43+
int regs[4];
44+
45+
__cpuidex(regs, func, subfunc);
46+
47+
cpuinfo.eax = regs[0];
48+
cpuinfo.ebx = regs[1];
49+
cpuinfo.ecx = regs[2];
50+
cpuinfo.edx = regs[3];
4451
}
4552
#else
4653
static void __zend_cpuid(uint32_t func, uint32_t subfunc) {
4754
cpuinfo.eax = 0;
4855
}
4956
#endif
5057

51-
ZEND_API int zend_cpu_supports(zend_cpu_feature feature) {
58+
void zend_cpu_startup(void)
59+
{
5260
if (!cpuinfo.initialized) {
5361
cpuinfo.initialized = 1;
5462
__zend_cpuid(0, 0);
5563
if (cpuinfo.eax == 0) {
56-
return 0;
64+
return;
5765
}
5866
__zend_cpuid(1, 0);
5967
}
68+
}
69+
70+
ZEND_API int zend_cpu_supports(zend_cpu_feature feature) {
71+
#ifdef HAVE_FUNC_ATTRIBUTE_IFUNC
72+
/* The resolver is invoked before zend_startup(). */
73+
zend_cpu_startup();
74+
#endif
6075
if (feature & ZEND_CPU_EDX_MASK) {
6176
return (cpuinfo.edx & (feature & ~ZEND_CPU_EDX_MASK));
6277
} else {

Zend/zend_cpuinfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ typedef enum _zend_cpu_feature {
9393

9494
ZEND_API int zend_cpu_supports(zend_cpu_feature feature);
9595

96+
void zend_cpu_startup(void);
97+
9698
#endif
9799

98100
/*

0 commit comments

Comments
 (0)