We're using ptrace(PTRACE_SETREGSET, NT_X86_XSTATE) to write all non-gpt
registers on x86 linux. Unfortunately, this method has a quirk, where
the kernel rejects all attempts to write to this area if one supplies a
buffer which is smaller than the area size (even though the kernel will
happily accept partial reads from it).
This means that if the CPU supports some new registers/extensions that
we don't know about (in my case it was the PKRU extension), we will fail
to write *any* non-gpr registers, even those that we know about.
Since this is a situation that's likely to appear again and again, I add
code to NativeRegisterContextLinux_x86_64 to detect the runtime size of
the area, and allocate an appropriate buffer. This does not mean that we
will start automatically supporting all new extensions, but it does mean
that the new extensions will not prevent the old ones from working.
This fixes tests attempting to write to non-gpr registers on new intel
processors (cca Kaby Lake Refresh).
This doesn't compile for me (on stock Ubuntu 16.04, so using gcc/libstdc++ 5.4.0), since my cpuid.h doesn't have __get_cpuid_count. Do I just need to update/fix my toolset, or is that a supported one that we should change this code to accommodate?