Skip to content

Improve memory allocation related code in zend_fibers #7058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 28, 2021

Conversation

twose
Copy link
Member

@twose twose commented May 27, 2021

  • make_fcontext() never returns NULL.
  • Show syscall error info in exception just like zend_alloc does (it also use php_win32_error_msg_free() 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.

@twose twose requested review from nikic and trowski May 27, 2021 07:58
@twose
Copy link
Member Author

twose commented May 27, 2021

I am trying to work on some simple parts first :)
I may do nothing before I get feedback here because I can't work well on multiple threads...ˋ(′~‵)ˊ

@krakjoe
Copy link
Member

krakjoe commented May 27, 2021

bump resolve conflicts for easy testing ...

PS, this looks testable with an --INI-- section ?

@@ -481,7 +494,6 @@ ZEND_API void zend_fiber_start(zend_fiber *fiber, zval *params, uint32_t param_c
fiber->fci.named_params = named_params;

if (!zend_fiber_init_context(&fiber->context, zend_fiber_execute, EG(fiber_stack_size))) {
zend_throw_exception(NULL, "Could not create fiber context", 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intentionally throwing an Exception, not Error, because it does not indicate a programming error but an environment error that is can happen during normal operation (normally, if more than 65k fibers are created).

Though maybe it should use something more specific than just Exception.

Copy link
Member Author

@twose twose May 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intentionally throwing an Exception, not Error

Sorry... I know that. It's a typo error... I just copy the code from my implementation version and remove the zend_ce_fiber_exception because we have not declared it, I never noticed that I misuse zend_throw_error instead of using zend_throw_exception_ex to throw an exception so it becomes Error here...

Though maybe it should use something more specific than just Exception.

So should we declare FiberException here?

Copy link
Member

@trowski trowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than switching the memory alloc/protect errors back to Exception or a sub-class thereof, LGTM.

- make_fcontext() never returns NULL.
- Show syscall error info in exception just like zend_alloc does (it also use php_win32_error_msg_free() 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.
@twose twose merged commit 7e11b4d into php:master May 28, 2021
@twose twose deleted the fiber-alloc branch May 28, 2021 04:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants