-
Notifications
You must be signed in to change notification settings - Fork 7
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?
Changes from 1 commit
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
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,16 +70,13 @@ unsafe fn patch_function(function_ptr: usize, code: *const u8, size: size_t) { | |
let layout = Layout::from_size_align(start_offset, page_size) | ||
.expect("Failed to create layout for function memory page"); | ||
|
||
// Set function memory page as writable | ||
let result = mprotect(page_address, layout.size(), PROT_READ | PROT_WRITE); | ||
if result != 0 { | ||
panic!("Failed to change memory protection to be writable"); | ||
} | ||
// Set function memory page as writable. | ||
// Ignoring mprotect call failure. | ||
mprotect(page_address, layout.size(), PROT_READ | PROT_WRITE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't want to ignore the return code: we just want to abort changing the machine code. So we need something like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to check: is just Alternatively, if we think "if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's ok to return if I tested it with different invalid memory addresses that resulted in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, I think this runtime patching is an integral part of SWT. |
||
// Copy the new code over | ||
std::ptr::copy_nonoverlapping(code, function_ptr as *mut u8, size); | ||
// Set function memory page as readable | ||
let result = mprotect(page_address, layout.size(), PROT_READ | PROT_EXEC); | ||
if result != 0 { | ||
if mprotect(page_address, layout.size(), PROT_READ | PROT_EXEC) != 0 { | ||
panic!("Failed to change memory protection back to 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.
Let's just use
unwrap
as all theseexpect
s really bloat the code, especially as they shouldn't ever trigger. [As this suggests we almost never useexpect
: it does have a place, but it's really rare for us.]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.
Got it.
updated 👉 0428dc1
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.
Can we get rid of the other
expect
s introduced in this PR too please?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 see any other
expect
s only a singleunwrap
.Am I missing it somehow?