Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unstable book: in a sanitizer example, check the code #139113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
36 changes: 18 additions & 18 deletions src/doc/unstable-book/src/compiler-flags/sanitizer.md
Original file line number Diff line number Diff line change
Expand Up @@ -244,43 +244,42 @@ 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 {
x + 1
}

#[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",
)
}
}

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 @@ -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).
Expand Down
Loading