module printtlsinfo;

import std.c.windows.windows;
import core.sys.windows.dll;
import std.c.stdio;
import main;

__gshared extern(C) extern int _tls_index;

void printTlsInfo() {
	printf("  _tls_index: %i, &_tls_index: %X\n", _tls_index, &_tls_index);
	int* p;
	asm {
		mov EBX, FS:[0x2C];
		jz noTls;
		mov ECX, _tls_index;
		mov EBX, [EBX+ECX*4];
		lea EAX, [EBX+tlsVar];
		mov p, EAX;
	}
	if(p == &tlsVar)
		printf("  tlsVar = %i, &tlsVar = %X\n", tlsVar, &tlsVar);
	else {
		printf("  FAKE tlsVar = %i, &tlsVar = %X\n", tlsVar, &tlsVar);
		printf("  REAL tlsVar = %i, &tlsVar = %X\n", *p, p);
	}
	if(*p != val)
		printf("  Incorrect tlsVar. Should be %i\n", val);
	goto end;
noTls:
	printf("  no TLS\n");
end:
	puts("\n");
}
