File tree Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Expand file tree Collapse file tree 3 files changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -234,6 +234,12 @@ _x86_64_asm_hlt:
234
234
hlt
235
235
retq
236
236
237
+ .global _x86_64_asm_nop
238
+ .p2align 4
239
+ _x86_64_asm_nop:
240
+ nop
241
+ retq
242
+
237
243
.global _x86_64_asm_rdfsbase
238
244
.p2align 4
239
245
_x86_64_asm_rdfsbase:
Original file line number Diff line number Diff line change @@ -30,6 +30,12 @@ extern "C" {
30
30
) ]
31
31
pub ( crate ) fn x86_64_asm_hlt ( ) ;
32
32
33
+ #[ cfg_attr(
34
+ any( target_env = "gnu" , target_env = "musl" ) ,
35
+ link_name = "_x86_64_asm_nop"
36
+ ) ]
37
+ pub ( crate ) fn x86_64_asm_nop ( ) ;
38
+
33
39
#[ cfg_attr(
34
40
any( target_env = "gnu" , target_env = "musl" ) ,
35
41
link_name = "_x86_64_asm_read_from_port_u8"
Original file line number Diff line number Diff line change @@ -23,6 +23,25 @@ pub fn hlt() {
23
23
}
24
24
}
25
25
26
+ /// Executes the `nop` instructions, which performs no operation (i.e. does nothing).
27
+ ///
28
+ /// This operation is useful to work around the LLVM bug that endless loops are illegally
29
+ /// optimized away (see https://github.com/rust-lang/rust/issues/28728). By invoking this
30
+ /// instruction (which is marked as volatile), the compiler should no longer optimize the
31
+ /// endless loop away.
32
+ #[ inline]
33
+ pub fn nop ( ) {
34
+ #[ cfg( feature = "inline_asm" ) ]
35
+ unsafe {
36
+ llvm_asm ! ( "nop" :: :: "volatile" ) ;
37
+ }
38
+
39
+ #[ cfg( not( feature = "inline_asm" ) ) ]
40
+ unsafe {
41
+ crate :: asm:: x86_64_asm_nop ( ) ;
42
+ }
43
+ }
44
+
26
45
/// Emits a '[magic breakpoint](https://wiki.osdev.org/Bochs#Magic_Breakpoint)' instruction for the [Bochs](http://bochs.sourceforge.net/) CPU
27
46
/// emulator. Make sure to set `magic_break: enabled=1` in your `.bochsrc` file.
28
47
#[ cfg( feature = "inline_asm" ) ]
You can’t perform that action at this time.
0 commit comments