-
Notifications
You must be signed in to change notification settings - Fork 112
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
Alter FailFast behaviour of memcpy #526
Merged
Merged
Changes from all commits
Commits
Show all changes
5 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 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 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 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.
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 don't like that this has gone away because I was using it in other functions. The goal for this header was to provide a set of tools that could be used for wrappers around other libc functions.
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 have moved the
if constexpr
back inside, so you can now doIs this acceptable? Could you elaborate on where you feel the
CheckDirection
approach would be clearer?It seems you have to pass two parameters
I have updated the comments and error message changes to not be
memcpy
specific, and have added aFakeReturn
, so that different things could be tail called in case the function needs a different return type.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 check needs two pieces of information:
I'm not sure how you encode that in a single template parameter.
I am using ifunc resolvers to instantiate the outer functions multiple times so that I get two versions:
If it's a wrapper, then I use the underlying function for the no-checks version. I can then switch between them based on an environment variable at process-launch time. As long as I can still do that concisely, I'm happy.
Making
check_bounds
take two arguments meant that I didn't need anyif constexpr
in the outer function, which simplifies my wrappers considerably because they just unconditionally forward their arguments. My ifunc resolver is, itself, generated from a templated function that takes atemplate template
parameter and instantiates it with the wrapper version to generate (read or write checks).Most of the libc function wrappers can be a simple template that calls
check_bounds<>
on any read/write pointer arguments and then forwards to the underlying implementation.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.
So with a single template parameter I can do the following, which has no
if constexpr
in the caller.I can push the
SNMALLOC_UNLIKELY
inside the call, but it doesn't seem to bias the branches correctly.It has to be two calls to get the good codegen, when we have error messages as we need to conditionally tail call the error message.
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.
Fair enough. I can always wrap the two calls in a macro.
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.
So a macro would work, but you will probably need two versions one for a
void
returning function, and another that takes a type parameter for a not void function.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.
One of my favourite small parts of C++ is that you can
return
an expression that evaluates to avoid
type from a function with avoid
return, so this should be possible to make generic.