Skip to content

Commit 54ddde1

Browse files
committed
reintroduce a section on unwinding out of naked_asm!
1 parent 0677e1e commit 54ddde1

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

src/inline-assembly.md

+36-1
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ r[asm.rules.reg-not-output]
12201220
Code should not rely on this however since it depends on the results of register allocation.
12211221

12221222
r[asm.rules.unwind]
1223-
- Behavior is undefined if execution unwinds out of an asm block.
1223+
- Behavior is undefined if execution unwinds out of an `asm!` block.
12241224
- This also applies if the assembly code calls a function which then unwinds.
12251225

12261226
r[asm.rules.mem-same-as-ffi]
@@ -1373,6 +1373,41 @@ r[asm.naked-rules.black-box]
13731373
- 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.
13741374
- Runtime code patching is allowed, via target-specific mechanisms.
13751375

1376+
r[asm.naked-rules.unwind]
1377+
- Unwinding out of a `naked_asm!` block is allowed.
1378+
- For correct behavior, the appropriate assembler directives that emit unwinding metadata must be used.
1379+
1380+
<!-- #[naked] is currently unstable, tests would fail if this were marked `rust` -->
1381+
```txt
1382+
# #[cfg(target_arch = "x86_64")] {
1383+
#[naked]
1384+
extern "C-unwind" fn naked_function() {
1385+
unsafe {
1386+
core::arch::naked_asm!(
1387+
".cfi_startproc",
1388+
"push rbp",
1389+
".cfi_def_cfa_offset 16",
1390+
".cfi_offset rbp, -16",
1391+
"mov rbp, rsp",
1392+
".cfi_def_cfa_register rbp",
1393+
"",
1394+
"call {function}",
1395+
"",
1396+
"pop rbp",
1397+
".cfi_def_cfa rsp, 8",
1398+
"ret",
1399+
".cfi_endproc",
1400+
function = sym function_that_panics,
1401+
)
1402+
}
1403+
}
1404+
1405+
extern "C-unwind" fn function_that_panics() {
1406+
panic!("unwind!");
1407+
}
1408+
# }
1409+
```
1410+
13761411
r[asm.validity]
13771412
### Correctness and Validity
13781413

0 commit comments

Comments
 (0)