Skip to content

Refactor FCI API - #9723

Draft
Girgias wants to merge 5 commits into
php:masterfrom
Girgias:fci-api-refactoring
Draft

Girgias wants to merge 5 commits into
php:masterfrom
Girgias:fci-api-refactoring

Conversation

@Girgias

@Girgias Girgias commented Oct 11, 2022

Copy link
Copy Markdown
Member

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

Comment thread UPGRADING.INTERNALS Resolved
Comment thread ext/standard/basic_functions.c Outdated
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Girgias force-pushed the fci-api-refactoring branch from 8788f17 to 9fc9151 Compare October 19, 2022 15:21
@Girgias

Girgias commented Oct 20, 2022

Copy link
Copy Markdown
Member Author

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

@iluuu1994

iluuu1994 commented Oct 20, 2022 •

Copy link
Copy Markdown
Member

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

@Girgias

Girgias commented Oct 20, 2022 •

Copy link
Copy Markdown
Member Author

@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

Girgias commented Oct 20, 2022

Copy link
Copy Markdown
Member Author

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
Copy Markdown
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.

3 participants