-
Notifications
You must be signed in to change notification settings - Fork 584
Replace some sv_2mortal() instances with more direct equivalents #23153
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
43cb571
Use newSVpvn_flags() rather than sv_2mortal(newSVpvn_utf8)
richardleach 18c083d
do_readline: create new mortal with less branching
richardleach d1f6ac0
pp_system: use newSVtype_mortal instead of two functions
richardleach 6cd3cbd
regcomp.c - create mortal HV/AV in one step
richardleach 981d0f7
Perl_hv_common: sv_2mortal(newSVsv()) to sv_mortalcopy_flags()
richardleach 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
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
Oops, something went wrong.
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.
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.
What end the life of the sv head now that mortal is missing?
Why 81 bytes when old was 80?
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.
Thanks, it was meant to be
newSV_type_mortal
, I'll change that now.It's to keep the allocation size consistent:
Perl_newSV
callssv_grow_fresh(sv, len + 1);
.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.
Be very very careful and single step it line by line if your making assumptions about
+1
s and perl's PV/NewX API. This class of bugs already is sitting in stable and blead perl. "can't introduce an exploit" "safe than sorry"+1 +1
, another 16 or 32 bytes just disappeared times a couple 1000. All these +1s and the PERL_STR_RNDUP macro are very fragile. Open PR with this class of bug#22879
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.
update:
the off by 1 in
#23153
goes back to your commit at
64b4056614429bb6fc7d35118e19a220459358fd
I suggest you single step the C code and verify what integer from the interp is entering glibc.so func since you/nobody else (including me) understands this area of the SVPV API anymore. Short made up demo math of the details in #23153
80/8=10, aligned!
(81+7)&(~7)=88
(81+15)&(~15)=96
Atleast use bytes 82-95 on a PP C level if you paided for them from libc, but this 1+1+15 then !0xF mask over and ever. needs to be stopped.
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 +1 is done by the normal Perl_sv_grow() for the default COW build as well,
sv_grow_fresh
simply duplicates that.That said, the exact value doesn't matter too much.
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.
This commit does create/leave behind 100% unused bytes (~1 upto ~15 bytes). But probably the old code before this commit also did (an 80 byte null term PV will always be 81 bytes of real VM). So the "fix" is moving the byte length const to 72-1 or 72-2, or 88-1 or 88-2 or 96-1 or 96-2. But count 80 is the magic shell terminal line length since 1970, which might mean something in this particular area of the interp, so 72 or 96 might change some other runtime observable behavior without reading/studying more src code.
Test code to play around with on 5.41.7 winperl64.
Malloc bucket jump happens at 81 and 97. Don't ask me why CRT realloc() / HeapReAlloc() / RtlReallocateHeap() move the memory block 100% redundantly between a pair of constant addresses on each realloc() +1 call.
Spectre security fix by MS ?????
Someone else is free to try out my demo code on Win11 or Glibc or OSX.
perl cppinl.pl 71 71 1
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.
Yeah, this was the main motivation for preserving the
80 + 1
behaviour in that commit.