http://d.puremagic.com/issues/show_bug.cgi?id=5591
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 AssignedTo: nob...@puremagic.com ReportedBy: hypothermia.fr...@gmail.com --- Comment #0 from hypothermia.fr...@gmail.com 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; bar=&foo; asm { mov EBX,1; } //try normal call foo(2); asm { mov ebx,EBX; } std.stdio.writefln("EBX(after foo) = %x",ebx); asm { mov EBX,3; } // now try pointer call for the 1st time bar(4); asm { mov ebx,EBX; } std.stdio.writefln("EBX(after bar) = %x",ebx); asm { mov EBX,5; } //2nd time bar(6); asm { mov ebx,EBX; } std.stdio.writefln("EBX(after bar 2nd time round) = %x",ebx); main2(); } void main2(){ //and 3rd time! size_t ebx=0; asm { mov EBX,7; } bar(8); asm { mov ebx,EBX; } std.stdio.writefln("EBX(after bar 3rd time round in other func) = %x",ebx); } output: 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: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------