コード例 #1
0
        private static bool IsCmpxchg16bSupported()
        {
            byte[] getCpuIdCode = new byte[]
            {
                0x53,                         // push rbx
                0xb8, 0x01, 0x00, 0x00, 0x00, // mov eax, 0x1
                0x0f, 0xa2,                   // cpuid
                0x89, 0xc8,                   // mov eax, ecx
                0x5b,                         // pop rbx
                0xc3                          // ret
            };

            IntPtr funcPtr = MapCodeAsExecutable(getCpuIdCode);

            GetCpuId getCpuId = Marshal.GetDelegateForFunctionPointer <GetCpuId>(funcPtr);

            int cpuId = getCpuId();

            MemoryManagement.Free(funcPtr);

            return((cpuId & (1 << 13)) != 0);
        }
コード例 #2
0
        private static IntPtr MapCodeAsExecutable(byte[] code)
        {
            ulong codeLength = (ulong)code.Length;

            IntPtr funcPtr = MemoryManagement.Allocate(codeLength);

            unsafe
            {
                fixed(byte *codePtr = code)
                {
                    byte *dest = (byte *)funcPtr;

                    long size = (long)codeLength;

                    Buffer.MemoryCopy(codePtr, dest, size, size);
                }
            }

            MemoryManagement.Reprotect(funcPtr, codeLength, MemoryProtection.Execute);

            return(funcPtr);
        }