Commit Graph

81 Commits

Author SHA1 Message Date
Niels Dossche
124c812542 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-12392: Segmentation fault on SoapClient::__getTypes
  Fix GH-11121: ReflectionFiber segfault
  [ci skip] NEWS
2023-10-11 17:27:54 +02:00
Niels Dossche
d8cd0f4ba0 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-12392: Segmentation fault on SoapClient::__getTypes
  Fix GH-11121: ReflectionFiber segfault
  [ci skip] NEWS
2023-10-11 17:23:17 +02:00
Daniil Gentili
71f14510f6 Fix GH-11121: ReflectionFiber segfault
Closes GH-12391.

Co-authored-by: Aaron Piotrowski <aaron@trowski.com>
2023-10-11 17:19:01 +02:00
Ilija Tovilo
8d8cfe24d3
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix potential NULL pointer access in zend_fiber_object_gc
2023-05-11 14:35:42 +02:00
Ilija Tovilo
0a04c008d0
Fix potential NULL pointer access in zend_fiber_object_gc
Accidentally introduced in GH-11208.

Fixes oss-fuzz #58795
2023-05-11 14:33:49 +02:00
Ilija Tovilo
173680acd3
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix use-of-undefined in zend_fiber_object_gc of ex->call
2023-05-09 14:38:25 +02:00
Ilija Tovilo
06fe9ff0f1
Fix use-of-undefined in zend_fiber_object_gc of ex->call
ex->call is only set for user calls, we shouldn't access it here.
zend_unfinished_execution_gc_ex wouldn't actually use it for internal calls, so
it didn't cause any serious issues.

Closes GH-11208
2023-05-09 14:37:47 +02:00
Max Kellermann
371ae12d89 Zend/zend_fibers: change return value to zend_result
According to @nikic:

> The current guideline for use of bool and zend_result in php-src is
> that bool is an appropriate return value for "is" or "has" style
> functions, which return a yes/no answer. zend_result is an
> appropriate return value for functions that perform some operation
> that may succeed or fail.

Closes GH-10622.
2023-02-26 15:07:08 +00:00
Bob Weinand
71f2d60cb0 Merge branch 'PHP-8.2' 2023-02-13 16:34:36 +00:00
Bob Weinand
98b8d1c152 Merge branch 'PHP-8.1' into PHP-8.2 2023-02-13 16:34:19 +00:00
Bob Weinand
95016138a5 Fix GH-10496: Fibers must not be garbage collected while implicitly suspended by resumption of another fiber 2023-02-13 16:30:21 +00:00
Bob Weinand
e8d16fda13 Merge branch 'PHP-8.2' 2023-02-13 13:10:44 +01:00
Bob Weinand
0e31e03bc5 Merge branch 'PHP-8.1' into PHP-8.2 2023-02-13 13:10:08 +01:00
Arnaud Le Blanc
d721dcc2ef Fix colletion of unfinished function call in fibers
Fixes GH-10496.

Co-authored-by: Bob Weinand <bobwei9@hotmail.com>
2023-02-13 13:09:04 +01:00
Aaron Piotrowski
ff84598055
Merge branch 'PHP-8.2'
* PHP-8.2:
  [ci skip] NEWS
  Fix GH-10437: Set active fiber to null on bailout (#10443)
2023-01-28 10:18:51 -06:00
Aaron Piotrowski
0c4aee464a
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10437: Set active fiber to null on bailout (#10443)
2023-01-28 10:16:04 -06:00
Aaron Piotrowski
284c29328e
Fix GH-10437: Set active fiber to null on bailout (#10443) 2023-01-28 10:13:58 -06:00
Arnaud Le Blanc
ebf26af71a Merge branch 'PHP-8.2'
* PHP-8.2:
  Handle non-INDIRECT symbol table entries in zend_fiber_object_gc() (#10386)
2023-01-27 10:55:40 +01:00
Arnaud Le Blanc
ab2097df48 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Handle non-INDIRECT symbol table entries in zend_fiber_object_gc() (#10386)
2023-01-27 10:55:30 +01:00
Arnaud Le Blanc
9830204213
Handle non-INDIRECT symbol table entries in zend_fiber_object_gc() (#10386)
Fixes GH-10340
2023-01-27 10:52:42 +01:00
Christoph M. Becker
c8955c078a
Revert GH-10220
Cf. <https://github.com/php/php-src/pull/10220#issuecomment-1383739816>.

This reverts commit ecc880f491.
This reverts commit 588a07f737.
This reverts commit f377e15751.
This reverts commit b4ba16fe18.
This reverts commit 694ec1deea.
This reverts commit 6b34de8eba.
This reverts commit aa1cd02a43.
This reverts commit 308fd311ea.
This reverts commit 16203b53e1.
This reverts commit 738fb5ca54.
This reverts commit 9fdbefacd3.
This reverts commit cd4a7c1d90.
This reverts commit 928685eba2.
This reverts commit 01e5ffc85c.
2023-01-16 12:27:33 +01:00
Arnaud Le Blanc
ba091ab3c7 Merge branch 'PHP-8.2'
* PHP-8.2:
  [ci skip] NEWS
  Reduce HT_MAX_SIZE to account for the max load factor of 0.5 (#10242)
  GC fiber unfinished executions (#9810)
2023-01-13 12:31:12 +01:00
Arnaud Le Blanc
d89408075f Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Reduce HT_MAX_SIZE to account for the max load factor of 0.5 (#10242)
  GC fiber unfinished executions (#9810)
2023-01-13 12:28:21 +01:00
Arnaud Le Blanc
4fb149390a
GC fiber unfinished executions (#9810) 2023-01-13 12:04:28 +01:00
David Carlier
41c0304647 Merge branch 'PHP-8.2' 2023-01-12 22:01:39 +00:00
David Carlier
884e8a970a Merge branch 'PHP-8.1' into PHP-8.2 2023-01-12 22:01:30 +00:00
Niels Dossche
833b45ac44 Fix GH-10249: Assertion `size >= page_size + 1 * page_size' failed.
Co-authored-by: Changochen <changochen1@gmail.com>

Closes GH-10284
2023-01-12 22:00:00 +00:00
Max Kellermann
aa1cd02a43 Zend/zend_fibers: include cleanup 2023-01-10 14:19:03 +00:00
Arnaud Le Blanc
a11c8a3039
Limit stack size (#9104) 2022-12-16 17:44:26 +01:00
Chen, Hu
37b84b7e32
Fiber: add shadow stack support
Shadow stack is part of Intel's Control-Flow Enforcement Technology (CET).

Whenever a function is called, the return address is pushed onto both
the regular stack and the shadow stack. When that function returns, the
return addresses are popped off both stacks and compared; if they fail
to match, #CP raised.

With this commit, we create shadow stack for each fiber context and
switch the shadow stack accordingly during fcontext switch.

Signed-off-by: Chen, Hu <hu1.chen@intel.com>

Closes GH-9283.
2022-11-07 14:48:27 +01:00
Bob Weinand
5a0b68bed7 Revert "Store default object handlers alongside the class entry"
This reverts commit 9e6eab3c13.

Reverted along a01dd9feda.
2022-09-14 11:18:14 +02:00
Bob Weinand
9e6eab3c13 Store default object handlers alongside the class entry
Object handlers being separate from class entries is a legacy inherited from PHP 5. Today it has little benefit to keep them separate: in fact, accessing object handlers usually requires not-so-safe hacks.
While it is possible to swap handlers in a custom installed create_object handler, this mostly is tedious, as well as it requires allocating the object handlers struct at runtime, possibly caching it etc..

This allows extensions, which intend to observe other classes to install their own class handlers.
The life cycle of internal classes may now be simply observed by swapping the class handlers in post_startup stage.
The life cycle of userland classes may be observed by iterating over the new classes in zend_compile_file and zend_compile_string and then swapping their handlers.

In general, this would also be a first step in directly tying the object handlers to classes. Especially given that I am not aware of any case where the object handlers would be different between various instances of a given class.

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-08-31 16:45:27 +02:00
Bob Weinand
8fe1db2089 Delay fiber VM stack cleanup until after observer has been called
Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-08-29 12:17:12 +02:00
Martin Schröder
0adbf9c2d4
Fix memory leak in fiber constructor by throwing an error (#9098) 2022-07-22 10:47:47 -05: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
Chen
040a37d3f1
Add IBT support for fiber
Indirect Branch Tracking (IBT) is part of Intel's Control-Flow
Enforcement Technology (CET). IBT is hardware based, forward edge
Control-Flow-Integrity mechanism where any indirect CALL/JMP must target
an ENDBR instruction or suffer #CP.

This commit adds IBT support for fiber:
1. Add endbr32/64 in assembly
2. Inform compiler jump_fcontext may return via indirect branch

Furthermore:
gcc support CET since v8.1 and set it to default since gcc 11. That is,
the ELF header of sapi/cli/php has a property named IBT. However, such
property is lost since PHP8.1 because the assembly introduced by Fiber.
This commit also fixes this.

Closes GH-8339

Signed-off-by: Chen, Hu <hu1.chen@intel.com>
Co-authored-by: Christoph M. Becker <cmbecker69@gmx.de>
2022-05-25 13:42:31 -05:00
Petr Sumbera
069bbf3e80
Fix zend_fibers.c build with ZEND_FIBER_UCONTEXT
Avoids (Solaris SPARC) issue:
  zend_fibers.c:77:9: error: unknown type name 'ucontext_t'

Closes GH-7773.
2021-12-20 14:21:50 +01:00
Nikita Popov
578b785ecf Don't return reference from Fiber::getReturn()
Even if the fiber function returns by reference, we must return
a value from Fiber::getReturn() to satisfy the function signature.

Fixes oss-fuzz #36417.
2021-07-22 09:44:19 +02:00
Joe Watkins
848b5458d1
more fiber notifications (#7293) 2021-07-21 17:18:15 +02:00
Joe Watkins
576655e23f
drop unused header in fibers 2021-07-20 22:22:53 +02:00
Nikita Popov
814a932734 Add ZEND_ACC_NOT_SERIALIZABLE flag
This prevents serialization and unserialization of a class and its
children in a way that does not depend on the zend_class_serialize_deny
and zend_class_unserialize_deny handlers that will be going away
in PHP 9 together with the Serializable interface.

In stubs, `@not-serializable` can be used to set this flag.

This patch only uses the new flag for a handful of Zend classes,
converting the remainder is left for later.

Closes GH-7249.
Fixes bug #81111.
2021-07-19 15:59:11 +02:00
Aaron Piotrowski
8fd747a2a0
Fiber ucontext support (#7226)
Co-authored-by: Martin Schröder <m.schroeder2007@gmail.com>
2021-07-11 15:40:11 -05:00
Patrick Allaert
aff365871a Fixed some spaces used instead of tabs 2021-06-29 11:30:26 +02:00
Aaron Piotrowski
66442a51d1
Allow creating Graceful/UnwindExit and use when destroying a fiber (#7174)
Direct creation of GracefulExit allows the the special exception object to be transfered and thrown into a destroyed fiber using the same path as any other exception thrown into a fiber instead of needing to check for a flag.
2021-06-28 15:23:34 -05:00
Martin Schröder
7713302fbd Implemented Fiber GC handler 2021-06-28 13:08:48 +02:00
Aaron Piotrowski
15dcdd7672
Remove copying of fiber result to transfer value
Removes unnecessary copying of fiber return value to transfer value. This zval was not used as the return of start/resume/throw, instead being destroyed when the fiber was dead. Now the zval initialized to NULL when starting the fiber is maintained as the transfer value and is subsequently returned from start/resume/throw.
2021-06-18 23:38:02 -05:00
Aaron Piotrowski
f71d62e3d2
Fiber cleanup
Add zend_fiber prefix to delegate_transfer_result().

Ensure status is set to INIT when initializing the fiber context in case memory is not zeroed.

Assert destination fiber context is not dead.

Update stack alloc failure messages.

getThis() -> ZEND_THIS
2021-06-18 23:37:35 -05:00
Aaron Piotrowski
865fb353f5
Rename Fiber::this() to Fiber::getCurrent() (#7155) 2021-06-18 11:02:02 -05:00
Martin Schröder
c5f9cdedd6
Flexible fiber bailout handling (#7163) 2021-06-18 11:01:10 -05:00
Martin Schröder
d4ead60672
Do not expose fiber VM state management (#7170) 2021-06-18 08:04:31 +02:00