@@ -140,3 +140,102 @@ pub fn cs() -> SegmentSelector {
140140 SegmentSelector ( segment)
141141 }
142142}
143+
144+ /// Writes the FS segment base address
145+ ///
146+ /// ## Safety
147+ ///
148+ /// If `CR4.FSGSBASE` is not set, this instruction will throw an `#UD`.
149+ ///
150+ /// The caller must ensure that this write operation has no unsafe side
151+ /// effects, as the FS segment base address is often used for thread
152+ /// local storage.
153+ #[ inline]
154+ pub unsafe fn wrfsbase ( val : u64 ) {
155+ #[ cfg( feature = "inline_asm" ) ]
156+ #[ inline( always) ]
157+ unsafe fn inner ( val : u64 ) {
158+ llvm_asm ! ( "wrfsbase $0" :: "r" ( val) :: "volatile" )
159+ }
160+
161+ #[ cfg( not( feature = "inline_asm" ) ) ]
162+ #[ inline( always) ]
163+ unsafe fn inner ( val : u64 ) {
164+ crate :: asm:: x86_64_asm_wrfsbase ( val)
165+ }
166+
167+ inner ( val)
168+ }
169+
170+ /// Reads the FS segment base address
171+ ///
172+ /// ## Safety
173+ ///
174+ /// If `CR4.FSGSBASE` is not set, this instruction will throw an `#UD`.
175+ #[ inline]
176+ pub unsafe fn rdfsbase ( ) -> u64 {
177+ #[ cfg( feature = "inline_asm" ) ]
178+ #[ inline( always) ]
179+ unsafe fn inner ( ) -> u64 {
180+ let val: u64 ;
181+ llvm_asm ! ( "rdfsbase $0" : "=r" ( val) :: : "volatile" ) ;
182+ val
183+ }
184+
185+ #[ cfg( not( feature = "inline_asm" ) ) ]
186+ #[ inline( always) ]
187+ unsafe fn inner ( ) -> u64 {
188+ crate :: asm:: x86_64_asm_rdfsbase ( )
189+ }
190+
191+ inner ( )
192+ }
193+
194+ /// Writes the GS segment base address
195+ ///
196+ /// ## Safety
197+ ///
198+ /// If `CR4.FSGSBASE` is not set, this instruction will throw an `#UD`.
199+ ///
200+ /// The caller must ensure that this write operation has no unsafe side
201+ /// effects, as the GS segment base address might be in use.
202+ #[ inline]
203+ pub unsafe fn wrgsbase ( val : u64 ) {
204+ #[ cfg( feature = "inline_asm" ) ]
205+ #[ inline( always) ]
206+ unsafe fn inner ( val : u64 ) {
207+ llvm_asm ! ( "wrgsbase $0" :: "r" ( val) :: "volatile" )
208+ }
209+
210+ #[ cfg( not( feature = "inline_asm" ) ) ]
211+ #[ inline( always) ]
212+ unsafe fn inner ( val : u64 ) {
213+ crate :: asm:: x86_64_asm_wrgsbase ( val)
214+ }
215+
216+ inner ( val)
217+ }
218+
219+ /// Reads the GS segment base address
220+ ///
221+ /// ## Safety
222+ ///
223+ /// If `CR4.FSGSBASE` is not set, this instruction will throw an `#UD`.
224+ #[ inline]
225+ pub unsafe fn rdgsbase ( ) -> u64 {
226+ #[ cfg( feature = "inline_asm" ) ]
227+ #[ inline( always) ]
228+ unsafe fn inner ( ) -> u64 {
229+ let val: u64 ;
230+ llvm_asm ! ( "rdgsbase $0" : "=r" ( val) :: : "volatile" ) ;
231+ val
232+ }
233+
234+ #[ cfg( not( feature = "inline_asm" ) ) ]
235+ #[ inline( always) ]
236+ unsafe fn inner ( ) -> u64 {
237+ crate :: asm:: x86_64_asm_rdgsbase ( )
238+ }
239+
240+ inner ( )
241+ }
0 commit comments