-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
py/nlraarch64: Fix dangerous use of input register. #11762
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
Code size report:
|
Codecov Report
@@ Coverage Diff @@
## master #11762 +/- ##
=======================================
Coverage 98.40% 98.40%
=======================================
Files 155 155
Lines 20539 20539
=======================================
Hits 20211 20211
Misses 328 328 |
I didn't see #11716 before doing this, but it fixes the issue as well. |
Surprisingly, #11716 actually generates larger code due to saving the clobbered registers at the beginning of the Disassembly of this PR:
Disassembly of #11716
|
Thank you, this fix is definitely needed. And it's how other native NLR implementations work. |
Starting with 2757acf, the `top` variable in `nlr_jump()` in `nlraarch64.c` was assigned to register `x19` by the compiler. However, the assembly code writes over that register with ldp x19, x20, [%0, micropython#32] since `%0` is now `x19`. This causes the next line ldp lr, x9, [%0, micropython#16] to load the wrong values. To fix the issue, we move the value of the `top` variable from an unknown register to a known register at the beginning of the asm code then only use known/hard-coded registers after that. Fixes issue micropython#11754. Signed-off-by: David Lechner <david@pybricks.com>
Starting with 2757acf, the
top
variable innlr_jump()
innlraarch64.c
was assigned to registerx19
by the compiler. However, the assembly code writes over that register withsince
%0
is nowx19
. This causes the next lineto load the wrong values. This lead to a crash when returning from the function since
lr
now contains a bad address.To fix the issue, we move the value of the
top
variable from an unknown register to a known register at the beginning of the asm code then only use known/hard-coded registers after that.Fixes: #11754