@@ -92,8 +92,14 @@ mod x86_64 {
92
92
}
93
93
94
94
/// Writes the RFLAGS register, preserves reserved bits.
95
+ ///
96
+ /// ## Safety
97
+ ///
98
+ /// Unsafe because undefined becavior can occur if certain flags are modified. For example,
99
+ /// the `DF` flag must be unset in all Rust code. Also, modifying `CF`, `PF`, or any other
100
+ /// flags also used by Rust/LLVM can result in undefined behavior too.
95
101
#[ inline]
96
- pub fn write ( flags : RFlags ) {
102
+ pub unsafe fn write ( flags : RFlags ) {
97
103
let old_value = read_raw ( ) ;
98
104
let reserved = old_value & !( RFlags :: all ( ) . bits ( ) ) ;
99
105
let new_value = reserved | flags. bits ( ) ;
@@ -104,16 +110,23 @@ mod x86_64 {
104
110
/// Writes the RFLAGS register.
105
111
///
106
112
/// Does not preserve any bits, including reserved bits.
113
+ ///
114
+ ///
115
+ /// ## Safety
116
+ ///
117
+ /// Unsafe because undefined becavior can occur if certain flags are modified. For example,
118
+ /// the `DF` flag must be unset in all Rust code. Also, modifying `CF`, `PF`, or any other
119
+ /// flags also used by Rust/LLVM can result in undefined behavior too.
107
120
#[ inline]
108
- pub fn write_raw ( val : u64 ) {
121
+ pub unsafe fn write_raw ( val : u64 ) {
109
122
#[ cfg( feature = "inline_asm" ) ]
110
- unsafe {
123
+ {
111
124
// FIXME - There's probably a better way than saying we preserve the flags even though we actually don't
112
125
asm ! ( "push {}; popf" , in( reg) val, options( preserves_flags) )
113
126
} ;
114
127
115
128
#[ cfg( not( feature = "inline_asm" ) ) ]
116
- unsafe {
129
+ {
117
130
crate :: asm:: x86_64_asm_write_rflags ( val)
118
131
}
119
132
}
0 commit comments