-
Notifications
You must be signed in to change notification settings - Fork 964
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
Fix (some ?) memory alignment issues on the crypto part - resulting in crashes or strange behavior #4867
Conversation
First step to fix some Crypto crashes or strange behaviors
Fix #4855, and probably multiple Crypto problems depending on hardware
It looks sane to me, though memory alignment isn't something I'm used to worrying about (obviously). I should have a rp2040 platform by the end of today to test with. |
I'm wondering whether we should align the firmware/src/mesh/RadioInterface.h Line 94 in 9bebad2
As we're doing pointer arithmetic for the payload afterwards: firmware/src/mesh/RadioLibInterface.cpp Line 392 in 9bebad2
|
Hi, I'd say, every structure should be aligned for performance at least. I'm rusty, but I found it strange that the compiler does not align global variables by default. Anyway, in your example, even if the start of the buffer is properly aligned, there is a risk that if sizeof(PacketHeader) is not modulo "word", your pointer will be not aligned. Everything I say must be verified, I'm not myself an expert in memory alignment or gcc specificities. |
@TheMalkavien Thanks, makes sense. We force |
#4878 adds a test case that crashes the rp2040. I've not yet been able to trigger the Heltec v3 flaw. This patch does fix that crash and get the test suite passing again on rp2040. |
Hi,
As discussed into the #4855 issue, here is my humble PR.
It fixes #4855 by avoiding the use of non aligned pointers. On some hardware, we do not care at all, but for some the result is not guaranteed, and it makes some hardware crash (rp2040 crashes, Heltecv3 PKI_FAILED, ...).
There is 2 main changes :
As discussed, these two changes are a quick way to fix crashes or bugs linked to the non-alignment of some objects. It will probably not fix all the alignment problems in the future (or even in the present), but it should be considered to avoid such difficult to debug behavior.
Maybe the compiler can provide some useful flags for that, and of course be very careful when using pointers (as usual ? :p ).
Tested and working on RP2040-lora and Heltecv3
Thanks !