Skip to content

Commit b3d0eb2

Browse files
Apply suggestions from code review
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
1 parent cf3a281 commit b3d0eb2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

src/inline-assembly.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,9 +463,11 @@ To avoid undefined behavior, these rules must be followed when using function-sc
463463
- This means that `asm!` blocks that never return (even if not marked `noreturn`) don't need to preserve these registers.
464464
- When returning to a different `asm!` block than you entered (e.g. for context switching), these registers must contain the value they had upon entering the `asm!` block that you are *exiting*.
465465
- You cannot exit an `asm!` block that has not been entered.
466-
Neither can you exit an `asm!` block that has already been exited.
466+
Neither can you exit an `asm!` block that has already been exited (without first entering it again).
467467
- You are responsible for switching any target-specific state (e.g. thread-local storage, stack bounds).
468+
- You cannot jump from an address in one `asm!` block to an address in another, even within the same function or block, without treating their contexts as potentially different and requiring context switching. You cannot assume that any particular value in those contexts (e.g. current stack pointer or temporary values below the stack pointer) will remain unchanged between the two `asm!` blocks.
468469
- The set of memory locations that you may access is the intersection of those allowed by the `asm!` blocks you entered and exited.
470+
- You cannot assume that two `asm!` blocks adjacent in source code, even without any other code between them, will end up in successive addresses in the binary without any other instructions between them.
469471
- You cannot assume that an `asm!` block will appear exactly once in the output binary.
470472
The compiler is allowed to instantiate multiple copies of the `asm!` block, for example when the function containing it is inlined in multiple places.
471473
- On x86, inline assembly must not end with an instruction prefix (such as `LOCK`) that would apply to instructions generated by the compiler.

0 commit comments

Comments
 (0)