Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/doc/unstable-book/src/compiler-flags/sanitizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ See the [Clang ControlFlowIntegrity documentation][clang-cfi] for more details.

## Example 1: Redirecting control flow using an indirect branch/call to an invalid destination

```rust,ignore (making doc tests pass cross-platform is hard)
```rust
#![feature(naked_functions)]

use std::arch::naked_asm;
use std::mem;

Expand All @@ -253,6 +255,7 @@ fn add_one(x: i32) -> i32 {
}

#[unsafe(naked)]
# #[cfg(target_arch = "x86_64")]
pub extern "C" fn add_two(x: i32) {
// x + 2 preceded by a landing pad/nop block
naked_asm!(
Expand All @@ -276,6 +279,7 @@ fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 {
f(arg) + f(arg)
}

# #[cfg(target_arch = "x86_64")]
fn main() {
let answer = do_twice(add_one, 5);

Expand All @@ -292,6 +296,7 @@ fn main() {

println!("The next answer is: {}", next_answer);
}
# #[cfg(not(target_arch = "x86_64"))] fn main() {}
```
Fig. 1. Redirecting control flow using an indirect branch/call to an invalid
destination (i.e., within the body of the function).
Expand Down
Loading