summaryrefslogtreecommitdiff
path: root/Zend/zend_execute_API.c
Commit message (Collapse)AuthorAgeFilesLines
* Don't imply SILENT from NO_AUTOLOADNikita Popov2021-03-181-8/+4
| | | | | | We have separate flags for non-autoloading class fetches and silent class fetches. There's no reason why NO_AUTOLOAD should be special-cased to be implicitly silent.
* Destroy constant values before object storeNikita Popov2021-03-181-15/+29
| | | | | | | | Now that constants can contain objects (currently only enums), we should destroy them before we free the object store, otherwise there will be false positive leak reports. This doesn't affect the fast_shutdown sequence.
* Change Zend Stream API to use zend_string* instead of char*.Dmitry Stogov2021-03-161-1/+1
| | | | | This allows to eliminate re-calculation of string lenght and hash value. See the detailed list of changes in UPGRADING.INTERNALS.
* Reference dynamic functions through dynamic_defsNikita Popov2021-03-011-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | Currently, dynamically declared functions and closures are inserted into the function table under a runtime definition key, and then later possibly renamed. When opcache is not used and a file containing a closure is repeatedly included, this leads to a very large memory leak, as the no longer needed closure declarations will never be freed (https://bugs.php.net/bug.php?id=76982). With this patch, dynamic functions are instead stored in a dynamic_func_defs member on the op_array, which opcodes reference by index. When the parent op_array is destroyed, the dynamic_func_defs it contains are also destroyed (unless they are stilled used elsewhere, e.g. because they have been bound, or are used by a live closure). This resolves the fundamental part of the leak, though doesn't completely fix it yet due to some arena allocations. The main non-obvious change here is to static variable handling: We can't destroy static_variables_ptr in destroy_op_array, as e.g. that would clear the static variables in a dynamic function when the op_array containing it is destroyed. Static variable destruction is separated out for this reason (we already do static variable destruction separately for normal functions, so we only need to handle main scripts). Closes GH-5595.
* Fix static variable behavior with inheritanceNikita Popov2021-02-181-4/+4
| | | | | | | | | | | | When a method is inherited, the static variables will now always use the initial values, rather than the values at the time of inheritance. As such, behavior no longer depends on whether inheritance happens before or after a method has been called. This is implemented by always keeping static_variables as the original values, and static_variables_ptr as the modified copy. Closes GH-6705.
* Added Inheritance Cache.Dmitry Stogov2021-02-091-1/+15
| | | | | | | | | | This is a new transparent technology that eliminates overhead of PHP class inheritance. PHP classes are compiled and cached (by opcahce) separately, however their "linking" was done at run-time - on each request. The process of "linking" may involve a number of compatibility checks and borrowing methods/properties/constants form parent and traits. This takes significant time, but the result is the same on each request. Inheritance Cache performs "linking" for unique set of all the depending classes (parent, interfaces, traits, property types, method types involved into compatibility checks) once and stores result in opcache shared memory. As a part of the this patch, I removed limitations for immutable classes (unresolved constants, typed properties and covariant type checks). So now all classes stored in opcache are "immutable". They may be lazily loaded into process memory, if necessary, but this usually occurs just once (on first linking). The patch shows 8% improvement on Symphony "Hello World" app.
* Replace zend_bool uses with boolNikita Popov2021-01-151-7/+7
| | | | | | | We're starting to see a mix between uses of zend_bool and bool. Replace all usages with the standard bool type everywhere. Of course, zend_bool is retained as an alias.
* Merge branch 'PHP-8.0'Nikita Popov2020-12-151-2/+2
|\ | | | | | | | | * PHP-8.0: IBM i PASE doesn't support ITIMER_PROF
| * Merge branch 'PHP-7.4' into PHP-8.0Nikita Popov2020-12-151-2/+2
| |\ | | | | | | | | | | | | * PHP-7.4: IBM i PASE doesn't support ITIMER_PROF
| | * IBM i PASE doesn't support ITIMER_PROFCalvin Buckley2020-12-151-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Like Cygwin, this platform needs to use a real-time timer. This was based on a patch by @kadler, but it didn't handle unsetting the timer, so the timeout would continue to be active, triggering `hard_timeout` unexpectedly. The patch is fixed to handle unsetting. Closes GH-6503.
* | | Merge branch 'PHP-8.0'Nikita Popov2020-10-301-1/+1
|\ \ \ | |/ / | | | | | | | | | * PHP-8.0: FIxed bug #80299
| * | FIxed bug #80299Nikita Popov2020-10-301-1/+1
| | | | | | | | | | | | The must_wrap was leaking across iterations.
| * | Revert "Change calling convention of zval_update_constant[_ex]() to fastcall."Nikita Popov2020-10-091-2/+2
|/ / | | | | | | | | | | This reverts commit 5a447b086bba450d61c283adfecbdec657cc5f34. Revert this ABI break from PHP-8.0, leaving it only on master.
* | Change calling convention of zval_update_constant[_ex]() to fastcall.Dmitry Stogov2020-10-081-2/+2
| |
* | Cleanup observer API and add JIT supportDmitry Stogov2020-09-181-3/+1
| |
* | Improve error messages mentioning parameters instead of argumentsMáté Kocsis2020-09-091-0/+21
| | | | | | | | Closes GH-5999
* | Accept zend_string instead of zval in zend_compile_stringNikita Popov2020-09-071-9/+6
| |
* | Add zend_observer APILevi Morrison2020-09-011-0/+4
| | | | | | | | | | | | | | Closes GH-5857. Co-authored-by: Nikita Popov <nikita.ppv@gmail.com> Co-authored-by: Sammy Powers <sammyk@datadoghq.com>
* | Correctly report failure in zend_handle_undef_args()Nikita Popov2020-08-311-11/+11
| | | | | | | | | | | | | | And do the check before increfing the closure object, otherwise we'd have to release it as well. Fixes oss-fuzz #25313.
* | Fix trampoline leak in array_mapNikita Popov2020-08-311-0/+3
| |
* | Improve type declarations for Zend APIsGeorge Peter Banyard2020-08-281-18/+18
| | | | | | | | | | | | | | | | | | Voidification of Zend API which always succeeded Use bool argument types instead of int for boolean arguments Use bool return type for functions which return true/false (1/0) Use zend_result return type for functions which return SUCCESS/FAILURE as they don't follow normal boolean semantics Closes GH-6002
* | Export and reuse zend_is_valid_class_name APINikita Popov2020-08-281-1/+1
| | | | | | | | | | Unserialization does the same check as zend_lookup_class, so let's share the same optimized implementation.
* | Fix refcounting for the named params case as wellNikita Popov2020-08-241-0/+1
| | | | | | | | | | Adjust the test case to pass a refcounted value and to also check the named params case.
* | Merge branch 'PHP-7.4'Nikita Popov2020-08-241-0/+1
|\ \ | |/ | | | | | | * PHP-7.4: Fix refcounting
| * Fix refcountingNikita Popov2020-08-241-0/+1
| |
* | Merge branch 'PHP-7.4' into masterChristoph M. Becker2020-08-241-4/+16
|\ \ | |/ | | | | | | * PHP-7.4: Fix #79979: passing value to by-ref param via CUFA crashes
| * Fix #79979: passing value to by-ref param via CUFA crashesChristoph M. Becker2020-08-241-2/+8
| | | | | | | | | | | | | | If a by-val send is not allowed, we must not do so. Instead we wrap the value in a temporary reference. Closes GH-6000
* | Implement named parametersNikita Popov2020-07-311-4/+78
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | From an engine perspective, named parameters mainly add three concepts: * The SEND_* opcodes now accept a CONST op2, which is the argument name. For now, it is looked up by linear scan and runtime cached. * This may leave UNDEF arguments on the stack. To avoid having to deal with them in other places, a CHECK_UNDEF_ARGS opcode is used to either replace them with defaults, or error. * For variadic functions, EX(extra_named_params) are collected and need to be freed based on ZEND_CALL_HAS_EXTRA_NAMED_PARAMS. RFC: https://wiki.php.net/rfc/named_params Closes GH-5357.
* | Fix bug #79900Nikita Popov2020-07-291-1/+1
| | | | | | | | | | | | | | Run debug build shutdown GC regardless even if GC has been disabled. Of course, this only does something meaningful if the GC has been disabled at runtime and root collection is still enabled. We cannot prevent leaks if GC is disabled completely.
* | Review the usage of apostrophes in error messagesMáté Kocsis2020-07-101-10/+10
| | | | | | | | Closes GH-5590
* | Remove no_separation flagNikita Popov2020-07-071-7/+2
| |
* | Correctly determine arg name of USER_ARG_INFO functionsNikita Popov2020-07-061-7/+4
| |
* | Reuse warning functionNikita Popov2020-07-061-12/+1
| |
* | Make exit() unwind properlyNikita Popov2020-06-291-2/+1
| | | | | | | | | | | | | | | | | | | | | | exit() is now internally implemented by throwing an exception, performing a normal stack unwind and a clean shutdown. This ensures that no persistent resource leaks occur. The exception is internal, cannot be caught and does not result in the execution of finally blocks. This may be relaxed in the future. Closes GH-5768.
* | More efficient check for valid class nameNikita Popov2020-06-101-1/+23
| | | | | | | | | | Use a bitset of valid characters instead of strspn. This is both more efficient and more compact.
* | Cleanup SPL autoload implementationNikita Popov2020-06-101-35/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Replace EG(autoload_func) with a C level zend_autoload hook. This avoids having to do one indirection through PHP function calls. The need for EG(autoload_func) was a leftover from the __autoload() implementation. Additionally, drop special-casing of spl_autoload(), and instead register it just like any other autoloading function. This fixes bug #71236 as a side-effect. Finally, change spl_autoload_functions() to always return an array. The distinction between false and an empty array no longer makes sense here. Closes GH-5696.
* | Back up fake_scope in zend_call_functionNikita Popov2020-06-091-4/+4
| | | | | | | | | | | | We regularly find new places where we forgot to reset fake_scope. Instead of having to handle this for each caller of zend_call_function() and similar APIs, handle it directly in zend_call_function().
* | Add zend_call_known_function() API familyNikita Popov2020-06-091-0/+45
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This adds the following APIs: void zend_call_known_function( zend_function *fn, zend_object *object, zend_class_entry *called_scope, zval *retval_ptr, int param_count, zval *params); void zend_call_known_instance_method( zend_function *fn, zend_object *object, zval *retval_ptr, int param_count, zval *params); void zend_call_known_instance_method_with_0_params( zend_function *fn, zend_object *object, zval *retval_ptr); void zend_call_known_instance_method_with_1_params( zend_function *fn, zend_object *object, zval *retval_ptr, zval *param); void zend_call_known_instance_method_with_2_params( zend_function *fn, zend_object *object, zval *retval_ptr, zval *param1, zval *param2); These are used to perform a call if you already have the zend_function you want to call. zend_call_known_function() is the base API, the rest are just really thin wrappers around it for the common case of instance method calls. Closes GH-5692.
* | Keep trace number in EG(jit_trace_num) instead of ↵Dmitry Stogov2020-05-251-0/+2
| | | | | | | | EG(reserved)[zend_func_info_rid]
* | Merge branch 'PHP-7.4'Nikita Popov2020-05-201-2/+1
|\ \ | |/ | | | | | | | | * PHP-7.4: Fix static property indirections in file cache Don't require rc=1 for function static variables
| * Don't require rc=1 for function static variablesNikita Popov2020-05-201-2/+3
| | | | | | | | | | | | If file cache only is used, then static_variables_ptr may point to an immutable static_variables HT, which we do not want to destroy here.
* | Improve error message for deprecated methodsMáté Kocsis2020-05-141-4/+2
| |
* | Honor script time limit when calling shutdown functionsAlex Dowad2020-05-131-0/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | A time limit can be set on PHP script execution via `set_time_limit` (or .ini file). When the time limit is reached, the OS will notify PHP and `timed_out` and `vm_interrupt` flags are set. While these flags are regularly checked when executing PHP code, once the end of the script is reached, they are not checked while invoking shutdown functions (registered via `register_shutdown_function`). Of course, if the shutdown functions are implemented *in* PHP, then the interrupt flag will be checked while the VM is running PHP bytecode and the timeout will take effect. But if the shutdown functions are built-in (implemented in C), it will not. Since the shutdown functions are invoked through `zend_call_function`, add a check of the `vm_interrupt` flag there. Then, the script time limit will be respected when *entering* each shutdown function. The fact still remains that if a shutdown function is built-in and runs for a long time, script execution will not time out until it finishes and the interpreter tries to invoke the next one. Still, the behavior of scripts with execution time limits will be more consistent after this patch. To make the execution time-out feature work even more precisely, it would be necessary to scrutinize all the built-in functions and add checks of the `vm_interrupt` flag in any which can run for a long time. That might not be worth the effort, though. It should be mentioned that this patch does not solely affect shutdown functions, neither does it solely allow for interruption of running code due to script execution timeout. Anything else which causes `vm_interrupt` to be set, such as the PHP interpreter receiving a signal, will take effect when exiting from an internal function. And not just internal functions which are called because they were registered to run at shutdown; there are other cases where a series of internal functions might run in the midst of a script. In all such cases, it will be possible to interrupt the interpreter now. Closes GH-5543.
* | zend_timeout is not a signal handler functionAlex Dowad2020-05-121-1/+1
| | | | | | | | | | The 'int dummy' parameter to this function makes it appear that it was intended as a signal handler, but it is not being used as such. So remove the redundant parameter.
* | Don't reset SIGG(running) when calling zend_on_timeoutNikita Popov2020-05-111-13/+4
| | | | | | | | | | This is only an internal callback nowadays and does not actually run any user code. It must be async signal safe.
* | Add zend_array_release() functionNikita Popov2020-05-061-3/+1
| | | | | | | | To complement zend_string_release() and zend_object_release().
* | Add helper APIs for get_gc implementationsNikita Popov2020-04-271-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | get_gc() implementations that need to explore heterogeneous data currently work by computing how many GC entries they need, allocating a buffer for that and storing it on the object. This is inefficient and wastes memory, because the buffer is retained after the GC run. This commit adds an API for a single global GC buffer, which can be reused by get_gc implementations (as only one get_gc call is ever active at the same time). The GC buffer will automatically grow during the GC run and be discarded at the end.
* | Fix [-Werror=missing-braces] compiler warningGeorge Peter Banyard2020-04-131-1/+1
| | | | | | | | Partial fix to bug 79431
* | Change argument error message formatMáté Kocsis2020-02-261-1/+1
| | | | | | | | Closes GH-5211
* | Make type error messages more consistentMáté Kocsis2020-02-171-2/+40
| | | | | | | | Closes GH-5092