Skip to content

Commit

Permalink
WIP - work on fixing runkit_import to import new classes
Browse files Browse the repository at this point in the history
FIXME this doesn't copy the properties yet. Just the methods.
  • Loading branch information
TysonAndre authored and TysonAndre-tmg committed Aug 17, 2017
1 parent a916900 commit fd6fb52
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 28 deletions.
1 change: 1 addition & 0 deletions config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ runkit_constants.c \
runkit_object_id.c \
runkit_common.c \
runkit_zend_execute_API.c \
runkit_classes.c \
runkit_props.c \
, $ext_shared,, -Wdeclaration-after-statement -Werror -Wall -Wno-deprecated-declarations -Wno-pedantic)
fi
2 changes: 1 addition & 1 deletion config.w32
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ if (PHP_RUNKIT != "no") {
AC_DEFINE("PHP_RUNKIT_FEATURE_SUPER", PHP_RUNKIT_SUPER == "yes", "Runkit Superglobals");
AC_DEFINE("PHP_RUNKIT_SPL_OBJECT_ID", PHP_RUNKIT_SPL_OBJECT_ID == "yes", "Runkit spl_object_id substitute");

EXTENSION("runkit", "runkit.c runkit_functions.c runkit_methods.c runkit_import.c runkit_constants.c runkit_object_id.c runkit_common.c runkit_props.c runkit_zend_execute_API.c");
EXTENSION("runkit", "runkit.c runkit_functions.c runkit_methods.c runkit_import.c runkit_constants.c runkit_object_id.c runkit_common.c runkit_props.c runkit_classes.c runkit_zend_execute_API.c");
}
4 changes: 2 additions & 2 deletions php_runkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static inline void* _debug_emalloc(void* data, int bytes, char* file, int line)
// TODO: Clean up these macros once the corresponding functions/files are 100% correct.
#define PHP_RUNKIT_MANIPULATION_IMPORT
#define PHP_RUNKIT_MANIPULATION_PROPERTIES
// #define PHP_RUNKIT_MANIPULATION_CLASSES
#define PHP_RUNKIT_MANIPULATION_CLASSES
#endif

#ifdef PHP_RUNKIT_MANIPULATION
Expand Down Expand Up @@ -242,7 +242,7 @@ void php_runkit_clear_all_functions_runtime_cache(TSRMLS_D);
void php_runkit_fix_all_hardcoded_stack_sizes(zend_string *called_name_lower, zend_function *called_f TSRMLS_DC);

void php_runkit_remove_function_from_reflection_objects(zend_function *fe TSRMLS_DC);
// void php_runkit_function_copy_ctor(zend_function *fe, zend_string *newname TSRMLS_DC);
// void php_runkit_function_copy_ctor(zend_function *fe, zend_string *newname, char orig_fe_type TSRMLS_DC);
zend_function* php_runkit_function_clone(zend_function *fe, zend_string *newname, char orig_fe_type TSRMLS_DC);
void php_runkit_function_dtor(zend_function *fe);
int php_runkit_remove_from_function_table(HashTable *function_table, zend_string *func_lower);
Expand Down
3 changes: 3 additions & 0 deletions runkit.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,13 @@ zend_function_entry runkit_functions[] = {
PHP_FE(runkit_constant_remove, arginfo_runkit_constant_remove)
PHP_FE(runkit_constant_add, arginfo_runkit_constant_add)

/*
// We support this **partially** just so that runkit_import will compile, but it's in progress.
#ifdef PHP_RUNKIT_MANIPULATION_PROPERTIES
PHP_FE(runkit_default_property_add, NULL)
PHP_FE(runkit_default_property_remove, NULL)
#endif
*/
#endif /* PHP_RUNKIT_MANIPULATION */

#ifdef PHP_RUNKIT_SANDBOX
Expand Down
2 changes: 1 addition & 1 deletion runkit_classes.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
| Author: Sara Golemon <[email protected]> |
| Modified by Dmitry Zenovich <[email protected]> |
+----------------------------------------------------------------------+
Note: This file is no longer being compiled due to changes to the internals in property manipulation.
FIXME: Check that all applicable flags, member variables, etc. are manipulated appropriately for classes, etc.
runkit_property_modify() may be implemented in the future.
*/

Expand Down
65 changes: 41 additions & 24 deletions runkit_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,46 +43,63 @@ static int php_runkit_import_functions(HashTable *function_table, long flags
zend_string *new_key;
zend_bool add_function = 1;
zend_bool exists = 0;
zend_bool create_as_internal = 0;

new_key = fe->common.function_name;

if (fe && fe->type == ZEND_USER_FUNCTION) {
if (!fe || fe->type != ZEND_USER_FUNCTION) {
continue;
}

if (key != NULL) {
new_key = key;
exists = ((orig_fe = zend_hash_find_ptr(EG(function_table), new_key)) != NULL);
} else {
exists = ((orig_fe = zend_hash_index_find_ptr(EG(function_table), idx)) != NULL);
}
if (key != NULL) {
new_key = key;
exists = ((orig_fe = zend_hash_find_ptr(EG(function_table), new_key)) != NULL);
} else {
exists = ((orig_fe = zend_hash_index_find_ptr(EG(function_table), idx)) != NULL);
}

if (exists) {
php_runkit_remove_function_from_reflection_objects(orig_fe TSRMLS_CC);
if (flags & PHP_RUNKIT_IMPORT_OVERRIDE) {
if (key != NULL) {
if (zend_hash_del(EG(function_table), new_key) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Inconsistency cleaning up import environment");
return FAILURE;
}
} else {
if (zend_hash_index_del(EG(function_table), idx) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Inconsistency cleaning up import environment");
return FAILURE;
}
if (exists) {
create_as_internal = orig_fe->type == ZEND_INTERNAL_FUNCTION;
if (create_as_internal && !RUNKIT_G(internal_override)) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "%s() is an internal function and runkit.internal_override is disabled", ZSTR_VAL(new_key));
continue;
}
php_runkit_remove_function_from_reflection_objects(orig_fe TSRMLS_CC);
if (flags & PHP_RUNKIT_IMPORT_OVERRIDE) {
if (key != NULL) {
if (zend_hash_del(EG(function_table), new_key) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Inconsistency cleaning up import environment");
return FAILURE;
}
*clear_cache = 1;
} else {
add_function = 0;
if (zend_hash_index_del(EG(function_table), idx) == FAILURE) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Inconsistency cleaning up import environment");
return FAILURE;
}
}
*clear_cache = 1;
} else {
add_function = 0;
}
}

if (add_function) {
if (zend_hash_add_ptr(EG(function_table), new_key, fe) == NULL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failure importing %s()", ZSTR_VAL(fe->common.function_name));
zend_function *add_fe = fe;
if (create_as_internal) {
add_fe = php_runkit_function_clone(fe, new_key, ZEND_INTERNAL_FUNCTION);
}
if (zend_hash_add_ptr(EG(function_table), new_key, add_fe) == NULL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Failure importing %s()", ZSTR_VAL(add_fe->common.function_name));
if (add_fe != fe) {
PHP_RUNKIT_DESTROY_FUNCTION(add_fe);
}
PHP_RUNKIT_DESTROY_FUNCTION(fe);
return FAILURE;
} else {
PHP_RUNKIT_FUNCTION_ADD_REF(fe);
if (add_fe != fe) {
PHP_RUNKIT_FUNCTION_ADD_REF(add_fe);
}
}
}
} ZEND_HASH_FOREACH_END();
Expand Down

0 comments on commit fd6fb52

Please sign in to comment.