Skip to content

Commit 738ea1b

Browse files
committed
Change text -> rust highlighting in sanitizer.md
1 parent a167cbd commit 738ea1b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/doc/unstable-book/src/compiler-flags/sanitizer.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ See the [Clang ControlFlowIntegrity documentation][clang-cfi] for more details.
213213
214214
## Example
215215
216-
```text
216+
```rust
217217
#![feature(naked_functions)]
218218
219219
use std::arch::asm;
@@ -223,6 +223,8 @@ fn add_one(x: i32) -> i32 {
223223
x + 1
224224
}
225225
226+
# // Only define this function if the assembly works
227+
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
226228
#[naked]
227229
pub extern "C" fn add_two(x: i32) {
228230
// x + 2 preceded by a landing pad/nop block
@@ -238,7 +240,7 @@ pub extern "C" fn add_two(x: i32) {
238240
nop
239241
nop
240242
nop
241-
lea rax, [rdi+2]
243+
lea eax, [edi+2]
242244
ret
243245
",
244246
options(noreturn)
@@ -250,6 +252,10 @@ fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 {
250252
f(arg) + f(arg)
251253
}
252254
255+
# // Can only call add_two on x86/64
256+
# #[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
257+
# fn main() { println!("this test does not work on this target") }
258+
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
253259
fn main() {
254260
let answer = do_twice(add_one, 5);
255261

0 commit comments

Comments
 (0)