Skip to content

Improve zend_jit_may_be_modified() check #16760

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

Merged
merged 1 commit into from
Nov 12, 2024
Merged
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
63 changes: 63 additions & 0 deletions ext/opcache/jit/zend_jit.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,69 @@ static bool zend_may_be_dynamic_property(zend_class_entry *ce, zend_string *memb
return 0;
}

static bool zend_jit_class_may_be_modified(const zend_class_entry *ce, const zend_op_array *called_from)
{
uint32_t i;

if (ce->type == ZEND_INTERNAL_CLASS) {
#ifdef _WIN32
/* ASLR */
return 1;
#else
return 0;
#endif
} else if (ce->type == ZEND_USER_CLASS) {
if (ce->ce_flags & ZEND_ACC_PRELOADED) {
return 0;
}
if (ce->info.user.filename == called_from->filename) {
if (ce->parent && zend_jit_class_may_be_modified(ce->parent, called_from)) {
return 1;
}
if (ce->num_interfaces) {
for (i = 0; i < ce->num_interfaces; i++) {
if (zend_jit_class_may_be_modified(ce->interfaces[i], called_from)) {
return 1;
}
}
}
if (ce->num_traits) {
for (i=0; i < ce->num_traits; i++) {
zend_class_entry *trait = zend_fetch_class_by_name(ce->trait_names[i].name,
ce->trait_names[i].lc_name, ZEND_FETCH_CLASS_TRAIT);
if (zend_jit_class_may_be_modified(trait, called_from)) {
return 1;
}
}
}
return 0;
}
}
return 1;
}

static bool zend_jit_may_be_modified(const zend_function *func, const zend_op_array *called_from)
{
if (func->type == ZEND_INTERNAL_FUNCTION) {
#ifdef _WIN32
/* ASLR */
return 1;
#else
return 0;
#endif
} else if (func->type == ZEND_USER_FUNCTION) {
if (func->common.fn_flags & ZEND_ACC_PRELOADED) {
return 0;
}
if (func->op_array.filename == called_from->filename
&& (!func->op_array.scope
|| !zend_jit_class_may_be_modified(func->op_array.scope, called_from))) {
return 0;
}
}
return 1;
}

#define OP_RANGE(ssa_op, opN) \
(((opline->opN##_type & (IS_TMP_VAR|IS_VAR|IS_CV)) && \
ssa->var_info && \
Expand Down
20 changes: 0 additions & 20 deletions ext/opcache/jit/zend_jit_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -683,26 +683,6 @@ static zend_always_inline const zend_op* zend_jit_trace_get_exit_opline(zend_jit
return NULL;
}

static inline bool zend_jit_may_be_modified(const zend_function *func, const zend_op_array *called_from)
{
if (func->type == ZEND_INTERNAL_FUNCTION) {
#ifdef _WIN32
/* ASLR */
return 1;
#else
return 0;
#endif
} else if (func->type == ZEND_USER_FUNCTION) {
if (func->common.fn_flags & ZEND_ACC_PRELOADED) {
return 0;
}
if (func->op_array.filename == called_from->filename && !func->op_array.scope) {
return 0;
}
}
return 1;
}

static zend_always_inline bool zend_jit_may_be_polymorphic_call(const zend_op *opline)
{
if (opline->opcode == ZEND_INIT_FCALL
Expand Down
Loading