Commit graph

34 commits

Author SHA1 Message Date
Bob Weinand
709540ccdc Fix add/remove observer API with multiple observers installed
Depending on the order in which observers were installed, some observers might have been executed twice after removal of another observer. Also, adding an observer could produce a bogus pointer.
2023-06-09 14:00:53 +02:00
Florian Sowade
8dabbda8bc Don’t reset func in zend_closure_internal_handler
The pointer is used in _zend_observe_fcall_begin().
2022-11-02 11:46:43 +01:00
Bob Weinand
396b2aab85 Wrap observer notify functions into inlined enabled checks
Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-08-23 15:22:22 +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
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
Bob Weinand
dc5475c191 Save previous observer on the VM stack
This avoids a possible significant performance penalty, when some leaf function was observed, deep in the stack.
As a side effect, we are not iterating over prev_execute_data anymore and thus, non-observed fake frames, possibly on stack, cannot have any impact on the observer anymore (especially within zend_observer_fcall_end_all).

Saving the previous observer happens now directly on the VM stack. If there is any observer, function frames are allocated an extra zval (the last temporary), which will, on observed frames, contain the previous observed frame address.
2022-08-04 17:16:27 +02:00
Bob Weinand
625f164963 Include internal functions in the observer API
There are two main motivations to this:
a) The logic for handling internal and userland observation can be unified.
b) Unwinding of observed functions on a bailout does notably not include observers. Even if users of observers were to ensure such handling themselves, it would be impossible to retain the relative ordering - either the user has to unwind all internal observed frames before the automatic unwinding (zend_observer_fcall_end_all) or afterwards, but not properly interleaved.

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-07-30 19:20:55 +02:00
Bob Weinand
9e2de4c2d9 Add an API to manipulate observers at runtime
Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-07-29 13:48:05 +02:00
Bob Weinand
0e88f749ff Merge branch 'PHP-8.1' 2022-03-01 14:55:09 +01:00
Bob Weinand
85b669e565 Merge branch 'PHP-8.0' into PHP-8.1 2022-03-01 14:54:09 +01:00
Bob Weinand
e6cf583160 Fix GH-8082: Prevent leaking memory on observed transient run_time_caches
This is achieved by tracking the observers on the run_time_cache (with a fixed amount of slots, 2 for each observer).
That way round, if the run_time_cache is freed all associated observer data is as well.

This approach has been chosen, as to avoid any ABI or API breakage.
Future versions may for example choose to provide a hookable API for run_time_cache freeing or similar.
2022-03-01 14:49:44 +01:00
Christoph M. Becker
1d4482908b
Merge branch 'PHP-8.1'
* PHP-8.1:
  Revert "Fix zend_observer_fcall_end_all() accessing dangling pointers"
2021-12-27 21:11:24 +01:00
Christoph M. Becker
d58c48d45d
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Revert "Fix zend_observer_fcall_end_all() accessing dangling pointers"
2021-12-27 21:10:40 +01:00
Christoph M. Becker
ee610947ce
Revert "Fix zend_observer_fcall_end_all() accessing dangling pointers"
This reverts commit 76e2a8380e.  Cf.
<76e2a8380e (r62560239)>.
2021-12-27 21:08:51 +01:00
Christoph M. Becker
a72a011054
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix zend_observer_fcall_end_all() accessing dangling pointers
2021-12-27 18:21:37 +01:00
Christoph M. Becker
d4c07df4df
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix zend_observer_fcall_end_all() accessing dangling pointers
2021-12-27 18:20:48 +01:00
Florian Sowade
76e2a8380e
Fix zend_observer_fcall_end_all() accessing dangling pointers
This may happen, when the execute_data was allocated on the stack.  We
ensure that the runtime cache pointer is not NULL before dereferencing
it.

This is a partial fix for bug 81430.

Closes GH-7665.
2021-12-27 18:19:13 +01:00
Joe Watkins
7699aed377
missing shutdown in observer 2021-10-13 07:12:09 +02:00
Joe Watkins
b94b97f7d6
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix #81380 observer may not be initialized properly
2021-09-29 12:41:28 +02:00
Joe Watkins
c884a5a21e
Fix #81380 observer may not be initialized properly 2021-09-29 12:39:29 +02:00
Bob Weinand
a8f06346ad Merge remote-tracking branch 'origin/PHP-8.0' into PHP-8.1 2021-09-13 16:15:55 +02:00
Bob Weinand
12b0f1b7cc Fix #81435 Observer current_observed_frame may point to an old (overwritten) frame
Ensure current_observed_frame always points to an actually observed frame.
This solution has a caveat of being O(stack size), with the worst case occurring if there are a lot of frames between the current and previous observed frames.
An O(1) solution would require keeping track of the previous observed frame, which would require some additional frame attached metadata, which is best not attempted in an already released version.
2021-09-13 15:58:58 +02:00
Joe Watkins
848b5458d1
more fiber notifications (#7293) 2021-07-21 17:18:15 +02:00
Martin Schröder
a65989b127
Alternative Fiber Internals Refactoring (#7101) 2021-06-04 23:25:35 -05:00
Aaron Piotrowski
c276c16b66
Implement Fibers
RFC: https://wiki.php.net/rfc/fibers

Closes GH-6875.
2021-04-26 11:07:06 -05:00
Nikita Popov
a1c6ee2164 Convert error filename to zend_string
Error handling functions/callbacks now accept the error filename
as a zend_string* instead of a const char*.
2021-04-23 11:05:14 +02:00
Sammy Kaye Powers
17142eab22 Observe fake closures
Closes GH-6607.
2021-01-28 10:03:41 +01:00
Dmitry Stogov
094e1a8b2d Skip dummy frames allocated on CPU stack of zend_call_function().
(Usage of "current_observed_frame" varible looks unsafe to me).
2021-01-26 18:41:26 +03:00
Sammy Kaye Powers
0425a6697a
Fire open observer end handlers after a zend_bailout
Closes GH-6377
2020-11-16 15:12:57 -08:00
Sammy Kaye Powers
e42abeafec
Pass zend_execute_data instead of zend_function to fcall init
The motivation for this change is to prevent extensions from having to check executor globals for the current execute_data during function call init. A previous implementation of the observer API initialized the function call from runtime cache initialization before execute_data was allocated which is why zend_function was passed in.

But now that the observer API is implemented via opcode specialization, it makes sense to pass in the execute_data. This also keeps the API a bit more consistent for existing extensions that already hook zend_execute_ex.

Closes GH-6209
2020-09-25 11:46:15 -07:00
Sammy Kaye Powers
12306728c5
Add system ID entropy API
The `zend_system_id` is a (true global) system ID that fingerprints a process state. When extensions add engine hooks during MINIT/startup, entropy is added the system ID for each hook. This allows extensions to identify that changes have been made to the engine since the last PHP process restart.

Closes GH-5871
2020-09-18 14:26:44 -07:00
Dmitry Stogov
d5d31ea3b3 Cleanup observer API and add JIT support 2020-09-18 12:55:58 +03:00
Benjamin Eberlei
1359a52d5b Rename zend_error_notify APIs to zend_observer_error* 2020-09-14 19:29:14 +02:00
Levi Morrison
66c3e900e2 Add zend_observer API
Closes GH-5857.

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
Co-authored-by: Sammy Powers <sammyk@datadoghq.com>
2020-09-01 09:59:59 -06:00