ayeks/SGX-hardware

Calling native cpuid obviously doesn't work in windows with Visual studio compiler

wireshrink opened this issue · 4 comments

(Who needs it at all, anyway) ?

With visual studio compiler it should look like

...
#if defined(_MSC_VER)
#include <intrin.h>
#endif
...
static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
	unsigned int *ecx, unsigned int *edx)
{
	/* ecx is often an input as well as an output. */
	
#if !defined(_MSC_VER)
	
	asm volatile("cpuid"
		: "=a" (*eax),
		"=b" (*ebx),
		"=c" (*ecx),
		"=d" (*edx)
		: "0" (*eax), "2" (*ecx));

#else 
	int registers[4] = {0,0,0,0};
	
	__cpuidex(registers, *eax, *ecx);
	*eax = registers[0];
	*ebx = registers[1];
	*ecx = registers[2];
	*edx = registers[3];

#endif
}

I know that it works in windows but unfortunately can not check that it still works in other places.

ayeks commented

Hey,
unfortunately I do not have a working visual studio environment currently. I will leave the issue open until someone can help or I have a running environment on my own.

Best regards
Lars

I have just compiled the file with the changes @wireshrink suggested for the native_cpuid function and it works on Windows 10 compiled with Visual Studio 2017.

I have then taken the code to a RHEL 6 machine with GCC 4.4.7 and it still works. Using the -Wall switch of course complains that main doesn't return a value.

Can clarify this change worked for me on Windows 10 with VS Pro 2015. Couldn't get the original version to work at all

ayeks commented

Thanks guys! 14acc2b