On 3/19/26 23:33, Yi Lai wrote:
> + /*
> + * SYSCALL works differently on FRED, it does not save RIP and RFLAGS
> + * to RCX and R11.
> + */
> + unsigned int eax, ebx, ecx, edx;
> +
> + __cpuid_count(0x7, 0x1, eax, ebx, ecx, edx);
> + if (!(eax & (1 << 17))) {
> + /* R11 and EFLAGS should already match. */
> + assert(ctx->uc_mcontext.gregs[REG_EFL] ==
> + ctx->uc_mcontext.gregs[REG_R11]);
> + }
Could of things:
First, CPUID doesn't tell you if FRED is in use. Is it even on by
default yet? There might not be a better way to do this than checking
CPUID, but checking CPUID is imprecise at best. This at _least_ needs to
be commented. Could you check around for other cases like this in the
x86 selftests and see what the existing solutions are?
Second, this is selftests/, but I feel like we can be a bit more
disciplined than doing raw CPUID calls and sprinkling magic numbers all
about. The least that can be done here is giving bit 17 a name and
making the "is FRED supported" into a helper function.
But it does look like something that needs to get fixed either way!