Summary: EBX register not preserved when calling stdcall
                    function pointer
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD

--- Comment #0 from 2011-02-15 03:58:17 PST ---
According to D's calling convention EBX register is preserved across function
calls, but when when I call a pointer to an extern(Windows) function, EBX gets
filled with some garbage value. It only happens the first time this function is
called, and the following times it behaves as expected!

The following sample code can be run to show it:

extern(Windows) void foo(int i){
    size_t ebx;
    asm { mov ebx,EBX; }
    std.stdio.writefln(" foo (EBX = %s,%s)",ebx,i);
    asm { mov EBX,10; }

alias extern(Windows) void function(int) fooT;

fooT bar;

void main(){
    size_t ebx=0;

    asm { mov EBX,1; } //try normal call
    asm { mov ebx,EBX; }
    std.stdio.writefln("EBX(after foo) = %x",ebx);    

    asm { mov EBX,3; } // now try pointer call for the 1st time
    asm { mov ebx,EBX; }
    std.stdio.writefln("EBX(after bar) = %x",ebx);

    asm { mov EBX,5; } //2nd time
    asm { mov ebx,EBX; }
    std.stdio.writefln("EBX(after bar 2nd time round) = %x",ebx);


void main2(){ //and 3rd time!
    size_t ebx=0;
    asm { mov EBX,7; }
    asm { mov ebx,EBX; }
    std.stdio.writefln("EBX(after bar 3rd time round in other func) = %x",ebx);

 foo (EBX = 1,2)
EBX(after foo) = 1
 foo (EBX = 5518328,4)
EBX(after bar) = 5433f8
 foo (EBX = 5,6)
EBX(after bar 2nd time round) = 5
 foo (EBX = 7,8)
EBX(after bar 3rd time round in other func) = 7

What's going on with EBX on the 1st call?

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to