[php-src] PR #19985: Bring back preloading on Windows
| From: | arnaud-lb | Date: | Mon, 29 Sep 2025 08:30:15 +0000 |
| Subject: | [php-src] PR #19985: Bring back preloading on Windows | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-33377@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/19985
Author: arnaud-lb
Support for preloading on Windows was removed in [1] [2]:
> On Windows, the preloading functionality is fairly crippled, because classes that reference
> internal classes or constants in some way cannot be preloaded due to ASLR restrictions. As this is a
> very significant restriction, it will not be possible to preload any non-trivial codebase on
> Windows.
This is because on Windows the opcache SHM may be reattached from different processes, whose address
layout is different, due to ASLR. Therefore SHM can't reference non-SHM addresses on Windows.
One solution is to drop support for reattachment, as suggested in [3]. Merging [4] would ensure that
the Apache2 SAPI doesn't need reattachment at all. [5] would ensure that we have at least 2
Windows SAPIs that don't need reattachment. The FastCGI SAPI would consume more memory.
I've also suggested this in [4][7], but this didn't get traction.
But, what seems to have passed under the radars is that since 7.4 we don't reattach at all when
ASLR is enabled (or at least when the address layout changed) [6]. Therefore any of the ASLR-related
limitations no longer have a reason to exist, as we never have reattachment and ASLR at the same
time.
Therefore we could bring back preloading on Windows. This is what this PR does.
Alternatively we could bring back reattachment on ASLR by fixing the invariant "SHM can not
reference non-SHM addresses". We can achieve this by adding indirections in places that
reference non-SHM addresses, such as in
zend_op.handler. As this invariant has not be
tested for 6 years, we may discover that other places need to be fixed. We could bring back
preloading on Windows if we added these indirections on zend_class_entry.parent and
other references to internal definitions. However this adds complexity and slows down the VM.
Any thoughts?
* [1] https://github.com/php/php-src/commit/59c3ddab13b5cc38e9406538801be8e134626793
* [2] https://github.com/php/php-src/pull/4999
* [3] https://github.com/php/php-src/pull/4999#issuecomment-564461618
* [4] https://github.com/php/php-src/pull/7865
* [5] https://github.com/php/php-src/pull/17838
* [6] https://github.com/php/php-src/commit/8ba10b8fbc020dc225d3b19d8f088f1351a3e304