Strange AV in asm mode (code only for amd64)

user1234 user1234 at 12.nl
Sun Nov 5 13:43:15 UTC 2017


Hello, try this:

---
import std.stdio;

alias Proc = size_t function();

size_t allInnOne()
{
     asm pure nothrow
     {
         mov RAX, 1;
         ret;
         nop;nop;nop;nop;nop;nop;nop;
         mov RAX, 2;
         ret;
     }
}

void main()
{
     Proc proc1 = &allInnOne;
     Proc proc2 = cast(Proc) (cast(void*)proc1 + 16);
     writeln(proc1(), " ", proc2());
}
---

The call to proc1() gens a SEGFAULT after the first RET.
Remove the call to proc1() and it works.

Why that ?


More information about the Digitalmars-d-learn mailing list