I have found the following function here and would like to get it to compile under MinGW:
size_t stackavail()
{
static unsigned StackPtr;
__asm mov [StackPtr],esp
static MEMORY_BASIC_INFORMATION mbi;
VirtualQuery((PVOID)StackPtr,&mbi,sizeof(mbi));
return StackPtr-(unsigned)mbi.AllocationBase;
}
I tried to modify the code above and managed to compile and run it:
size_t stackavail()
{
static unsigned StackPtr;
__asm__ ("movl %%esp, %0\n\t" : "=r" (StackPtr) );
MEMORY_BASIC_INFORMATION mbi;
VirtualQuery((PVOID)StackPtr, &mbi, sizeof(mbi));
return StackPtr-(unsigned)mbi.AllocationBase;
}
But I'm in doubt. Is it correct? Is there another way to do it?