[Mono-dev] MSVC compiled mono_jit_walk_stack problems

Aras Pranckevicius aras at otee.dk
Tue Jan 17 13:02:33 EST 2006


Hi,

Just got libgc/libmono compiling under microsoft VC7/VC8 (wasn't that
hard), but I'm having problems with mono_jit_walk_stack.

Basically, it uses MONO_INIT_CONTEXT_FROM_CALLER, which for MSVC is
defined as inline assembly using ebp register:
    unsigned int stackptr, retaddr;
    {
        __asm mov stackptr, ebp
        __asm mov eax, DWORD PTR [ebp + 4]
        __asm mov retaddr, eax
    }

As such, it requires the compiler to maintain "frame pointers" via
ebp. The problem is, MSVC in default "optimize for speed" mode quite
often omits them - the result is that ebp is often zero, and this code
tries to read from memory location 0x4 - a segfault.

At the moment I've forced MSVC to maintain frame pointers for the
whole mini-exceptions.c file: placed
    #ifdef _MSC_VER
    #pragma optimize("y",off)
    #endif
at beginning and
    #ifdef _MSC_VER
    #pragma optimize("",on)
    #endif
at the end of it.

However, I'm not sure if that produces the correct results for stack
walking (but it gets rid of segfault).


The stack walk is a result of calling mono_method_get_last_managed,
which our codebase uses to do something with mono exceptions.



Aras Pranckevicius
www.otee.dk



More information about the Mono-devel-list mailing list