Asm!'s nostack and ARM interrupts

โš“ Rust    ๐Ÿ“… 2025-08-11    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 4      

surdeus

Can option(nostack) be set on an asm!() call if the hardware's interrupt mechanism pushes to the stack and it's possible for an interrupt to occur during execution of the assembly? Does it matter whether it's a hardware or software interrupt?

Context on the question:

On ARM, a hardware exception will automatically align the stack pointer and push some data (e.g. the register values) onto the current thread's stack. When the exception handler returns, the stack pointer is restored to its previous value, but the bytes that were overwritten remain changed. This is true for both hardware and software exceptions.

Tock OS's userspace support library makes system calls by issuing a svc instruction in inline assembly. Many of Tock's system calls do not conceptually touch the stack, but because they go through the software exception mechanism the hardware will still push data to the stack then restore it. We're currently having a discussion at nostack option for ARM system calls ยท Issue #577 ยท tock/libtock-rs ยท GitHub over whether or not nostack can be set on these inline assembly blocks.

My initial reaction is that the answer is "yes, nostack is okay" because if the answer is "no", then the only time nostack can be used is if interrupts are disabled. However, reading through the reference and Rust by Example descriptions of nostack, it's not clear that my initial reaction is correct.

When I look up conversations about nostack, it seems the general sentiment is that nostack is only about the red-zone (which I don't believe ARM has -- or if it has it, then the hardware must respect it as well), but I haven't find anything authoritative saying that.

1 post - 1 participant

Read full topic

๐Ÿท๏ธ Rust_feed