-
-
Notifications
You must be signed in to change notification settings - Fork 431
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
Do not use ZYAN_ASSERT
for user passed arguments
#297
base: master
Are you sure you want to change the base?
Conversation
e5fa624
to
615a8f5
Compare
We probably should add a new fuzzer project to test the |
*/ | ||
const void* definition; | ||
ZyanU16 definition_id; |
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 change allows us to actually fuzz the code (open todo) and as well guarantees we never read invalid memory, even if the user passes nonsense data.
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.
And all while requiring less space in the struct! Nice.
f05434e
to
906f0f1
Compare
While I see why this is necessary under our current API guarantees, I really can't say that I like it too much. It adds a pretty significant amount of branches to our already way too branchy code. I ran a benchmark and the performance regression is pretty noticeable. :/ Performance impactFull decode + FormattingClangBefore
After
Regression~12% GCCBefore
After
Regression~9% |
*/ | ||
const void* definition; | ||
ZyanU16 definition_id; |
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.
And all while requiring less space in the struct! Nice.
ZYAN_ASSERT(definition->size[context->eosz_index] || | ||
(instruction->meta.category == ZYDIS_CATEGORY_AMX_TILE)); | ||
// ZYAN_ASSERT(definition->size[context->eosz_index] || (instruction->meta.category == ZYDIS_CATEGORY_AMX_TILE)); |
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.
Is this intentionally commented out? I feel like commented out asserts will confuse us in the future. I'd either reinstate it as a return condition or get rid of it entirely.
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.
It's still a valid assertion, but as instruction
is now passed by the user, it might contain invalid data, so we can't rely on this one anymore. On the other hand I don't want to remove it entirely, because it caused an issue in the past. Might convert it to a plain comment.
That's not nice. Have you been able to profile it? Probably the new branches in
This was actually my initial reason to do everything in one single pass when we started. Sadly, each approach has some drawbacks. Let's try to find out what's causing the regression and optimize it as good as we can. |
Here's a perf diff. Note that
|
@athre0z How do we proceed with this PR? |
Well, I'm not really excited about a 10% perf regression for everyone for what is essentially "make debugging easier". The single commit in this PR does a bunch of different things, some of which are entirely uncontroversial and will likely improve rather then regress performance, e.g. using lookup tables instead of chains of ternary expressions. We should probably start by splitting this one commit into multiple smaller ones and then do partial merges. As for the argument validation, we'll have to make a decision as to whether we simply define this as undefined behavior and keep performance intact or burn a ton of CPU on validation. |
Just go with undefined behavior is a bad idea, because it will often lead to invalid memory access or other critical side effects. We don't see these effects on master yet, because our fuzzer does not test this. Imho we have to continue using sanity checks for public APIs. There must be a way to mitigate the performance issues. |
No description provided.