1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

860 Commits

Author SHA1 Message Date
Weilin Du
2918caee20 ext/*: Remove break after return (#21485) 2026-03-23 20:30:13 +01:00
Ilija Tovilo
084e409694 Remove zend_exception_save() and zend_exception_restore()
These are leftovers from the pre-PHP-7.0 era. This also implicitly solves
GH-20564 by not clearing exceptions before entering the autoloader.

Closes GH-20256
Fixes GH-20564
2026-01-16 20:18:51 +01:00
Arnaud Le Blanc
626f3c3c7c Unify arg info representation for internal and user functions
The arg_info member of zend_function is now always a zend_arg_info*. Before,
it was a zend_internal_arg_info* on internal functions, unless the
ZEND_ACC_USER_ARG_INFO flag was set.

Closes GH-19022
2025-12-15 16:50:49 +01:00
Linus Groh
d4f1300011 opcache: Remove unused sys/ipc.h include from ZendAccelerator.c (#20662)
As far as I can tell that's been there since the initial open source
release (commit 528006a). The header defines ftok() and a handful of
IPC_* constants, none of which are used here.

System V IPC is increasingly being replaced by POSIX IPC and may
therefore not be implemented on new and/or hobbyist operating systems
such as SerenityOS[1]. In the past that wasn't an issue as the OPCache
could be disabled, which is no longer possible as of PHP 8.5[2].

I was able to build with the include patched out, but we would prefer
this to be addressed upstream.

1: https://github.com/SerenityOS/serenity/pull/26465
2: https://github.com/php/php-src/pull/18961
2025-12-07 22:48:43 +01:00
Arnaud Le Blanc
8f488f9556 Mask USR1/HUP while waiting for preloading
Preloading may fork and wait for the child to exit. In case waitpid() is
interrupted, the parent exits with a fatal error. This is fine when the
syscall is interrupted by a signal whose disposition is set to terminate
the process, but not otherwise.

In the apache2handler SAPI, the parent is the control process. Restarting
apache2 is done by sending SIGUSR1 or SIGHUP to the control process. Doing that
during the waitpid() syscall would cause the control process to exit instead.

Block the USR1 and HUP signals from being delivered during the syscall when
running the apache2handler SAPI, as these are not supposed to terminate
the process.

FPM is fine as it masks relevant signals during php startup.

Fixes GH-20051
Closes GH-20079

Co-authored-by: mycozyhom <welcomycozyhom@gmail.com>
2025-10-10 15:48:08 +02:00
Arnaud Le Blanc
ce7d4e726c Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix access to uninitialized variables in preload_load()
2025-10-10 15:45:34 +02:00
Arnaud Le Blanc
01e34156a8 Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix access to uninitialized variables in preload_load()
2025-10-10 15:45:22 +02:00
Arnaud Le Blanc
27807fd0f1 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix access to uninitialized variables in preload_load()
2025-10-10 15:44:33 +02:00
Arnaud Le Blanc
ab9d121f48 Fix access to uninitialized variables in preload_load()
preload_load() reads EG(class_table) and EG(function_table), but these may not
be initialized. Move these accesses out of preload_load().

Closes GH-20081
2025-10-10 15:42:58 +02:00
Ilija Tovilo
292e0c2937 Add ce_flags2 & fn_flags2 (GH-19991) 2025-09-30 22:54:59 +02:00
Ilija Tovilo
bcd4be7d50 Fix double-free of EG(errors)/persistent_script->warnings on persist of already persisted file
Both processes race to compile warning_replay.inc. Whichever is first will get
to persist the script. The loser will use the script that is already persisted,
and the script that was just compiled is freed.

However, EG(errors) and persistent_script->warnings still refer to the same
allocation, and EG(errors) becomes a dangling pointer. To solve this, we simply
don't free warnings from free_persistent_script() anymore to maintain exclusive
ownership for EG(errors).

Furthermore, we need to adjust a call to zend_emit_recorded_errors() that would
previously use EG(errors), even when persistent_script has been swapped out.

Fixes GH-19984
Closes GH-19995
2025-09-30 22:53:25 +02:00
Arnaud Le Blanc
0ee7732c01 Fix opcache.huge_code_pages
Building opcache into the main executable breaks opcache.huge_code_pages,
as we were relying on the fact that accel_remap_huge_pages() is not in the
same mapping as the main text segment.

Here I ensure that accel_remap_huge_pages() is placed out of the text
segment, and remap only the text segment. This approach is used in [1].

Closes GH-19388.

[1] 676bb7dec3/large_page-c/large_page.c (L260).
2025-09-01 19:36:11 +02:00
Arnaud Le Blanc
e4078a6a70 Disable opcache if no SHM backend is available
Currently, configure fails when no SHM backend is available. Additionally,
even after bypassing the configure check, opcache emits a fatal error if no
SHM backend is available.

Make the configure check non-fatal (a warning is printed). At runtime, disable
opcache if no backend is available, in the same way we disable opcache by
default on CLI.

Closes GH-19350
2025-08-08 14:41:37 +02:00
Arnaud Le Blanc
32290b3529 Add opcache_preloading() internal function
Add a C function, opcache_preloading(), that returns true during
preloading. Extensions can use this to detect preloading, not only during
compilation/execution, but also in RINIT()/RSHUTDOWN().

Since opcache currently doesn't install any header, I'm adding a new one:
zend_accelerator_api.h. Header name is based on other files in ext/opcache.

Closes GH-19288
2025-08-06 18:21:19 +02:00
Arnaud Le Blanc
3088d64068 Remove the Opcache SAPI whitelist
Closes GH-19351
2025-08-06 18:14:10 +02:00
Arnaud Le Blanc
3ddbad9589 Allocate a fast thread-safe-resource id for opcache
Closes GH-19347
2025-08-06 18:02:43 +02:00
Niels Dossche
0591defd6f Merge branch 'PHP-8.4'
* PHP-8.4:
  Remove dynamic defs from property hooks
  Add missing hooks JIT restart code
2025-07-31 20:22:20 +02:00
Niels Dossche
771bfaf34d Remove dynamic defs from property hooks
Otherwise this hits an assertion failure in pass2 reversal and causes a
subsequent crash.

Closes GH-19206.
2025-07-31 20:22:11 +02:00
Arnaud Le Blanc
712508fdb2 Call php_child_init() after fork during preloading (#19287) 2025-07-29 16:10:35 +02:00
Ilija Tovilo
35a4656a59 Fix error recording with file cache only (GH-19278)
Introduced by GH-18541.

This path is hit when compilation fails with a compile error, rather than
bailout. If a non-fatal error is recorded, it will not be emitted nor freed.
Handle accordingly.
2025-07-29 10:06:43 +02:00
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
Arnaud Le Blanc
7b4c14dc10 Make OPcache non-optional
This removes the --enable-opcache/--disable-opcache configure switch. OPcache
is now always builtin. The default value of opcache.enable and
opcache.enable_cli is unchanged.

RFC: https://wiki.php.net/rfc/make_opcache_required

Closes GH-18961.

Co-authored-by: Tim Düsterhus <tim@tideways-gmbh.com>
2025-07-27 09:40:22 +02:00
Tim Düsterhus
a2d8ee27f2 opcache: Disallow changing opcache.memory_consumption when SHM is set up (#19146)
* opcache: Reset `accel_startup_ok` after shutting down

This is necessary for phpdbg, which runs multiple startup/shutdown cycles in
the same process.

* opcache: Disallow changing `opcache.memory_consumption` when SHM is set up

Normally changing the INI value is not possible after SHM is set up, since it
is `PHP_INI_SYSTEM`. FPM is a notable exception: SHM is set up in the master
process, but when spawning the individual pools, the `php_admin_value` config
option can be used to change `PHP_INI_SYSTEM` INIs on a per-pool basis. This
does not work for this option, since it will only be read on early start,
leading to misleading PHPInfo output, since the INI value appears to be
successfully set and since some of the calculated values are derived from the
INI value rather than the actual value.
2025-07-25 18:36:47 +02:00
Niels Dossche
d8c48903c4 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-14082: Segmentation fault on unknown address 0x600000000018 in ext/opcache/jit/zend_jit.c
2025-06-23 22:29:00 +02:00
Niels Dossche
3664f4a859 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-14082: Segmentation fault on unknown address 0x600000000018 in ext/opcache/jit/zend_jit.c
2025-06-23 22:28:00 +02:00
Niels Dossche
1e3d92f8a9 Fix GH-14082: Segmentation fault on unknown address 0x600000000018 in ext/opcache/jit/zend_jit.c
During persisting, the JIT may trigger and fill in the call graph.
The call graph info is allocated on the arena which will be gone after preloading.
To prevent invalid accesses during normal requests, the arena data should be cleared.
This has to be done after all scripts have been persisted because shared op arrays between
scripts can change the call graph.

Closes GH-18916.
2025-06-23 22:27:36 +02:00
DanielEScherzer
cd751f98cb Reapply GH-17712 with a fix for internal class constants (#18464)
Add recursion protection when emitting deprecation warnings for class
constants, since the deprecation message can come from an attribute that is
using the same constant for the message, or otherwise result in recursion.

But, internal constants are persisted, and thus cannot have recursion
protection. Otherwise, if a user error handler triggers bailout before the
recursion flag is removed then a subsequent request (e.g. with `--repeat 2`)
would start with that flag already applied. Internal constants can presumably
be trusted not to use deprecation messages that come from recursive attributes.

Fixes GH-18463
Fixes GH-17711
2025-05-25 16:43:36 -07:00
Niels Dossche
b2d78ae00c Backport accel_globals->key leak fix (8.3)
Closes GH-18602.
2025-05-19 22:27:54 +02:00
Niels Dossche
146157ddf0 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix leak of accel_globals->key
2025-05-19 19:34:27 +02:00
Niels Dossche
db3bf715e0 Fix leak of accel_globals->key
I don't know why this was guarded with ZTS, but it leaks on this test
(and a few more):
`./sapi/cli/php ./run-tests.php -c . --show-diff sapi/phpdbg/tests/stdin_001.phpt`

Closes GH-18593.
2025-05-19 19:34:16 +02:00
Niels Dossche
383aad8007 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18534: FPM exit code 70 with enabled opcache and hooked properties in traits
2025-05-19 19:22:16 +02:00
Niels Dossche
6b795f64a5 Fix GH-18534: FPM exit code 70 with enabled opcache and hooked properties in traits
The trait handling for property hooks in preloading did not exist, we
add a check to skip trait clones and we add the necessary code to update
the op arrays.

Closes GH-18586.
2025-05-19 19:21:53 +02:00
Niels Dossche
94f5037ac3 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18567: Preloading with internal class alias triggers assertion failure
2025-05-19 19:20:16 +02:00
Niels Dossche
43915b302c Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-18567: Preloading with internal class alias triggers assertion failure
2025-05-19 19:20:11 +02:00
Niels Dossche
41e11a627d Fix GH-18567: Preloading with internal class alias triggers assertion failure
The assertion is imprecise now, and the code assumed that from the
moment an internal class was encountered that there were only internal
classes remaining. This is wrong now, and we still have to continue if
we encounter an internal class. We can only skip the remaining iterations
if the entry in the hash table is not an alias.

Closes GH-18575.
2025-05-19 19:19:26 +02:00
Saki Takamachi
47354a7404 Added zend_simd.h (#18413) 2025-05-16 15:42:20 +09:00
Ilija Tovilo
386ab1dad2 Revert "Fix infinite recursion on deprecated attribute evaluation"
This reverts commit 272f7f75e2.

Reverts GH-17712 for the PHP-8.4 branch. This will be reapplied later
with a fix for GH-18463 (GH-18464).
2025-04-30 20:52:56 +02: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
Ilija Tovilo
99f72fa499 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix infinite recursion on deprecated attribute evaluation
2025-03-26 23:40:58 +01:00
Ilija Tovilo
272f7f75e2 Fix infinite recursion on deprecated attribute evaluation
Fixes GH-17711
Fixes GH-18022
Closes GH-17712
2025-03-26 23:39:38 +01:00
Ilija Tovilo
076811af68 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix segfault when evaluating const expr default value of child prop with added hooks
2025-03-23 16:35:21 +01:00
Ilija Tovilo
d5bdf8f508 Fix segfault when evaluating const expr default value of child prop with added hooks
Introduced by GH-17870. Not adding a NEWS entry since this is fixed in
the same version.

Fixes oss-fuzz #403816122
Closes GH-18098
2025-03-23 16:35:04 +01:00
Niels Dossche
38d6d8542b Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18112: NULL access with preloading and INI option
2025-03-20 19:12:53 +01:00
Niels Dossche
66498152f1 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-18112: NULL access with preloading and INI option
2025-03-20 19:12:47 +01:00
Niels Dossche
e9c0296240 Fix GH-18112: NULL access with preloading and INI option
Preloading shutdown calls request shutdown which will deactivate the
virtual cwd state. However, further startup code still assumes the state
that was set by virtual_cwd_startup(). So we need to reactivate it
manually.

Creating a test was a bit difficult because the INI setting I wanted to
test this with is overridden by the test runner apparently.
To reproduce the issue, create an empty file test.php and execute this
in a ZTS build:
`php -d opcache.preload=./ext/opcache/tests/preload_class_alias_2.inc -d "error_log=" -d "allow_url_include=1" test.php`

Closes GH-18117.
2025-03-20 19:12:06 +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
David Carlier
f89b0a229c Merge branch 'PHP-8.4' 2025-02-23 10:45:55 +00:00
David Carlier
e8dda54dd5 Merge branch 'PHP-8.3' into PHP-8.4 2025-02-23 10:45:46 +00:00
David Carlier
cefdf00e7e Fix GH-17899: zend_test_compile_string crash on invalid script path.
when opcache is enabled.

close GH-17901
2025-02-23 10:45:10 +00:00