Commit Graph

81 Commits

Author SHA1 Message Date
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
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
Joe Watkins
f46063495d
reset blocking state on init 2021-06-15 09:41:36 +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
Martin Schröder
039f0fec58
Destroy previous fiber context in trampoline as needed (#7143) 2021-06-11 23:40:19 -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
Joe Watkins
ef5de9fb3f
ditch function from zend_fiber 2021-06-10 15:40:43 +02: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
twosee
e2e770c442
Fix undefined return value of fiber after bailout (#7103) 2021-06-05 07:20:47 -05:00
Aaron Piotrowski
42dbd1f09e
Improve Fiber::getReturn()
Allows flags besides ZEND_FIBER_FLAG_THREW to be set without causing this method to throw.

The method will not be called after a bailout, so the ZEND_FIBER_FLAG_BAILOUT case was removed.
2021-06-04 23:55:08 -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
twosee
7e11b4d325
Improve memory allocation related code in zend_fibers (#7058)
- make_fcontext() never returns NULL.
- Show syscall error info in exception just like zend_alloc does (we also used php_win32_error_*() in Zend).
- MAP_ANON was marked as deprecated or compatibility macro on Linux, It would be better to use MAP_ANONYMOUS first.
- Makes the code consistent with the code of other modules in the kernel.
- adds some comments.
2021-05-28 12:04:44 +08:00
twosee
795efd7613
Add zend_getpagesize() and reuse it in accelerator and fiber (#7057) 2021-05-27 18:27:18 +08: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
twosee
0e2ac303af
Use ZEND_WIN32 instead of PHP_WIN32 (#7055) 2021-05-27 08:32:40 +02:00
Aaron Piotrowski
3c3ec441e4
Move fiber stack allocation within try
If VM stack allocation fails, the bailout will be caught within the fiber.
2021-05-08 23:30:48 -05: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
779fe8e43a
Check current_execute_data instead of flags in fiber destructor
Checking EG(current_exectue_data) throws into the previous fiber instead of triggering a fatal error during shutdown. A fatal error is triggered only if the throwing destroyed fiber was resumed from {main}.
2021-05-05 10:48:30 -05:00
Nikita Popov
fb374f56a7 Rethrow exceptions in fiber destructor
We need to make sure that HANDLE_EXCEPTION is set when the fiber
throws during destruction.

Fixes oss-fuzz #33875.
2021-05-05 12:49:47 +02: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
Aaron Piotrowski
f3465e6740
Minor fiber fixes
Assert error is fatal when calling zend_error_suspend_fiber.

Added missing static.

Removed .S extension from output of configure.
2021-04-30 10:08:01 -05:00
Aaron Piotrowski
4166653298
Fix exception thrown during fiber destruction
Previously an exception thrown during fiber destruction resulted in a fatal error, but that exception should be able to be caught (unless we’ve entered shutdown, then still use a fatal error so the error is not hidden).
2021-04-30 00:26:47 -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