Commit graph

776 commits

Author SHA1 Message Date
Niels Dossche
b7a158a19b
Fix incorrect page_size check
The current check always evaluated to false because if `!page_size`
is true, then `page_size & (page_size - 1)` equals `0 & (0 - 1)` which
is always 0. The if condition is meant to check if page_size is zero or
not a power of two, thus we must change the AND to an OR to fix this
issue.

Closes GH-10427

Signed-off-by: George Peter Banyard <girgias@php.net>
2023-01-25 00:06:56 +00:00
Max Kellermann
bff7a56d00
Revert "ext/opcache: use C11 atomics for "restart_in" (#10276)" (#10339)
* Revert "ext/opcache: use C11 atomics for "restart_in" (#10276)"

This reverts commit 061fcdb0a5.

While the commit does indeed improve performance, @dstogov complained
that it disables the code path calling kill_all_lockers(), and thus
hanging workers are never killed and restarted.
https://github.com/php/php-src/pull/10276#issuecomment-1383593046

The fact that this feature was not implemented in the existing atomic
code path (i.e. Windows) did not mean that the feature was considered
not strictly necessary, but that the Windows implementation just did
not need the feature because SAPIs that work on Windows do not manage
child processes
https://github.com/php/php-src/pull/10276#issuecomment-1383868696
https://github.com/php/php-src/pull/10276#issuecomment-1384235011

* ext/opcache: document lack of kill_all_lockers() on Windows

kill_all_lockers() is not implemented on Windows, and does not need to
be.
2023-01-19 16:55:48 +01:00
Max Kellermann
061fcdb0a5
ext/opcache: use C11 atomics for "restart_in" (#10276)
Cheaper than fcntl(F_SETLK).  The same is done already on Windows, so
if that works, why not use it everywhere?  (Of course, only if the
compiler supports this C11 feature.)

As a bonus, the code in this commit also works on C++ via C++11
std::atomic, just in case somebody adds some C++ code to the opcache
extension one day.
2023-01-13 00:02:35 +01:00
Ilija Tovilo
08fb7f93a1
Merge branch 'PHP-8.2'
* PHP-8.2:
  Initialize ping_auto_globals_mask to prevent undefined behaviour
2022-12-22 15:00:14 +01:00
Ilija Tovilo
c714e626c8
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Initialize ping_auto_globals_mask to prevent undefined behaviour
2022-12-22 15:00:00 +01:00
Niels Dossche
c4487b7a12
Initialize ping_auto_globals_mask to prevent undefined behaviour
Closes GH-10121
2022-12-22 14:59:24 +01:00
Arnaud Le Blanc
1cba98ebe9 Merge branch 'PHP-8.2'
* PHP-8.2:
  [ci skip] NEWS
  [ci skip] NEWS
  Do not resolve constants on non-linked class during preloading (#9975)
2022-11-25 14:37:55 +01:00
Arnaud Le Blanc
5563535e97 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  [ci skip] NEWS
  Do not resolve constants on non-linked class during preloading (#9975)
2022-11-25 14:11:52 +01:00
Arnaud Le Blanc
91b3b58f71
Do not resolve constants on non-linked class during preloading (#9975)
Fixes GH-9968
2022-11-25 14:02:45 +01:00
Bob Weinand
2cab4874ad Merge branch 'PHP-8.2' 2022-11-09 16:36:50 +01:00
Bob Weinand
4052bbf0e3 Fix opcache preload with observers enabled
Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-11-09 16:36:28 +01:00
Kévin Dunglas
7acb7703e2
opcache: add FrankenPHP to the allow list 2022-10-20 15:08:03 +02:00
Kévin Dunglas
c8c09b4aae opcache: add FrankenPHP to the allow list 2022-10-15 14:30:17 +02:00
Arnaud Le Blanc
2864282725 Improve warning message 2022-10-07 15:48:05 +02:00
Arnaud Le Blanc
722ed598d5 Do not require opcache.preload_user in cli SAPIs 2022-10-07 15:48:05 +02:00
Arnaud Le Blanc
73dabdfebe Refactor accel_finish_startup 2022-10-07 15:48:05 +02:00
Dmitry Stogov
7d794c0d33 Merge branch 'PHP-8.2'
* PHP-8.2:
  Intern string values of internal classes to prevent their future interning during inheritance.
2022-09-20 20:46:54 +03:00
Dmitry Stogov
bda449afe8 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Intern string values of internal classes to prevent their future interning during inheritance.
2022-09-20 20:46:44 +03:00
Dmitry Stogov
3a46f9fd1d Intern string values of internal classes to prevent their future interning during inheritance. 2022-09-20 20:43:29 +03:00
Dmitry Stogov
8f3c1940f9 Merge branch 'PHP-8.2'
* PHP-8.2:
  Reorder conditions to avoid valgrind "Conditional jump or move depends on uninitialised value" warning.
2022-09-19 17:19:38 +03:00
Dmitry Stogov
5a868022e7 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Reorder conditions to avoid valgrind "Conditional jump or move depends on uninitialised value" warning.
2022-09-19 17:19:28 +03:00
Dmitry Stogov
20d1d234ca Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Reorder conditions to avoid valgrind "Conditional jump or move depends on uninitialised value" warning.
2022-09-19 17:19:19 +03:00
Dmitry Stogov
e488f7b0eb Reorder conditions to avoid valgrind "Conditional jump or move depends on uninitialised value" warning. 2022-09-19 17:17:53 +03:00
Arnaud Le Blanc
0a9a8a90ae
Fix GH-9139: Allow FFI in opcache.preload when opcache.preload_user=root (#9473) 2022-09-09 11:00:57 +02:00
Arnaud Le Blanc
fb242f41ba
Fix high opcache.interned_strings_buffer causing shm corruption (#9260) 2022-09-03 11:23:10 +02:00
Bob Weinand
bf427b732a Add an API to observe functions and classes being linked
To observe when the functions and classes start being officially available to the user

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-08-23 15:22:22 +02:00
Christoph M. Becker
9313cd899e
Don't enforce 64 hit counter on Windows
There is no particular need to have a 64bit hit counter on Windows.

Closes GH-9367.
2022-08-22 17:49:30 +02:00
Jakub Zelenka
438f692e92
Merge branch 'PHP-8.1' 2022-08-12 17:12:28 +01:00
Jakub Zelenka
d0527427be
Fix GH-8409: SSL handshake timeout persistent connections hanging
This is not actually related to SSL handshake but stream socket creation
which does not clean errors if the error handler is set. This fix
prevents emitting errors until the stream is freed.
2022-08-12 17:09:24 +01:00
dixyes
3a843f953b
Windows arm64 zend and standard extension support
* Port zend_cpuid for windows arm64
* Fix zend_atomic windows arm64 build
* Fix windows arm64 multiply
* Enable arm64 neon for windows in standard extension
* Enable arm64 neon for windows in zend_hash.c
* Workaround for msvc arm64 optimization bug

Closes GH-9115.
2022-08-09 12:45:14 +02:00
iamluc
eac6330c72
[ci skip] Fix typo (proloading → preloading)
Closes GH-9076.
2022-07-21 12:35:15 +02: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
0429159775
Fully convert accel_remap_huge_pages to use zend_result
Changes were lost during rebase...
2022-06-22 18:10:05 +02:00
Ilija Tovilo
1380b65d26
Remove reundant address comparison in accel_remap_huge_pages
Closes GH-8830

MAP_FIXED guarantees mmap will return that exact address or fail so the
address comparison is redundant.

The return value of this function is unused but I kept it because it
improves readability.
2022-06-22 18:01:53 +02:00
Max Kellermann
e67565f54c
Zend, ext/opcache: use PR_SET_VMA_ANON_NAME (Linux 5.17) (#8234)
The new Linux 5.17 feature PR_SET_VMA_ANON_NAME can give names to
anonymous private memory, see:

 https://lwn.net/Articles/867818/

It can be useful while debugging, to identify which portion of the
process's memory belongs to which subsystem.

This is how /proc/PID/maps can look like:

 555ccd400000-555ccdc00000 r-xp 00000000 00:00 0                          [anon:huge_code_pages]
 7f6ec6600000-7f6ec6800000 rw-p 00000000 00:00 0                          [anon:zend_alloc]

The first mapping is the PHP executable copied to anonymous memory by
option "opcache.huge_code_pages".  The second one is a memory area for
the "zend_alloc.h" memory allocator library.

Unfortunately, it is not possible to give names to shared memory
(MAP_SHARED),  because Linux MAP_SHARED really maps /dev/zero (see
shmem_zero_setup()), which makes madvise_vma_anon_name() believe this
is a file mapping, failing the prctl() with EBADF.
2022-06-20 12:27:01 +01:00
George Peter Banyard
926407f224
Fix some MSAN complaints under Clang (#8553) 2022-05-13 23:30:20 +01:00
Max Kellermann
c732549200
ext/opcache/ZendAccelerator: fix accel_deactivate_now() prototype (#8541)
Fixes -Wstrict-prototypes warning introduced by commit 04a4864b65
2022-05-12 13:19:30 +02:00
Ilija Tovilo
3b4eaf67ec
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix preloading of constants containing enums
2022-04-21 11:59:15 +02:00
Ilija Tovilo
4397811db2
Fix preloading of constants containing enums
Fixes GH-8133
2022-04-21 11:57:12 +02:00
George Peter Banyard
2c2ecba063
Determine value of ZEND_MM_* during config and fix sign conversion (#6981)
Also add a new ZEND_MM_NEED_EIGHT_BYTE_REALIGNMENT definition.

This fixes many [-Wsign-conversion] warnings.

Co-authored-by: Guillaume Charifi <guillaume.charifi@sfr.fr>
Co-authored-by: Bob Weinand <bobwei9@hotmail.com>
2022-04-01 15:43:42 +01: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
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
Max Kellermann
b9b134de5c ext/opcache/ZendAccelerator: move duplicate code into bzero_aligned() 2022-03-20 20:42:14 +01:00
Max Kellermann
63281763bf ext/opcache/zend_shared_alloc: add zend_shared_alloc_aligned()
Eliminate some duplicate code.
2022-03-20 20:42:14 +01:00
Max Kellermann
82de4fcfe6
ext/opcache/ZendAccelerator: remove redundant check (#8222)
The "accelerator_enabled" flag has been checked already in the
previous "if".
2022-03-19 13:51:40 +00:00
Dmitry Stogov
529f9f8997 Merge branch 'PHP-8.1'
* PHP-8.1:
  Release lock and protect SHM before replaying warnings
2022-02-17 19:25:58 +03:00
Dmitry Stogov
90ca8f97de Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Release lock and protect SHM before replaying warnings
2022-02-17 19:25:42 +03:00
Dmitry Stogov
8f5480e7eb Release lock and protect SHM before replaying warnings 2022-02-17 19:16:15 +03:00
Tyson Andre
a5f782170b
Fix typos in opcache code comments, tests (#7794) 2021-12-19 10:04:09 -05:00
Dmitry Stogov
d339e5fcdc Merge branch 'PHP-8.1'
* PHP-8.1:
  Preloading: don't remove INCLUDE_OE_EVAL nstructions with used result
2021-12-14 11:37:52 +03:00