Commit Graph

31 Commits

Author SHA1 Message Date
Arnaud Le Blanc
3c56af9902
Allow fiber switching during destructor execution
Fiber switching was disabled during destructor execution due to conflicts
with the garbage collector. This unfortunately introduces a function color
problem: destructors can not call functions that may switch Fibers.

In this change we update the GC so that Fiber switching during GC is safe. In
turn we allow Fiber switching during destrutor execution.

The GC executes destructors in a dedicated Fiber. If a destructor suspends, the
Fiber is owned by userland and a new dedicated Fiber is created to execute the
remaining destructors. Destructor suspension results in a resurection of the
object, which is handled as usual: The object is not considered garbage anymore,
but may be collected in a later run.

When the GC is executed in the main context (not in a Fiber), then destructors
are executed in the main context as well because there is no risk of conflicting
with GC in this case (main context can not suspend).

Fixes GH-11389
Closes GH-13460
2024-07-02 15:00:40 +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
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
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
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
Bob Weinand
da94baf31a Add proper handling to observe functions in fibers
The current_observed_frame is carried along the fiber context and thus always correct now.

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-08-04 17:16:27 +02:00
Joe Watkins
bf294d51b4
Extend resource reservation to Fibers (#7292) 2021-07-21 20:19:20 +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
Ganesh Kandu
6157fcc010 Fix typedef redefinition warnings.
Closes GH-7197.
2021-06-28 10:11:43 +02: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
Aaron Piotrowski
5d4f05527b
Drop fiber block hooks
Removes the ability for an extension to allow Fiber switching in blocked contexts.

See discussion on fdc22744a8.
2021-06-15 08:58:07 -05:00
Nikita Popov
0eafc97d29 Fix prototype 2021-06-15 10:08:50 +02:00
Joe Watkins
ba3c8027bc
Adds zend_fiber_startup at the right stage, moves setting of switch hooks
to correct stage

In a threaded environment, these ought to be set before any threads are
created, and they ought to be set once.
2021-06-15 09:56:15 +02:00
Aaron Piotrowski
859524c246
Remove fiber context embedding 2021-06-14 14:34:36 -05:00
Aaron Piotrowski
fdc22744a8
Add API to prevent Fiber switch in select contexts
Co-authored-by: Martin Schröder <m.schroeder2007@gmail.com>
2021-06-14 14:19:00 -05:00
Aaron Piotrowski
7df3fd9d55
Change stack field to a pointer in fiber context
The variable size of zend_fiber_stack results in the offset of other fields to be variable, which causes compatiblity issues with extensions when php-src is compiled with ASan enabled. This solution was prefered over moving the stack field to be the last member, as inclusion of ZEND_FIBER_CONTEXT_FIELDS into other structs may still result in field offset errors.

The definition of zend_fiber_stack was removed from the header to hide it from the ABI.

Renamed prior_pointer and prior_size to asan_pointer and asan_size to reflect their current use.

Changed context flags type to uint8_t.

Renamed valgrind stack id field to valgrind_stack_id and fixed the type to unsigned int.
2021-06-11 16:05:42 -05:00
Aaron Piotrowski
e6e6b3e68b
Improve fiber interoperability (#7128) 2021-06-10 23:00:07 -05:00
Martin Schröder
fa3d19830c
Unify control & data transfer between fibers (#7120)
Co-authored-by: Aaron Piotrowski <aaron@trowski.com>
2021-06-09 11:20:13 -05:00
Aaron Piotrowski
2184422adc
Merge fiber switching functions (#7106)
Co-authored-by: Martin Schröder <m.schroeder2007@gmail.com>
2021-06-08 08:23:56 -05:00
Martin Schröder
b76a9dbcf9
Add fiber type to better support custom fiber APIs (#7105) 2021-06-07 14:21:05 -05:00
Martin Schröder
a65989b127
Alternative Fiber Internals Refactoring (#7101) 2021-06-04 23:25:35 -05:00
Aaron Piotrowski
d2e5203865
Split fiber status and flags (#7094)
Co-Authored-By: twosee <twose@qq.com>
2021-06-03 15:34:48 -05:00
Aaron Piotrowski
3939c9b07e
Add internal Fiber API (#7045)
This additional internal fiber API creates and manipulates a Fiber object, allowing any internal function to start, resume, or suspend a fiber. The existing zend_fiber_context API allows custom C-based fiber creation using the bundled switching context, but does not interact with the PHP VM. This API behaves the same as calling Fiber object methods from user code, switching EGs, and triggering the fiber switch observer. In general, the Fiber object methods call these new API methods.
2021-05-27 08:33:40 +02:00
Aaron Piotrowski
5fb03758e5
Rename sanitizer members for clarity
These members hold the prior stack pointer and size, so bottom and capacity were poor name choices, prior_pointer and prior_size are more clear.
2021-05-08 13:12:06 -05:00
Aaron Piotrowski
af2905968c
Add sanitizer fiber switching support 2021-05-07 15:52:12 -05:00
Aaron Piotrowski
ccc069d0bb
Catch and repeat zend_bailout in fibers
This removes switching to main for fatal errors in fibers in favor of catching any zend_bailout in a fiber and calling zend_bailout again after switching to the previous fiber or {main}.
2021-05-07 15:52:11 -05:00
Aaron Piotrowski
810fb59f66
Improve fiber backtraces
The start/resume/throw execute_data is now attached as the prev_execute_data to the bottom frame of the fiber stack when the fiber is running.
2021-04-30 12:17:50 -05:00
Nikita Popov
e8e7c04a3a Use common struct to store error information
This is needed by both fibers and opcache (and GH-6903 also uses it),
so make it a common structure that can be used by any functionality
storing warnings/errors.
2021-04-29 11:50:54 +02:00
Aaron Piotrowski
c276c16b66
Implement Fibers
RFC: https://wiki.php.net/rfc/fibers

Closes GH-6875.
2021-04-26 11:07:06 -05:00