MCPcopy Create free account
hub / github.com/F-Stack/f-stack / fpu_clean_state

Function fpu_clean_state

freebsd/amd64/amd64/fpu.c:1010–1030  ·  view source on GitHub ↗

* On AuthenticAMD processors, the fxrstor instruction does not restore * the x87's stored last instruction pointer, last data pointer, and last * opcode values, except in the rare case in which the exception summary * (ES) bit in the x87 status word is set to 1. * * In order to avoid leaking this information across processes, we clean * these values by performing a dummy load before executin

Source from the content-addressed store, hash-verified

1008 * these values by performing a dummy load before executing fxrstor().
1009 */
1010static void
1011fpu_clean_state(void)
1012{
1013 static float dummy_variable = 0.0;
1014 u_short status;
1015
1016 /*
1017 * Clear the ES bit in the x87 status word if it is currently
1018 * set, in order to avoid causing a fault in the upcoming load.
1019 */
1020 fnstsw(&status);
1021 if (status & 0x80)
1022 fnclex();
1023
1024 /*
1025 * Load the dummy variable into the x87 stack. This mangles
1026 * the x87 stack, but we don't care since we're about to call
1027 * fxrstor() anyway.
1028 */
1029 __asm __volatile("ffree %%st(7); flds %0" : : "m" (dummy_variable));
1030}
1031
1032/*
1033 * This really sucks. We want the acpi version only, but it requires

Callers 1

restore_fpu_curthreadFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected