File tree Expand file tree Collapse file tree 1 file changed +18
-18
lines changed
src/doc/unstable-book/src/compiler-flags Expand file tree Collapse file tree 1 file changed +18
-18
lines changed Original file line number Diff line number Diff line change @@ -244,10 +244,12 @@ See the [Clang ControlFlowIntegrity documentation][clang-cfi] for more details.
244244
245245# # Example 1: Redirecting control flow using an indirect branch/call to an invalid destination
246246
247- ` ` ` rust,ignore (making doc tests pass cross-platform is hard)
247+ ` ` ` rust
248248#! [feature(naked_functions)]
249249
250- use std::arch::asm;
250+ # #[cfg(target_arch = "x86_64")] mod m {
251+
252+ use std::arch::naked_asm;
251253use std::mem;
252254
253255fn add_one(x: i32) -> i32 {
@@ -258,22 +260,19 @@ fn add_one(x: i32) -> i32 {
258260pub extern " C" fn add_two(x: i32) {
259261 // x + 2 preceded by a landing pad/nop block
260262 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- );
263+ naked_asm! (
264+ " nop" ,
265+ " nop" ,
266+ " nop" ,
267+ " nop" ,
268+ " nop" ,
269+ " nop" ,
270+ " nop" ,
271+ " nop" ,
272+ " nop" ,
273+ " lea eax, [rdi+2]" ,
274+ " ret" ,
275+ )
277276 }
278277}
279278
@@ -297,6 +296,7 @@ fn main() {
297296
298297 println! (" The next answer is: {}" , next_answer);
299298}
299+ # }
300300` ` `
301301Fig. 1. Redirecting control flow using an indirect branch/call to an invalid
302302destination (i.e., within the body of the function).
You can’t perform that action at this time.
0 commit comments