diff --git a/src/doc/unstable-book/src/compiler-flags/sanitizer.md b/src/doc/unstable-book/src/compiler-flags/sanitizer.md index 4679acf0a6a15..9faf486728ded 100644 --- a/src/doc/unstable-book/src/compiler-flags/sanitizer.md +++ b/src/doc/unstable-book/src/compiler-flags/sanitizer.md @@ -244,10 +244,10 @@ 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::asm; +use std::arch::naked_asm; use std::mem; fn add_one(x: i32) -> i32 { @@ -255,25 +255,23 @@ fn add_one(x: i32) -> i32 { } #[naked] +# #[cfg(target_arch = "x86_64")] pub extern "C" fn add_two(x: i32) { // x + 2 preceded by a landing pad/nop block unsafe { - asm!( - " - nop - nop - nop - nop - nop - nop - nop - nop - nop - lea eax, [rdi+2] - ret - ", - options(noreturn) - ); + naked_asm!( + "nop", + "nop", + "nop", + "nop", + "nop", + "nop", + "nop", + "nop", + "nop", + "lea eax, [rdi+2]", + "ret", + ) } } @@ -281,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); @@ -297,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).