Commit graph

312 commits

Author SHA1 Message Date
Arnaud Le Blanc
7b3e68ff69
Fix error handling inconsistency with opcache
When opcache is enabled, error handling is altered in the following ways:

 * Errors emitted during compilation bypass the user-defined error handler
 * Exceptions emitted during class linking are turned into fatal errors

Changes here make the behavior consistent regardless of opcache being enabled or
not:

 * Errors emitted during compilation and class linking are always delayed and
   handled after compilation or class linking. During handling, user-defined
   error handlers are not bypassed. Fatal errors emitted during compilation or
   class linking cause any delayed errors to be handled immediately (without
   calling user-defined error handlers, as it would be unsafe).
 * Exceptions thrown by user-defined error handlers when handling class linking
   error are not promoted to fatal errors anymore and do not prevent linking.

Fixes GH-17422.
Closes GH-18541.
Closes GH-17627.

Co-authored-by: Tim Düsterhus <tim@bastelstu.be>
2025-07-27 11:01:49 +02:00
Ilija Tovilo
927aecaf6d
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix missing HAVE_JIT guard
2025-07-01 17:50:48 +02:00
Ilija Tovilo
c57ec92eb6
Fix missing HAVE_JIT guard
Closes GH-18993
2025-07-01 17:44:11 +02:00
Niels Dossche
4a98b36416
Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18898: SEGV zend_jit_op_array_hot with property hooks and preloading
2025-06-30 18:38:30 +02:00
Niels Dossche
53f2aa93ae
Fix GH-18898: SEGV zend_jit_op_array_hot with property hooks and preloading
Property hooks were not handled for JIT+trait+preloading.
Split the existing functions that handle op arrays, and add iterations
for property hooks.

Closes GH-18923.
2025-06-30 18:38:11 +02:00
DanielEScherzer
3f03f7ed3d
[RFC] Add support for attributes on compile-time constants
https://wiki.php.net/rfc/attributes-on-constants
2025-04-29 11:53:09 -07:00
Gina Peter Banyard
71da944c82 Zend: Add MUTABLE zend_type foreach macros and const qualifiers
The motivation for this is that types should be considered immutable.
The only times this is not valid is during compilation, optimizations (opcache), or destruction.

Therefore the "normal" type foreach macros are marked to take const arguments and we add mutable version that say so in the name.
Thus add various const qualifiers to communicate intent.
2025-04-07 12:52:40 +01:00
Bob Weinand
bcd7222522 Merge branch 'PHP-8.4' 2025-02-24 14:37:21 +01:00
Bob Weinand
53fa98ecd3
Fix GH-17715: Handle preloaded internal function runtime cache (#17835)
This solely affects the builtin enum functions currently.

Given that these are stored in SHM, we cannot simply hardwire a pointer into the internal function runtime cache on NTS too, but have to use a MAP_PTR (like on ZTS).
Now, by design, the runtime cache of internal functions no longer is reset between requests, hence we need to store them explicitly as static runtime cache.

On NTS builds we cannot trivially move the pointers into CG(internal_run_time_cache) as they're directly stored on the individual functions (on ZTS we could simply iterate the static map_ptrs).
Hence, we have the choice between having opcache managing the internal run_time_cache for its preloaded functions itself or realloc CG(internal_run_time_cache) and iterate through all functions to assign the new address. We choose the latter for simplicity and initial speed.
2025-02-24 14:35:47 +01:00
Tim Düsterhus
2042fd34e0
Support first-class callables in const-expressions (#17213)
RFC: https://wiki.php.net/rfc/fcc_in_const_expr

Co-authored-by: Volker Dusch <volker@tideways-gmbh.com>
2025-02-20 18:52:47 +01:00
Gina Peter Banyard
65d433161a
Use new known "self" and "parent" zend_strings (#17766) 2025-02-12 15:30:55 +00:00
Tim Düsterhus
cee64ed3bd
Add dedicated zend_ast_op_array struct (#17391)
Given that the `ZEND_AST_OP_ARRAY` type already needed special handling in
various places, it makes sense to give it its own struct to avoid some of the
casts. As a side benefit, it is a little smaller than the `zend_ast_zval`
struct.
2025-01-08 11:26:35 +01:00
Tim Düsterhus
fd1eacc2ed
Add assertions verifying that zend_ast_decl AST nodes are not treated as regular zend_ast nodes (#17390)
* zend_compile: Do not traverse children of ZEND_AST_CLOSURE in zend_compile_const_expr()

* Add assertions verifying that zend_ast_decl AST nodes are not treated as regular zend_ast nodes
2025-01-08 10:36:02 +01:00
Tim Düsterhus
f6a0bb4d04
Support Closures in constant expressions (#16458)
RFC: https://wiki.php.net/rfc/closures_in_const_expr

Co-authored-by: Volker Dusch <volker@tideways-gmbh.com>
Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
Co-authored-by: Arthur Kurbidaev <artkurbidaev@gmail.com>
2024-12-02 18:25:43 +01:00
Dmitry Stogov
eb89233800
Merge branch 'PHP-8.3'
* PHP-8.3:
  Don't set IS_STR_PERMANENT flag for strings stored in the file cache (#15643)
2024-08-30 01:01:33 +03:00
Dmitry Stogov
b55816e9d1
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Don't set IS_STR_PERMANENT flag for strings stored in the file cache (#15643)
2024-08-30 01:01:22 +03:00
Dmitry Stogov
afba2010c0
Don't set IS_STR_PERMANENT flag for strings stored in the file cache (#15643) 2024-08-30 00:59:06 +03:00
Dmitry Stogov
45dac39c71
Prevent JIT of propery hooks in case of file caching (related to GH-15497) 2024-08-29 16:54:25 +03:00
Dmitry Stogov
17e313ee62
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-15497: Opcache with file_cache and JIT enabled crashes (#15635)
2024-08-29 16:46:56 +03:00
Dmitry Stogov
fd42cdbd0a
Fix GH-15497: Opcache with file_cache and JIT enabled crashes (#15635) 2024-08-29 16:46:49 +03:00
Dmitry Stogov
d28b75f70d
Fix GH-15497: Opcache with file_cache and JIT enabled crashes (#15635) 2024-08-29 16:45:15 +03:00
Ilija Tovilo
780a8280d2
[RFC] Property hooks (#13455)
RFC: https://wiki.php.net/rfc/property-hooks

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2024-07-14 11:55:03 +02:00
Ilija Tovilo
858008b1c6
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix persisting of inherited class constants
2024-05-06 16:02:29 +02:00
Ilija Tovilo
929bbb23d1
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix persisting of inherited class constants
2024-05-06 16:02:20 +02:00
Ilija Tovilo
42ede5597e
Fix persisting of inherited class constants
Class constants are inherited to user classes without cloning. Thus, internal
class constants should not be persisted at all. Simply keep pointing to the
internal class constant.

Fixes GH-14109
Closes GH-14114
2024-05-06 16:00:48 +02:00
Niels Dossche
6316eb1b2c Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix GH-13433: Segmentation Fault in zend_class_init_statics when using opcache.preload
2024-03-26 21:29:29 +01:00
Niels Dossche
55e617691a Fix GH-13433: Segmentation Fault in zend_class_init_statics when using opcache.preload
This regressed in 9a250cc9d6, which allowed static properties to get
overridden by a trait during inheritance. In particular, because of the
change to the loop in zend_update_parent_ce(), it's not guaranteed that
all indirects are after one another.

This means that during persisting the zvals of the static members table,
some static properties may be skipped. In case of the test code, this
means that the array in the trait will keep referring to the old, new
freed, stale value. To solve this, we check the type for IS_INDIRECT,
which is the same as what zend_persist_calc() is already doing anyway.

Since 2543e61aed we can check for IS_INDIRECT to see if it should be
persisted or not.

Closes GH-13794.
2024-03-26 21:29:07 +01:00
Bob Weinand
9bed0b5f2f Merge branch 'PHP-8.3' 2024-03-18 19:06:12 +01:00
Bob Weinand
6d6cd29909 Merge branch 'PHP-8.2' of https://github.com/php/php-src into PHP-8.3 2024-03-18 19:04:12 +01:00
Bob Weinand
10d912d6e3
Fix GH-13712: Segmentation fault for enabled observers when calling trait method of internal trait when opcache is loaded (#13735)
Inherited methods regardless of source must share the original runtime cache. Traits were missed.
This adds ZEND_ACC_TRAIT_CLONE to internal functions as well to allow easy distinction of these.
2024-03-18 19:02:42 +01:00
Máté Kocsis
f2e199e878
Implement "support doc comments for internal classes and functions" (#13266)
Fixes #13130
2024-02-25 08:41:31 +01:00
Ilija Tovilo
49ebfb04ef
Fix JMP_FRAMELESS with ZEND_USE_ABS_JMP_ADDR
which is used on 32-bit machines.
2024-02-07 15:50:38 +01:00
Cristian Rodríguez
2196e2299f
Use zend_ast_size consistenly (#11955)
* opcache: use zend_ast_size helper in zend_persist_ast

* opcache: use zend_ast_size helper in zend_persist_ast_calc

* Zend: fix zend_ast_size definition

It is better not to use sizeof(struct_with_flexible_array)
and instead rely on offsetof(type, member) like most
other similar wrappers do.
2023-08-14 00:51:14 +02:00
George Peter Banyard
d5ad75108e
More usage of known zend_str instead of C string (#11381) 2023-06-08 13:03:29 +01:00
Ilija Tovilo
0b1d750d91
Allow arbitrary expressions in static variable initializer
Closes GH-9301
2023-05-24 20:17:31 +02:00
Máté Kocsis
414f71a902
Typed class constants (#10444)
RFC: https://wiki.php.net/rfc/typed_class_constants

Co-Authored-By: Ben <7127204+moliata@users.noreply.github.com>
Co-Authored-By: Bob Weinand <3154871+bwoebi@users.noreply.github.com>
Co-Authored-By: Ilija Tovilo <ilija.tovilo@me.com>
2023-04-16 22:20:26 +02:00
Ilija Tovilo
9a250cc9d6
Add separate static property through trait if parent already declares it
Fixes GH-10935
Closes GH-10937
2023-04-06 14:27:24 +02:00
Ilija Tovilo
9944f58d3f
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-10709: UAF in recursive AST evaluation
2023-03-06 15:03:19 +01:00
Ilija Tovilo
1978a7b393
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10709: UAF in recursive AST evaluation
2023-03-06 14:58:25 +01:00
Ilija Tovilo
7202fe16b7
Fix GH-10709: UAF in recursive AST evaluation
Fixes https://oss-fuzz.com/testcase-detail/6445949468934144
Closes GH-10718
2023-03-06 14:55:34 +01:00
Max Kellermann
413844d626
Zend/zend_types.h: deprecate zend_bool, zend_intptr_t, zend_uintptr_t (#10597)
These types are standard C99.

For compatibility with out-of-tree extensions, keep the typedefs
in main/php.h.
2023-02-18 19:31:28 +00:00
George Peter Banyard
64127b66c6 Concatenating two valid UTF-8 strings produces a valid UTF-8 string
The UTF-8 valid flag needs to be copied upon interning,
otherwise strings that are concatenated at compile time lose this information.

However, if previously this string was interned without the flag it is not added
E.g. in the case the string is an existing class name.

Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
2023-02-02 12:02:36 +00:00
Bob Weinand
b30448f48f Fix observing inherited internal functions
Fixes GH-9871
2022-11-02 15:33:04 +01:00
Bob Weinand
5e9654be03 Fixed missing run_time_cache for preloaded arena allocated internal functions
This effectively affected all preloaded enums, leading them to possibly share a run_time_cache__ptr slot with unrelated functions. (Given that these were not set again.)
This bugfix is not accompanied by a test, due to how hard to trigger it was and getting a crash also depends a lot on the precise alignment of whether a cache entry accidentally overlapping has been used etc.
2022-10-22 22:07:41 +00:00
Dmitry Stogov
34b11a7524 Fix memory leaks in
Zend/tests/type_declarations/union_types/inheritance.phpt introduced by f24548e217
2022-07-18 15:26:04 +03:00
Dmitry Stogov
f24548e217 Fix invalid free() during type persistence
Fixes oss-fuzz #49042
2022-07-18 15:11:02 +03:00
George Peter Banyard
f905590764
Add support for Disjoint Normal Form (DNF) types (#8725)
RFC: https://wiki.php.net/rfc/dnf_types

This allows to combine union and intersection types together in the following form (A&B)|(X&Y)|T but not of the form (X|A)&(Y|B) or (X|A)&(Y|B)|T.

* Improve union type parsing

Co-authored-by: Sara Golemon <pollita@php.net>
2022-07-08 11:30:23 +01:00
Ilija Tovilo
ddc0b490f7
Allow arbitrary const expressions in backed enums
Closes GH-7821
Closes GH-8190
Closes GH-8418
2022-06-12 22:56:05 +02:00
Max Kellermann
04a4864b65
ext/opcache: merge redundant code and "bool" refactoring (#8237)
* ext/opcache/ZendAccelerator: make check_persistent_script_access() static

* ext/opcache/ZendAccelerator: convert "int" to "bool"

* ext/opcache/zend_file_cache: convert "int" to "bool"

* ext/opcache: use true/false for zend_persistent_script.corrupted

* ext/opcache/ZendAccelerator: move duplicate code to zend_accel_discard_script()

* ext/opcache/ZendAccelerator: convert accel_deactivate_now() to function

Simplify the #iddef ZEND_WIN32.

* ext/opcache/zend_file_cache: simplify iovec initializer

* ext/opcache/zend_file_cache: add local zend_string* variables

Eliminates lots of redundant casts and avoids reloading the variable
from RAM into registers.

* ext/opcache/zend_file_cache: use ZSTR_VAL()

* ext/opcache/zend_file_cache: move code to zend_file_cache_script_write()

This eliminates duplicate error handling code.
2022-03-24 15:03:53 +01:00
Nikita Popov
4543cd32ae Remove JMPZNZ opcode
While JMPZNZ can avoid execution of a separate JMP opcode in some
cases, it also prevents smart branch optimization, so creating
JMPZNZ may actually have a negative effect. It also adds additional
complexity for optimizations.

Drop JMPZNZ in favor of JMPZ+JMP or JMPNZ+JMP.

Closes GH-7857.
2022-01-10 22:07:10 +01:00