Skip to content

Commit b02a5fa

Browse files
dlechdpgeorge
authored andcommitted
py/nlraarch64: Fix dangerous use of input register.
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, adafruit#32] since `%0` is now `x19`. This causes the next line ldp lr, x9, [%0, adafruit#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 <[email protected]>
1 parent 8cf9898 commit b02a5fa

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

py/nlraarch64.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,14 @@ NORETURN void nlr_jump(void *val) {
6262
MP_STATIC_ASSERT(offsetof(nlr_buf_t, regs) == 16); // asm assumes it
6363

6464
__asm volatile (
65-
"ldr x29, [%0, #112]\n"
66-
"ldp x27, x28, [%0, #96]\n"
67-
"ldp x25, x26, [%0, #80]\n"
68-
"ldp x23, x24, [%0, #64]\n"
69-
"ldp x21, x22, [%0, #48]\n"
70-
"ldp x19, x20, [%0, #32]\n"
71-
"ldp lr, x9, [%0, #16]\n" // 16 == offsetof(nlr_buf_t, regs)
65+
"mov x0, %0 \n"
66+
"ldr x29, [x0, #112]\n"
67+
"ldp x27, x28, [x0, #96]\n"
68+
"ldp x25, x26, [x0, #80]\n"
69+
"ldp x23, x24, [x0, #64]\n"
70+
"ldp x21, x22, [x0, #48]\n"
71+
"ldp x19, x20, [x0, #32]\n"
72+
"ldp lr, x9, [x0, #16]\n" // 16 == offsetof(nlr_buf_t, regs)
7273
"mov sp, x9 \n"
7374
"mov x0, #1 \n" // non-local return
7475
"ret \n"

0 commit comments

Comments
 (0)