Commit Graph

1020 Commits

Author SHA1 Message Date
Nikita Popov
5d160e309e Fix static variable behavior with inheritance
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.
2021-02-18 11:18:19 +01:00
Dmitry Stogov
4b79dba932 Added Inheritance Cache.
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.
2021-02-09 22:53:57 +03:00
Nikita Popov
3e01f5afb1 Replace zend_bool uses with bool
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.
2021-01-15 12:33:06 +01:00
Nikita Popov
3642042629 Merge branch 'PHP-8.0'
* PHP-8.0:
  IBM i PASE doesn't support ITIMER_PROF
2020-12-15 10:15:52 +01:00
Nikita Popov
b6d043aae2 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  IBM i PASE doesn't support ITIMER_PROF
2020-12-15 10:15:47 +01:00
Calvin Buckley
54248b18fe IBM i PASE doesn't support ITIMER_PROF
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.
2020-12-15 10:15:28 +01:00
Nikita Popov
ada2a55e07 Merge branch 'PHP-8.0'
* PHP-8.0:
  FIxed bug #80299
2020-10-30 17:24:02 +01:00
Nikita Popov
904c1b6589 FIxed bug #80299
The must_wrap was leaking across iterations.
2020-10-30 17:23:18 +01:00
Nikita Popov
6188b7a1da Revert "Change calling convention of zval_update_constant[_ex]() to fastcall."
This reverts commit 5a447b086b.

Revert this ABI break from PHP-8.0, leaving it only on master.
2020-10-09 15:06:12 +02:00
Dmitry Stogov
5a447b086b Change calling convention of zval_update_constant[_ex]() to fastcall. 2020-10-08 02:04:38 +03:00
Dmitry Stogov
d5d31ea3b3 Cleanup observer API and add JIT support 2020-09-18 12:55:58 +03:00
Máté Kocsis
9975986b7e
Improve error messages mentioning parameters instead of arguments
Closes GH-5999
2020-09-09 10:47:43 +02:00
Nikita Popov
f5dbebd82e Accept zend_string instead of zval in zend_compile_string 2020-09-07 11:42:21 +02:00
Levi Morrison
66c3e900e2 Add zend_observer API
Closes GH-5857.

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
Co-authored-by: Sammy Powers <sammyk@datadoghq.com>
2020-09-01 09:59:59 -06:00
Nikita Popov
061c708a93 Correctly report failure in zend_handle_undef_args()
And do the check before increfing the closure object, otherwise
we'd have to release it as well.

Fixes oss-fuzz #25313.
2020-08-31 10:37:55 +02:00
Nikita Popov
e81becce08 Fix trampoline leak in array_map 2020-08-31 10:14:39 +02:00
George Peter Banyard
fa8d9b1183 Improve type declarations for Zend APIs
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
2020-08-28 15:41:27 +02:00
Nikita Popov
df5011f56c Export and reuse zend_is_valid_class_name API
Unserialization does the same check as zend_lookup_class, so let's
share the same optimized implementation.
2020-08-28 10:06:01 +02:00
Nikita Popov
7a6ae9b148 Fix refcounting for the named params case as well
Adjust the test case to pass a refcounted value and to also check
the named params case.
2020-08-24 16:30:49 +02:00
Nikita Popov
779e904465 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix refcounting
2020-08-24 16:23:33 +02:00
Nikita Popov
bb54694f4f Fix refcounting 2020-08-24 16:23:19 +02:00
Christoph M. Becker
5643f34a1e Merge branch 'PHP-7.4' into master
* PHP-7.4:
  Fix #79979: passing value to by-ref param via CUFA crashes
2020-08-24 15:03:26 +02:00
Christoph M. Becker
6b6c2c003c Fix #79979: passing value to by-ref param via CUFA crashes
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
2020-08-24 14:08:32 +02:00
Nikita Popov
d92229d8c7 Implement named parameters
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.
2020-07-31 15:53:36 +02:00
Nikita Popov
c206c742d6 Fix bug #79900
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.
2020-07-29 15:27:48 +02:00
Máté Kocsis
d30cd7d7e7
Review the usage of apostrophes in error messages
Closes GH-5590
2020-07-10 21:05:28 +02:00
Nikita Popov
302933daea Remove no_separation flag 2020-07-07 09:30:24 +02:00
Nikita Popov
75c4e613e4 Correctly determine arg name of USER_ARG_INFO functions 2020-07-06 11:51:10 +02:00
Nikita Popov
795d2cbd71 Reuse warning function 2020-07-06 10:38:02 +02:00
Nikita Popov
75a04eac97 Make exit() unwind properly
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.
2020-06-29 15:50:12 +02:00
Nikita Popov
1c74bab8e6 More efficient check for valid class name
Use a bitset of valid characters instead of strspn. This is both
more efficient and more compact.
2020-06-10 14:50:35 +02:00
Nikita Popov
5b59d4915c Cleanup SPL autoload implementation
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.
2020-06-10 09:38:47 +02:00
Nikita Popov
e56e53a59d Back up fake_scope in zend_call_function
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().
2020-06-09 16:33:33 +02:00
Nikita Popov
257dbb0450 Add zend_call_known_function() API family
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.
2020-06-09 16:21:54 +02:00
Dmitry Stogov
bfc56ed511 Keep trace number in EG(jit_trace_num) instead of EG(reserved)[zend_func_info_rid] 2020-05-25 17:05:26 +03:00
Nikita Popov
1b1d313275 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix static property indirections in file cache
  Don't require rc=1 for function static variables
2020-05-20 11:13:35 +02:00
Nikita Popov
8819d247c6 Don't require rc=1 for function static variables
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.
2020-05-20 11:12:18 +02:00
Máté Kocsis
93640db4d5
Improve error message for deprecated methods 2020-05-14 17:23:31 +02:00
Alex Dowad
555489dd83 Honor script time limit when calling shutdown functions
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.
2020-05-13 12:47:12 +02:00
Alex Dowad
f0960879e4 zend_timeout is not a signal handler function
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.
2020-05-12 17:13:46 +02:00
Nikita Popov
5d93eab620 Don't reset SIGG(running) when calling zend_on_timeout
This is only an internal callback nowadays and does not actually
run any user code. It must be async signal safe.
2020-05-11 15:05:01 +02:00
Nikita Popov
718e55c3e0 Add zend_array_release() function
To complement zend_string_release() and zend_object_release().
2020-05-06 11:27:20 +02:00
Nikita Popov
48a34bc120 Add helper APIs for get_gc implementations
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.
2020-04-27 10:48:22 +02:00
George Peter Banyard
446724bcd9 Fix [-Werror=missing-braces] compiler warning
Partial fix to bug 79431
2020-04-13 23:03:31 +02:00
Máté Kocsis
960318ed95
Change argument error message format
Closes GH-5211
2020-02-26 15:00:08 +01:00
Máté Kocsis
ac0853eb26
Make type error messages more consistent
Closes GH-5092
2020-02-17 14:22:17 +01:00
Nikita Popov
cb7b21009b Merge branch 'PHP-7.4'
* PHP-7.4:
  Reset trampoline on executor startup
  Fix UAF in is_callable() and allocated trampoline
2020-01-30 11:05:56 +01:00
Nikita Popov
98deece6f7 Reset trampoline on executor startup
Make sure the trampoline is usable, even if we had an unclean
shutdown on the last request.
2020-01-30 11:05:04 +01:00
Nikita Popov
0a2f6c5527 Move undefined constant error into get_constant_ex
All the other error conditions are already handled in there, so
this one should be as well.
2020-01-10 11:48:10 +01:00
Nikita Popov
72a5fdec2c Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78921
2019-12-13 16:38:42 +01:00