File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -125,6 +125,25 @@ r[attributes.codegen.naked]
125125r[attributes. codegen. naked. intro]
126126The * `naked` [attribute]* prevents the compiler from emitting a function prologue and epilogue for the attributed function.
127127
128+ > [! EXAMPLE ]
129+ > ```rust
130+ > # #[cfg(target_arch = "x86_64")] {
131+ > /// Adds 3 to the given number.
132+ > ///
133+ > /// SAFETY: The validity of the used registers
134+ > /// is guaranteed according to the "sysv64" ABI.
135+ > #[unsafe (naked)]
136+ > pub extern "sysv64" fn add_n(number: usize ) -> usize {
137+ > core :: arch :: naked_asm! (
138+ > "add rdi, {}",
139+ > "mov rax, rdi",
140+ > "ret",
141+ > const 3,
142+ > )
143+ > }
144+ > # }
145+ > ```
146+
128147r[attributes. codegen. naked. body]
129148The [function body] must consist of exactly one [`naked_asm! `] macro invocation.
130149
You can’t perform that action at this time.
0 commit comments