-
Notifications
You must be signed in to change notification settings - Fork 8k
Detect misuse of ZEND_MAP_PTR_NEW() #16468
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
Open
arnaud-lb
wants to merge
2
commits into
php:master
Choose a base branch
from
arnaud-lb:map-ptr-lock
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
CG(in_compilation)
looks suspicious. Is it necessary for PHP without opcache?I think, it may be better to use
CG(map_ptr_protected)
initialized byfalse
, then setting it totrue
in opcache post_starup and then updated by lock/unlock.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without opcache
ZEND_MAP_PTR_NEW()
is always safe, but I think it's better to implement the same restrictions when opcache is not enabled, so that code that works without opcache also works with it.Indeed. I was convinced that compilation occurred while opcache was locked, so this was to handle the non-opcache case, but actually it's not.
I've simplified as you suggested, but I still deny usage of
ZEND_MAP_PTR_NEW()
after startup when opcache is not enabled.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without opcache,
map_ptr
buffer belongs to process/thread and it may allocate new slots at any time.With opcache.
map_ptr
buffer is addressed through opcache SHM, so we shouldn't add new slots without opcache lock. I think, protection should be obtained and managed by opcache. In case, we manage it outside opcache (e.g. inzend_alloc_ce_cache()
we just negate the protection. (I may be wrong)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes,
zend_alloc_ce_cache()
is what originally convinced me that the lock was held during compilation, since it callsZEND_MAP_PTR_NEW_OFFSET()
. But actually, the conditions inzend_alloc_ce_cache()
ensure that we never callZEND_MAP_PTR_NEW_OFFSET()
after startup when opcache is enabled (a map ptr is only allocated when the class name is interned and not permanent, which only happens without opcache).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still think that the modification of
CG(map_ptr_protected)
inzend_alloc_ce_cache()
is a bad decision.The protection should have a single point of responsibility.
This is too complex verbal condition and it may be easily violated by inaccurate future modification.
You introduce protection exactly against inaccurate future modifications, so it's better not to make exceptions without a big reason.