In my kernel routine that executes at HIGH_LEVEL IRQL, I've been trying to manage the floating-point state by directly invoking FXSAVE and FXRSTOR. As KeSaveExtendedProcessorState and KeRestoreExtendedProcessorState are not usable at this level, I had to resort to this method.
Here's my current implementation:
In the assembly code, I've defined two procedures SaveFxState and RestoreFxState:
SaveFxState PROC
; Save the floating point state
mov rax, rcx
fxsave [rax]
ret
SaveFxState ENDP
RestoreFxState PROC
; Restore the floating point state
mov rax, rcx
fxrstor [rax]
ret
RestoreFxState ENDP
These procedures are exposed with extern "C" linkage to my C++ code:
extern "C" {
void SaveFxState(void* saveArea);
void RestoreFxState(void* saveArea);
}
I use these procedures as follows:
FXSAVE_FORMAT g_FxSaveArea;
SaveFxState(&g_FxSaveArea);
// Floating-point operations are here
RestoreFxState(&g_FxSaveArea);
Can anyone confirm whether this approach is correct and safe for managing floating-point state at HIGH_LEVEL IRQL? I would appreciate any insights or suggestions for improvement.