Skip to content

Zend: Make EG(fake_scope) a const zend_class_entry* #19060

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Zend/Optimizer/zend_inference.c
Original file line number Diff line number Diff line change
Expand Up @@ -2409,7 +2409,7 @@ static const zend_property_info *lookup_prop_info(const zend_class_entry *ce, ze
/* If the class is linked, reuse the precise runtime logic. */
if ((ce->ce_flags & ZEND_ACC_LINKED)
&& (!scope || (scope->ce_flags & ZEND_ACC_LINKED))) {
zend_class_entry *prev_scope = EG(fake_scope);
const zend_class_entry *prev_scope = EG(fake_scope);
EG(fake_scope) = scope;
prop_info = zend_get_property_info(ce, name, 1);
EG(fake_scope) = prev_scope;
Expand Down
17 changes: 9 additions & 8 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -1400,13 +1400,14 @@ ZEND_API void zend_merge_properties(zval *obj, HashTable *properties) /* {{{ */
{
zend_object *zobj = Z_OBJ_P(obj);
zend_object_write_property_t write_property = zobj->handlers->write_property;
zend_class_entry *old_scope = EG(fake_scope);
zend_string *key;
zval *value;

if (HT_IS_PACKED(properties)) {
return;
}

const zend_class_entry *old_scope = EG(fake_scope);
EG(fake_scope) = Z_OBJCE_P(obj);
ZEND_HASH_MAP_FOREACH_STR_KEY_VAL(properties, key, value) {
if (key) {
Expand Down Expand Up @@ -1746,7 +1747,7 @@ ZEND_API void object_properties_load(zend_object *object, HashTable *properties)
size_t prop_name_len;
if (zend_unmangle_property_name_ex(key, &class_name, &prop_name, &prop_name_len) == SUCCESS) {
zend_string *pname = zend_string_init(prop_name, prop_name_len, 0);
zend_class_entry *prev_scope = EG(fake_scope);
const zend_class_entry *prev_scope = EG(fake_scope);
if (class_name && class_name[0] != '*') {
zend_string *cname = zend_string_init(class_name, strlen(class_name), 0);
EG(fake_scope) = zend_lookup_class(cname);
Expand Down Expand Up @@ -5001,7 +5002,7 @@ ZEND_API void zend_declare_class_constant_string(zend_class_entry *ce, const cha

ZEND_API void zend_update_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, zval *value) /* {{{ */
{
zend_class_entry *old_scope = EG(fake_scope);
const zend_class_entry *old_scope = EG(fake_scope);

EG(fake_scope) = scope;

Expand All @@ -5014,7 +5015,7 @@ ZEND_API void zend_update_property_ex(zend_class_entry *scope, zend_object *obje
ZEND_API void zend_update_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length, zval *value) /* {{{ */
{
zend_string *property;
zend_class_entry *old_scope = EG(fake_scope);
const zend_class_entry *old_scope = EG(fake_scope);

EG(fake_scope) = scope;

Expand All @@ -5038,7 +5039,7 @@ ZEND_API void zend_update_property_null(zend_class_entry *scope, zend_object *ob
ZEND_API void zend_unset_property(zend_class_entry *scope, zend_object *object, const char *name, size_t name_length) /* {{{ */
{
zend_string *property;
zend_class_entry *old_scope = EG(fake_scope);
const zend_class_entry *old_scope = EG(fake_scope);

EG(fake_scope) = scope;

Expand Down Expand Up @@ -5110,14 +5111,14 @@ ZEND_API zend_result zend_update_static_property_ex(zend_class_entry *scope, zen
{
zval *property, tmp;
zend_property_info *prop_info;
zend_class_entry *old_scope = EG(fake_scope);

if (UNEXPECTED(!(scope->ce_flags & ZEND_ACC_CONSTANTS_UPDATED))) {
if (UNEXPECTED(zend_update_class_constants(scope) != SUCCESS)) {
return FAILURE;
}
}

const zend_class_entry *old_scope = EG(fake_scope);
EG(fake_scope) = scope;
property = zend_std_get_static_property_with_info(scope, name, BP_VAR_W, &prop_info);
EG(fake_scope) = old_scope;
Expand Down Expand Up @@ -5210,7 +5211,7 @@ ZEND_API zend_result zend_update_static_property_stringl(zend_class_entry *scope
ZEND_API zval *zend_read_property_ex(zend_class_entry *scope, zend_object *object, zend_string *name, bool silent, zval *rv) /* {{{ */
{
zval *value;
zend_class_entry *old_scope = EG(fake_scope);
const zend_class_entry *old_scope = EG(fake_scope);

EG(fake_scope) = scope;

Expand All @@ -5236,7 +5237,7 @@ ZEND_API zval *zend_read_property(zend_class_entry *scope, zend_object *object,
ZEND_API zval *zend_read_static_property_ex(zend_class_entry *scope, zend_string *name, bool silent) /* {{{ */
{
zval *property;
zend_class_entry *old_scope = EG(fake_scope);
const zend_class_entry *old_scope = EG(fake_scope);

EG(fake_scope) = scope;
property = zend_std_get_static_property(scope, name, silent ? BP_VAR_IS : BP_VAR_R);
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ static void zend_update_property_num_checked(zend_class_entry *scope, zend_objec
return;
}
#if ZEND_DEBUG
zend_class_entry *old_scope = EG(fake_scope);
const zend_class_entry *old_scope = EG(fake_scope);
EG(fake_scope) = i_get_exception_base(object);
const zend_property_info *prop_info = zend_get_property_info(object->ce, member, true);
ZEND_ASSERT(OBJ_PROP_TO_NUM(prop_info->offset) == prop_num);
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ ZEND_API ZEND_COLD void ZEND_FASTCALL zend_object_released_while_assigning_to_pr
ZEND_API ZEND_COLD void ZEND_FASTCALL zend_asymmetric_visibility_property_modification_error(
const zend_property_info *prop_info, const char *operation
) {
zend_class_entry *scope;
const zend_class_entry *scope;
if (EG(fake_scope)) {
scope = EG(fake_scope);
} else {
Expand Down
3 changes: 1 addition & 2 deletions Zend/zend_execute_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -814,7 +814,6 @@ zend_result zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_
zend_function *func;
uint32_t call_info;
void *object_or_called_scope;
zend_class_entry *orig_fake_scope;

ZVAL_UNDEF(fci->retval);

Expand Down Expand Up @@ -1003,7 +1002,7 @@ zend_result zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_
fci_cache->function_handler = NULL;
}

orig_fake_scope = EG(fake_scope);
const zend_class_entry *orig_fake_scope = EG(fake_scope);
EG(fake_scope) = NULL;
if (func->type == ZEND_USER_FUNCTION) {
uint32_t orig_jit_trace_num = EG(jit_trace_num);
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ struct _zend_executor_globals {
size_t vm_stack_page_size;

struct _zend_execute_data *current_execute_data;
zend_class_entry *fake_scope; /* used to avoid checks accessing properties */
const zend_class_entry *fake_scope; /* used to avoid checks accessing properties */

uint32_t jit_trace_num; /* Used by tracing JIT to reference the currently running trace */

Expand Down
12 changes: 6 additions & 6 deletions Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ static ZEND_COLD zend_never_inline void zend_readonly_property_unset_error(
ZSTR_VAL(ce->name), ZSTR_VAL(member));
}

static zend_always_inline zend_class_entry *get_fake_or_executed_scope(void)
static zend_always_inline const zend_class_entry *get_fake_or_executed_scope(void)
{
if (UNEXPECTED(EG(fake_scope))) {
return EG(fake_scope);
Expand Down Expand Up @@ -391,7 +391,7 @@ static zend_always_inline uintptr_t zend_get_property_offset(zend_class_entry *c
flags = property_info->flags;

if (flags & (ZEND_ACC_CHANGED|ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) {
zend_class_entry *scope = get_fake_or_executed_scope();
const zend_class_entry *scope = get_fake_or_executed_scope();

if (property_info->ce != scope) {
if (flags & ZEND_ACC_CHANGED) {
Expand Down Expand Up @@ -491,7 +491,7 @@ ZEND_API zend_property_info *zend_get_property_info(const zend_class_entry *ce,
flags = property_info->flags;

if (flags & (ZEND_ACC_CHANGED|ZEND_ACC_PRIVATE|ZEND_ACC_PROTECTED)) {
zend_class_entry *scope = get_fake_or_executed_scope();
const zend_class_entry *scope = get_fake_or_executed_scope();
if (property_info->ce != scope) {
if (flags & ZEND_ACC_CHANGED) {
zend_property_info *p = zend_get_parent_private_property(scope, ce, member);
Expand Down Expand Up @@ -583,7 +583,7 @@ ZEND_API zend_result zend_check_property_access(const zend_object *zobj, zend_st
ZEND_API bool ZEND_FASTCALL zend_asymmetric_property_has_set_access(const zend_property_info *prop_info) {
ZEND_ASSERT(prop_info->flags & ZEND_ACC_PPP_SET_MASK);
ZEND_ASSERT(!(prop_info->flags & ZEND_ACC_PUBLIC_SET));
zend_class_entry *scope = get_fake_or_executed_scope();
const zend_class_entry *scope = get_fake_or_executed_scope();
if (prop_info->ce == scope) {
return true;
}
Expand Down Expand Up @@ -2030,7 +2030,7 @@ ZEND_API zval *zend_std_get_static_property_with_info(zend_class_entry *ce, zend
}

if (!(property_info->flags & ZEND_ACC_PUBLIC)) {
zend_class_entry *scope = get_fake_or_executed_scope();
const zend_class_entry *scope = get_fake_or_executed_scope();
if (property_info->ce != scope) {
if (UNEXPECTED(property_info->flags & ZEND_ACC_PRIVATE)
|| UNEXPECTED(!is_protected_compatible_scope(property_info->ce, scope))) {
Expand Down Expand Up @@ -2114,7 +2114,7 @@ ZEND_API zend_function *zend_std_get_constructor(zend_object *zobj) /* {{{ */

if (constructor) {
if (UNEXPECTED(!(constructor->common.fn_flags & ZEND_ACC_PUBLIC))) {
zend_class_entry *scope = get_fake_or_executed_scope();
const zend_class_entry *scope = get_fake_or_executed_scope();
ZEND_ASSERT(!(constructor->common.fn_flags & ZEND_ACC_PUBLIC));
if (!zend_check_method_accessible(constructor, scope)) {
zend_bad_constructor_call(constructor, scope);
Expand Down
27 changes: 13 additions & 14 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -4190,7 +4190,7 @@ ZEND_METHOD(ReflectionClass, getStaticProperties)
ZEND_METHOD(ReflectionClass, getStaticPropertyValue)
{
reflection_object *intern;
zend_class_entry *ce, *old_scope;
zend_class_entry *ce;
zend_string *name;
zval *prop, *def_value = NULL;

Expand All @@ -4204,7 +4204,7 @@ ZEND_METHOD(ReflectionClass, getStaticPropertyValue)
RETURN_THROWS();
}

old_scope = EG(fake_scope);
const zend_class_entry *old_scope = EG(fake_scope);
EG(fake_scope) = ce;
prop = zend_std_get_static_property(ce, name, BP_VAR_IS);
EG(fake_scope) = old_scope;
Expand All @@ -4231,7 +4231,7 @@ ZEND_METHOD(ReflectionClass, getStaticPropertyValue)
ZEND_METHOD(ReflectionClass, setStaticPropertyValue)
{
reflection_object *intern;
zend_class_entry *ce, *old_scope;
zend_class_entry *ce;
zend_property_info *prop_info;
zend_string *name;
zval *variable_ptr, *value;
Expand All @@ -4245,7 +4245,7 @@ ZEND_METHOD(ReflectionClass, setStaticPropertyValue)
if (UNEXPECTED(zend_update_class_constants(ce) != SUCCESS)) {
RETURN_THROWS();
}
old_scope = EG(fake_scope);
const zend_class_entry *old_scope = EG(fake_scope);
EG(fake_scope) = ce;
variable_ptr = zend_std_get_static_property_with_info(ce, name, BP_VAR_W, &prop_info);
EG(fake_scope) = old_scope;
Expand Down Expand Up @@ -4998,7 +4998,7 @@ ZEND_METHOD(ReflectionClass, isInstance)
ZEND_METHOD(ReflectionClass, newInstance)
{
reflection_object *intern;
zend_class_entry *ce, *old_scope;
zend_class_entry *ce;
zend_function *constructor;

GET_REFLECTION_OBJECT_PTR(ce);
Expand All @@ -5007,7 +5007,7 @@ ZEND_METHOD(ReflectionClass, newInstance)
return;
}

old_scope = EG(fake_scope);
const zend_class_entry *old_scope = EG(fake_scope);
EG(fake_scope) = ce;
constructor = Z_OBJ_HT_P(return_value)->get_constructor(Z_OBJ_P(return_value));
EG(fake_scope) = old_scope;
Expand Down Expand Up @@ -5065,7 +5065,7 @@ ZEND_METHOD(ReflectionClass, newInstanceWithoutConstructor)
ZEND_METHOD(ReflectionClass, newInstanceArgs)
{
reflection_object *intern;
zend_class_entry *ce, *old_scope;
zend_class_entry *ce;
int argc = 0;
HashTable *args = NULL;
zend_function *constructor;
Expand All @@ -5084,7 +5084,7 @@ ZEND_METHOD(ReflectionClass, newInstanceArgs)
return;
}

old_scope = EG(fake_scope);
const zend_class_entry *old_scope = EG(fake_scope);
EG(fake_scope) = ce;
constructor = Z_OBJ_HT_P(return_value)->get_constructor(Z_OBJ_P(return_value));
EG(fake_scope) = old_scope;
Expand Down Expand Up @@ -5908,7 +5908,7 @@ ZEND_METHOD(ReflectionProperty, getValue)
}
}

zend_class_entry *old_scope = EG(fake_scope);
const zend_class_entry *old_scope = EG(fake_scope);
EG(fake_scope) = intern->ce;
member_p = Z_OBJ_P(object)->handlers->read_property(Z_OBJ_P(object),
ref->unmangled_name, BP_VAR_R, ref->cache_slot, &rv);
Expand Down Expand Up @@ -5967,7 +5967,7 @@ ZEND_METHOD(ReflectionProperty, setValue)
Z_PARAM_ZVAL(value)
ZEND_PARSE_PARAMETERS_END();

zend_class_entry *old_scope = EG(fake_scope);
const zend_class_entry *old_scope = EG(fake_scope);
EG(fake_scope) = intern->ce;
object->handlers->write_property(object, ref->unmangled_name, value, ref->cache_slot);
EG(fake_scope) = old_scope;
Expand Down Expand Up @@ -6026,7 +6026,7 @@ ZEND_METHOD(ReflectionProperty, getRawValue)

if (!prop || !prop->hooks || !prop->hooks[ZEND_PROPERTY_HOOK_GET]) {
zval rv;
zend_class_entry *old_scope = EG(fake_scope);
const zend_class_entry *old_scope = EG(fake_scope);
EG(fake_scope) = intern->ce;
zval *member_p = Z_OBJ_P(object)->handlers->read_property(
Z_OBJ_P(object), ref->unmangled_name, BP_VAR_R,
Expand All @@ -6052,7 +6052,7 @@ static void reflection_property_set_raw_value(zend_property_info *prop,
zend_object *object, zval *value)
{
if (!prop || !prop->hooks || !prop->hooks[ZEND_PROPERTY_HOOK_SET]) {
zend_class_entry *old_scope = EG(fake_scope);
const zend_class_entry *old_scope = EG(fake_scope);
EG(fake_scope) = intern->ce;
object->handlers->write_property(object, unmangled_name, value, cache_slot);
EG(fake_scope) = old_scope;
Expand Down Expand Up @@ -6275,7 +6275,6 @@ ZEND_METHOD(ReflectionProperty, isInitialized)
}
RETURN_FALSE;
} else {
zend_class_entry *old_scope;
int retval;

if (!object) {
Expand All @@ -6298,7 +6297,7 @@ ZEND_METHOD(ReflectionProperty, isInitialized)
}
}

old_scope = EG(fake_scope);
const zend_class_entry *old_scope = EG(fake_scope);
EG(fake_scope) = intern->ce;
retval = Z_OBJ_HT_P(object)->has_property(Z_OBJ_P(object),
ref->unmangled_name, ZEND_PROPERTY_EXISTS, ref->cache_slot);
Expand Down