-
Notifications
You must be signed in to change notification settings - Fork 749
Try to align the native code to the next 8 byte boundary #899
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
Conversation
NativeCodePage = mapper.MapWriteable(codeLength + 7); | ||
|
||
// Round to 8 byte boundary | ||
var start = new IntPtr(((NativeCodePage.ToInt64() + 7) >> 3) << 3); |
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.
>> 3) << 3)
can be replaced with & ~0x7L
IMHO, even better to write a generic align function (and unit test it)
Marshal.Copy(NativeCode.Active.Code, 0, NativeCodePage, codeLength); | ||
|
||
// Request 7 bytes more than required such that we can align to an 8 byte boundary on ARM | ||
NativeCodePage = mapper.MapWriteable(codeLength + 7); |
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.
mmap will return minimum a full page, and pages are typically 4096-byte-aligned (certainly more than 8-byte aligned). Add some logging to make sure, but I don't expect your changes are actually doing anything.
After the bx lr you might need a nop? I don't know this ISA myself, but it's not uncommon in architectures with branch prediction (i.e. basically all of them) that it'll unconditionally run an opcode right after a branch.
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.
https://community.arm.com/developer/ip-products/processors/f/cortex-m-forum/7154/alignment-in-arm
Looks like you need 16-byte-aligned if it's 64-bit ARM. So your Return1 is not properly aligned.
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 older RPis are 32bit, though, so this (8 byte alignment) can't be the current issue.
You mentioned compiling on the raspberry pi was slow. You can compile the C# dll on any platform -- as long as you set the |
What does this implement/fix? Explain your changes.
Aligns the ARM code to the next 8 byte boundary.
Does this close any currently open issues?
Maybe #898