Commit graph

1071 commits

Author SHA1 Message Date
Christoph M. Becker
b683a7e470
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fallback to first line of function when ex->opline is NULL (#10003)
2022-12-05 12:45:22 +01:00
Arnaud Le Blanc
adc23828b4
Fallback to first line of function when ex->opline is NULL (#10003)
ex->opline can be null due to missing SAVE_OPLINE() in the VM

Fixes GH-9933
2022-12-02 17:21:30 +01:00
Ilija Tovilo
cc9dddea38
Fix fake closure leaking when called from internal func
Introduced in 8e49d7f32f.

ZEND_CALL_RELEASE_THIS was previously not handled for internal calls but
just for user calls in the zend_leave_helper.

Closes GH-9884
2022-11-03 14:31:47 +01:00
Ilija Tovilo
1d6b32f65c
Remove unnecessary ast eval bailout
We can just reset the filename_override to NULL in php_request_shutdown.

Closes GH-9805
2022-10-27 10:54:59 +02:00
Jakub Zelenka
505e8d2a04
Fix GH-9310: SSL local_cert and local_pk do not respect open_basedir restriction 2022-08-28 12:11:14 +01:00
Bob Weinand
625f164963 Include internal functions in the observer API
There are two main motivations to this:
a) The logic for handling internal and userland observation can be unified.
b) Unwinding of observed functions on a bailout does notably not include observers. Even if users of observers were to ensure such handling themselves, it would be impossible to retain the relative ordering - either the user has to unwind all internal observed frames before the automatic unwinding (zend_observer_fcall_end_all) or afterwards, but not properly interleaved.

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-07-30 19:20:55 +02:00
George Peter Banyard
6b160e78a7
Change fetch_type from int to uint32_t (#9152)
This is because it is derived from the opcode num which is an uint32_t
2022-07-28 21:03:09 +01:00
Rowan Tommins
af15923bc3
Extend deprecation notices to is_callable($foo) and callable $foo
Implements https://wiki.php.net/rfc/partially-supported-callables-expand-deprecation-notices
so that uses of "self" and "parent" in is_callable() and callable
type constraints now raise a deprecation notice, independent of the
one raised when and if the callable is actually invoked.

A new flag is added to the existing check_flags parameter of
zend_is_callable / zend_is_callable_ex, for use in internal calls
that would otherwise repeat the notice multiple times. In particular,
arguments to internal function calls are checked first based on
arginfo, and then again during ZPP, so the former suppresses the
deprecation notice.

Some existing tests which raised this deprecation have been updated
to avoid the syntax, but the existing version retained for maximum
regression coverage until it is made an error.

With thanks to Juliette Reinders Folmer for the RFC and initial
investigation.

Closes GH-8823.
2022-07-14 17:07:42 +02:00
Ilija Tovilo
d9e1871c85 Fix leak of backed_enum_table with preloading 2022-06-23 19:17:44 +02:00
Levi Morrison
280fd680c8
Make vm_interrupt and timed_out atomic (#8327)
This is done by adding a new zend_atomic_bool type. The type
definition is only available for compiler alignment and size info; it
should be treated as opaque and only the zend_atomic_bool_* family of
functions should be used.

Note that directly using atomic_bool is complicated. All C++ compilers
stdlibs that I checked typedef atomic_bool to std::atomic<bool>, which
can't be used in an extern "C" section, and there's at least one usage
of this in core, and probably more outside of it.

So, instead use platform specific functions, preferring compiler
intrinsics.
2022-06-01 09:43:25 -06:00
Sara Golemon
6c0a1db4a8 Merge branch 'PHP-8.1'
* PHP-8.1:
  Verify internal types before abandoning call frame
2022-06-01 00:52:30 +00:00
Sara Golemon
01d84545e7
Verify internal types before abandoning call frame
An internal caller executing a builtin method with
a static return type will lose context if we drop
our frame before performing the validation.
2022-06-01 00:51:08 +00:00
Máté Kocsis
da857c94a4
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix get_function_or_method_name when included file is scoped
2022-05-03 21:38:32 +02:00
Máté Kocsis
510061b595
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix get_function_or_method_name when included file is scoped
2022-05-03 21:36:42 +02:00
vajexal
74924ada93
Fix get_function_or_method_name when included file is scoped (#8467) 2022-05-03 21:34:01 +02:00
Max Kellermann
b9e895bca0
Replace memcmp() with zend_string functions (#8216)
* ext/oci8: use zend_string_equals()

Eliminate duplicate code.

* main/php_variables: use zend_string_equals_literal()

Eliminate duplicate code.

* Zend/zend_string: add zend_string_equals_cstr()

Allows eliminating duplicate code.

* Zend, ext/{opcache,standard}, main/output: use zend_string_equals_cstr()

Eliminate duplicate code.

* Zend/zend_string: add zend_string_starts_with()

* ext/{opcache,phar,spl,standard}: use zend_string_starts_with()

This adds missing length checks to several callers, e.g. in
cache_script_in_shared_memory().  This is important when the
zend_string is shorter than the string parameter, when memcmp()
happens to check backwards; this can result in an out-of-bounds memory
access.
2022-03-31 16:27:58 +02:00
Ilija Tovilo
e3ef7bbbb8
Adjust filename/lineno for constant expressions
Closes GH-7771
Closes GH-8124
2022-03-09 18:41:04 +01:00
Bob Weinand
c414c5f946 Merge branch 'PHP-8.1' 2022-03-07 18:27:43 +01:00
Bob Weinand
cbbf3502a2 Fix GH-8176: Fix leaking enum values in property initializers 2022-03-07 18:26:46 +01:00
Dmitry Stogov
d56ec0a624 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed bug #81607 (CE_CACHE allocation with concurrent access)
2021-11-17 18:25:00 +03:00
Dmitry Stogov
76548e5093 Fixed bug #81607 (CE_CACHE allocation with concurrent access) 2021-11-17 18:23:36 +03:00
Nikita Popov
f51eb15799 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix bug #81611
  Extract code for reporting a zend_fetch_class() error
2021-11-16 14:40:37 +01:00
Cameron Porter
812df2bd8a Fix bug #81611
Add zend_fetch_class_with_scope() which accepts a scope to use for
self/parent, and use that during constant expression evaluation.

Closes GH-7649.
2021-11-16 14:40:06 +01:00
Nikita Popov
d9ff09a333 Extract code for reporting a zend_fetch_class() error 2021-11-16 14:39:08 +01:00
Dmitry Stogov
90b7bde615 Use more compact representation for packed arrays.
- for packed arrays we store just an array of zvals without keys.
- the elements of packed array are accessible throuf as ht->arPacked[i]
  instead of ht->arData[i]
- in addition to general ZEND_HASH_FOREACH_* macros, we introduced similar
  familied for packed (ZEND_HASH_PACKED_FORECH_*) and real hashes
  (ZEND_HASH_MAP_FOREACH_*)
- introduced an additional family of macros to access elements of array
  (packed or real hashes) ZEND_ARRAY_ELEMET_SIZE, ZEND_ARRAY_ELEMET_EX,
  ZEND_ARRAY_ELEMET, ZEND_ARRAY_NEXT_ELEMENT, ZEND_ARRAY_PREV_ELEMENT
- zend_hash_minmax() prototype was changed to compare only values

Because of smaller data set, this patch may show performance improvement
on some apps and benchmarks that use packed arrays. (~1% on PHP-Parser)

TODO:
    - sapi/phpdbg needs special support for packed arrays (WATCH_ON_BUCKET).
    - zend_hash_sort_ex() may require converting packed arrays to hash.
2021-11-03 15:18:26 +03:00
Nikita Popov
70bd46cdac Release trampoline on zend_call_function with active exception
zend_call_function() normally always releases a cached call
trampoline. Do this also if the call does not actually happen
due to an active exception, so the caller does not need to deal
with this very special case.

Fixes oss-fuzz #39792.
2021-10-11 11:23:20 +02:00
Nikita Popov
d4368b88b6 Merge branch 'PHP-8.1'
* PHP-8.1:
  Don't populate CE_CACHE during compilation
2021-10-04 15:38:15 +02:00
Nikita Popov
ac70bb362e Don't populate CE_CACHE during compilation
It's possible for CE_CACHE slots to be populated during compilation
(e.g. due to an early binding attempt). When opcache then persists
the class, it clears the CE_CACHE slot for the class name as declared,
but not for different spellings (that only differ in case). As such,
a pointer to the old, non-persistent class entry may be retained.

Fix this by not populating CE_CACHE if in_compilation is set.

Closes GH-7542.
2021-10-04 15:38:01 +02:00
codinghuang
5bda4cd25a Support specifying start position in compile_string
Add additional zend_compile_position argument, which can be either
AT_SHEBANG, AT_OPEN_TAG or AFTER_OPEN_TAG. The previous behavior
corresponds to AFTER_OPEN_TAG.

Closes GH-7462.
2021-09-30 10:21:33 +02:00
Nikita Popov
485d3acfe6 Make zend_call_function() failure handling consistent
This API had rather peculiar behavior in case the provided function
is not callable. For some types of failures, it would silently
return FAILURE (e.g. a function does not exist), while for others
(e.g. a class does not exist) it would generate a warning. Depending
on what the calling code does, this can either result in silent
failure or duplicate errors.

This commit switches the contract such that zend_call_function()
always (*) succeeds, though that success might be in the form of
throwing an exception. Calling a non-callable will now consistently
throw an exception.

There are some rare callers that do want to ignore missing methods,
for legacy APIs that are specific with optional methods. For these
use cases a new zend_call_method_if_exists() API is provided.

Calling code generally does not need to explicitly check for and
report zend_call_function() failures -- it can rely on
zend_call_function() having already done so. However, existing
code that does check for failure should continue to work fine.

(*) The only exception to this is if EG(active) being false during
late engine shutdown. This is not relevant to most code, but code
running in destructors and similar may need to be aware of the
possibility.
2021-09-01 16:09:23 +02:00
Dmitry Stogov
827d72d38c Merge branch 'PHP-8.1'
* PHP-8.1:
  Avoid class name validation if it's already have IS_STR_CLASS_NAME_MAP_PTR flag.
2021-09-01 16:03:38 +03:00
Dmitry Stogov
c7fdf9c139 Avoid class name validation if it's already have IS_STR_CLASS_NAME_MAP_PTR flag. 2021-09-01 16:02:11 +03:00
Nikita Popov
3ec14000c6 Remove UNDEF checks in userstream implementation
I don't see how object can be UNDEF here -- and just passing
NULL in that case is not going to do anything reasonable either.
It would fall back to global functions with the same name.
2021-09-01 12:31:22 +02:00
Nikita Popov
cecea72a10 Reuse parts of normal executor shutdown for preloading
preloading currently reimplements parts of shutdown_executor(),
so it's easy for that code to go out of sync.

Extract this into an zend_shutdown_executor_values() API function
and use it as part of the preloading pre-shutdown.
2021-08-16 16:20:03 +02:00
Nikita Popov
8755976315 Fix arginfo/zpp consistency check for call_user_func from strict_types scope
This was using the wrong strict_types information. In this case the
call is performed with strict_types=0.
2021-08-16 12:11:39 +02:00
Nikita Popov
b5746a4c7f Drop HAS_UNLINKED_USES flag
Instead always use the unlinked_uses table, which is already used
if opcache is used. Not much point in having a different mechanism
for the non-opcache case.
2021-07-29 16:10:50 +02:00
Nikita Popov
89d0115409 Remove zend_cleanup_internal_classes()
If fast_shutdown is used, then we don't need to destroy static
members at all. If fast_shutdown is not used, then we already
loop over classes to destroy static members and static variables
in methods.
2021-07-23 12:51:47 +02:00
Levi Morrison
ae8647d9d3
Remove leading underscore for _zend_hash_find_known_hash (#7260)
Convert zend_hash_find_ex(..., 1) to zend_hash_find_known_hash(...)
Convert zend_hash_find_ex(..., 0) to zend_hash_find(...)

Also add serializable changes to UPGRADING.INTERNALS summary
2021-07-20 17:07:17 -06:00
Nikita Popov
ee65e92070 Check internal function type consistency in zend_call_function
We do this for calls in the engine, but not those going through
zend_call_function().
2021-07-13 11:50:07 +02:00
Patrick Allaert
aff365871a Fixed some spaces used instead of tabs 2021-06-29 11:30:26 +02:00
Martin Schröder
a65989b127
Alternative Fiber Internals Refactoring (#7101) 2021-06-04 23:25:35 -05:00
Nikita Popov
100a1e8e21 Convert exception during inheritance to fatal error
Now that inheritance can throw deprecations again, these may be
converted to exception by a custom error handler. In this case
we need to convert the exception to a fatal error, as inheritance
cannot safely throw in the general case.
2021-05-28 10:19:23 +02:00
Nikita Popov
dd86987b2c
Replay warnings during inheritance (#6928)
Since 3e6b447979 it is again possible to have
warnings (deprecations) during inheritance, and more such functionality is
likely in the future. This is a problem, because such warnings will only be
shown on the first request if the opcache inheritance cache is used. This
currently causes test failures in --repeat builds.

Fix this by uplifting the error recording functionality from opcache to Zend,
and then using it to persist a warning trace in the inheritance cache, which
can then be used to replay the warnings on subsequent executions.
2021-04-29 16:37:53 +02:00
Aaron Piotrowski
c276c16b66
Implement Fibers
RFC: https://wiki.php.net/rfc/fibers

Closes GH-6875.
2021-04-26 11:07:06 -05:00
Dmitry Stogov
0fdf668dce Keep fci->object unchanged 2021-04-15 15:31:45 +03:00
Dmitry Stogov
ca49e53670 Stop inserting fake frames on VM stack.
Now similar "fake" frames now materialized when fetching debug
backtraces. The patch also fixes few incorrect backtraces for generators
in *.phpt tests.
2021-04-15 15:30:10 +03:00
Dmitry Stogov
d8e4fbae62 Fast Class Cache
This is generalization of idea, that was previously usesd for caching
resolution of class_entries in zend_type. Now very similar mechanizm is
used for general zend_string into zend_class_entry resolution.

Interned zend_string with IS_STR_CLASS_NAME_MAP_PTR GC_FLAG uses its
refcount to adress corresponding zend_class_entry cache slot.
The refcount keeps an offset to this slot from CG(map_ptr_base).
Flag may be checked by ZSTR_HAS_CE_CACHE(str), cache slot may be read by
ZSTR_GET_CE_CACHE(str) and set by ZSTR_SET_CE_CACHE(str, ce).
2021-04-08 23:37:40 +03:00
Nikita Popov
4df39f4bd0 Don't imply SILENT from NO_AUTOLOAD
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.
2021-03-18 15:15:21 +01:00
Nikita Popov
234af00bcb Destroy constant values before object store
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.
2021-03-18 10:31:28 +01:00
Dmitry Stogov
c732ab400a Change Zend Stream API to use zend_string* instead of char*.
This allows to eliminate re-calculation of string lenght and hash value.
See the detailed list of changes in UPGRADING.INTERNALS.
2021-03-16 20:31:36 +03:00