Skip to content
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

Refactor FCI API #9723

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft

Refactor FCI API #9723

wants to merge 5 commits into from

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Oct 11, 2022

The current FCI API is highly confusing IMHO, the zval *args parameters is not as one could expect the parameter which will set the params field within an FCI structure. Instead it is expected to be a PHP array, something it doesn't assert and causes confusions as to why usage of the API fails.

Moreover, since PHP 8.0, if one has a HashTable for the positional arguments it is simpler to pass this HashTable to the named_params field which also supports positional arguments. Using this field instead of the current FCI API removes unnecessary heap allocations for zvals which are for the most part locally stack allocated.

This PR should be reviewed commit by commit as the change from the FCI API to using the named_params field is split from the actual removal of the API.

Note: The removal of zend_fcall_info_argp() is still a WIP as I'm hitting a very strange bug on test file: Zend/tests/declare_007.phpt

UPGRADING.INTERNALS Show resolved Hide resolved
bool status;

if (zend_parse_parameters(ZEND_NUM_ARGS(), "f*", &entry.fci, &entry.fci_cache, &params, &param_count) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "f*", &entry.fci, &entry.fci_cache, &entry.fci.params, &entry.fci.param_count) == FAILURE) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entry.fci.params will point to the VM call stack, and needs to be duplicated as it outlives the register_shutdown_function() call

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahhh that's indeed an issue. Okay here it makes sense to realloc. :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you have a test that fails? As currently it does not even with this change.

@Girgias
Copy link
Member Author

Girgias commented Oct 20, 2022

Tried reproducing the ASAN failure but it doesn't happen on my machine (Fedora 36)

@iluuu1994
Copy link
Member

iluuu1994 commented Oct 20, 2022

@Girgias I assume you passed the --asan flag to run-tests.php (or make test TESTS=)?

@Girgias
Copy link
Member Author

Girgias commented Oct 20, 2022

@Girgias I assume you passed the --asan flag to run-tests.php (or make test TESTS=)?

I did, might try a complete recompile, but I wonder if there is some reason why Linux is less picky then FreeBSD

Update: Finally managed to reproduce

@Girgias
Copy link
Member Author

Girgias commented Oct 20, 2022

It also seems to be due to the usage of zend_release_fcall_info_cache() which maybe is not needed? As it only does something when the zend_function is a trampoline (which I don't really understand when this is the case or what it is).

@iluuu1994
Copy link
Member

The ASAN build is run on Linux 🙂

Instead handle the copying and safe reallocation of the param zvals ourself.
The last parameter which is named zval *args, does NOT set the FCI params field.
It is expected to be a PHP array which gets looped over to set the arguments which is also a zval pointer...

Since PHP 8.0, the named_params field is a more appropriate way of doing this.

Also remove zend_fcall_info_args_save() and zend_fcall_info_args_restore() as they were only used in the implementation of zend_fcall_info_call()
Usage of these function heap allocates the zvals when they can already be used directly with an FCI
This function reallocates the param zvals on the heap, when in general they can be directly assigned to the FCI
TODO better description of what to do in each case
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants