unstable book: in a sanitizer example, check the code · rust-lang/rust@b00b6a8 (original) (raw)
File tree
1 file changed
lines changed
- src/doc/unstable-book/src/compiler-flags
1 file changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -244,36 +244,36 @@ See the [Clang ControlFlowIntegrity documentation][clang-cfi] for more details. | ||
244 | 244 | |
245 | 245 | ## Example 1: Redirecting control flow using an indirect branch/call to an invalid destination |
246 | 246 | |
247 | -```rust,ignore (making doc tests pass cross-platform is hard) | |
247 | +```rust | |
248 | 248 | #![feature(naked_functions)] |
249 | 249 | |
250 | -use std::arch::asm; | |
250 | +use std::arch::naked_asm; | |
251 | 251 | use std::mem; |
252 | 252 | |
253 | 253 | fn add_one(x: i32) -> i32 { |
254 | 254 | x + 1 |
255 | 255 | } |
256 | 256 | |
257 | +# #[cfg(not(target_arch = "x86_64"))] pub extern "C" fn add_two(_: i32) {} | |
258 | + | |
257 | 259 | #[naked] |
260 | +# #[cfg(target_arch = "x86_64")] | |
258 | 261 | pub extern "C" fn add_two(x: i32) { |
259 | 262 | // x + 2 preceded by a landing pad/nop block |
260 | 263 | unsafe { |
261 | - asm!( | |
262 | -" | |
263 | - nop | |
264 | - nop | |
265 | - nop | |
266 | - nop | |
267 | - nop | |
268 | - nop | |
269 | - nop | |
270 | - nop | |
271 | - nop | |
272 | - lea eax, [rdi+2] | |
273 | - ret | |
274 | - ", | |
275 | - options(noreturn) | |
276 | - ); | |
264 | + naked_asm!( | |
265 | +"nop", | |
266 | +"nop", | |
267 | +"nop", | |
268 | +"nop", | |
269 | +"nop", | |
270 | +"nop", | |
271 | +"nop", | |
272 | +"nop", | |
273 | +"nop", | |
274 | +"lea eax, [rdi+2]", | |
275 | +"ret", | |
276 | + ) | |
277 | 277 | } |
278 | 278 | } |
279 | 279 |