문제

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?

도움이 되었습니까?

해결책

You can get rid of the inline ASM, use

void* StackPtr = &StackPtr;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top