Skip to content

Commit 81ad95f

Browse files
committedMar 18, 2025
reintroduce a section on unwinding out of naked_asm!
1 parent 9d54480 commit 81ad95f

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
 

‎src/inline-assembly.md

+35
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,41 @@ r[asm.naked-rules.black-box]
14041404
- This effectively means that the compiler must treat the `naked_asm!` as a black box and only take the interface specification into account, not the instructions themselves.
14051405
- Runtime code patching is allowed, via target-specific mechanisms.
14061406

1407+
r[asm.naked-rules.unwind]
1408+
- Unwinding out of a `naked_asm!` block is allowed.
1409+
- For correct behavior, the appropriate assembler directives that emit unwinding metadata must be used.
1410+
1411+
<!-- #[naked] is currently unstable, tests would fail if this were marked `rust` -->
1412+
```txt
1413+
# #[cfg(target_arch = "x86_64")] {
1414+
#[naked]
1415+
extern "C-unwind" fn naked_function() {
1416+
unsafe {
1417+
core::arch::naked_asm!(
1418+
".cfi_startproc",
1419+
"push rbp",
1420+
".cfi_def_cfa_offset 16",
1421+
".cfi_offset rbp, -16",
1422+
"mov rbp, rsp",
1423+
".cfi_def_cfa_register rbp",
1424+
"",
1425+
"call {function}",
1426+
"",
1427+
"pop rbp",
1428+
".cfi_def_cfa rsp, 8",
1429+
"ret",
1430+
".cfi_endproc",
1431+
function = sym function_that_panics,
1432+
)
1433+
}
1434+
}
1435+
1436+
extern "C-unwind" fn function_that_panics() {
1437+
panic!("unwind!");
1438+
}
1439+
# }
1440+
```
1441+
14071442
r[asm.validity]
14081443
### Correctness and Validity
14091444

0 commit comments

Comments
 (0)