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.
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
Tracing function runtime patch #1060
base: master
Are you sure you want to change the base?
Tracing function runtime patch #1060
Changes from 8 commits
8d706a5
e1fd774
ee56310
461448f
e237278
0699dbf
0db3e4f
6994b59
0e88a29
86e404b
3725c71
799644e
d572cab
0bd8f36
08029de
b2aee3d
f1794a2
c46bb5f
40c0696
4401153
5ead893
b6fcbd4
b334bfa
6f4bdc3
8e00241
ada68bb
3e7d023
18b7fee
e1be48c
0428dc1
6be7bef
6f0abb3
94597ef
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
We can use
std::alloc::Layout::align
and friends to do this calculation for us.I'm also not sure what the difference between
function_ptr
andfunc_address
is.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.
My understanding/intention here is that
function_ptr
is just the pointer to the function whilefunc_address
is the page address (maybe it should be renamed)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.
updated 👉 8e00241
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 might get lost but there are some comments on 8e00241.
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.
oh I did missed that! sorry
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.
You don't need the
PROT_EXEC
here since you are changing it back to executable again below. In fact, on some systems you are not allowed to mark a region writeable and executable at the same time.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.
Sounds good.
But when I remove
PROT_EXEC
I get some of the tests failing in a non-deterministic way 🤔I guess its because somehow test execution overlaps and this runtime patching takes effect while other tests try to execute these instructions.
I get the same result when I run the tests sequentially as:
YKB_TRACER=swt cargo test -- --test-threads=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.
I think Lukas's point is that you can
mprotect(PROT_READ | PROT_WRITE)
ormprotect(PROT_READ | PROT_EXEC)
but you can't combinePROT_EXEC
andPROT_WRITE
: you have to write the page and only then mark it as executable.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.
Updated 👉 40c0696
I get that :)
My issue was with failing the test, but I can't reproduce it anymore 😶
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 understand that I can't combine
PROT_WRITE
andPROT_EXEC
but..I again get this issue with failing tests if I set
PROT_READ | PROT_WRITE
before callingcopy_nonoverlapping
(patching the function):But when I set it as
PROT_READ | PROT_WRITE | PROT_EXEC
it works fine.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 normal trick here is: set to
PROT_READ|PROT_WRITE
do the writes; then set it toPROT_READ | PROT_EXEC
. That way you never havePROT_WRITE
andPROT_EXEC
set at once.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 understand and I wish it would work for me but I get segfault when I do it.
Will dig deeper.
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 think I'm going mad 🙃
Its working fine with
PROT_READ | PROT_WRITE
on patch andPROT_READ | PROT_EXEC
restore.updated 👉 6f4bdc3